Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #257 from Henry00IS/Overlays
Browse files Browse the repository at this point in the history
Added overlays support for 2021.2.
  • Loading branch information
Henry00IS authored Jul 12, 2021
2 parents e039394 + 37b024a commit a703098
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Scripts/CSGModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public void OnSceneGUI(SceneView sceneView)
}
Event e = Event.current;

#if UNITY_2021_2_OR_NEWER
if (SabreToolbarOverlay.Instance != null) SabreToolbarOverlay.Instance.displayed = EditMode;
if (SabreToolsOverlay.Instance != null) SabreToolsOverlay.Instance.displayed = EditMode;
#endif

if (!EditMode)
{
return;
Expand Down
8 changes: 6 additions & 2 deletions Scripts/Tools/ClipEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ void OnRepaint(SceneView sceneView, Event e)
GUIStyle toolbar = new GUIStyle(EditorStyles.toolbar);
toolbar.normal.background = SabreCSGResources.ClearTexture;
toolbar.fixedHeight = rectangle.height;
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = () => OnToolbarGUI(0);
#else
GUILayout.Window(140006, rectangle, OnToolbarGUI, "",toolbar);
}
#endif
}

void OnToolbarGUI(int windowID)
{
Expand Down Expand Up @@ -602,7 +606,7 @@ void InsertEdgeLoop()

public override void Deactivated ()
{

base.Deactivated();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Scripts/Tools/DrawEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ private void OnRepaint(SceneView sceneView, Event e)

public override void Deactivated()
{
base.Deactivated();
}

public override bool PreventBrushSelection
Expand Down
5 changes: 5 additions & 0 deletions Scripts/Tools/PaintEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,11 @@ private void OnRepaintGUI(SceneView sceneView, Event e)
// Set the style height to match the rectangle (so it stretches instead of tiling)
toolbar.fixedHeight = toolbarRect.height + toolbarHeight;
// Draw the actual GUI via a Window
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = () => OnToolbarGUI(0);
#else
GUILayout.Window(140010, actualToolbarRect, OnToolbarGUI, "", toolbar);
#endif
}

private void OnToolbarGUI(int windowID)
Expand Down Expand Up @@ -1034,6 +1038,7 @@ private void DrawToolbarPalette()

public override void Deactivated()
{
base.Deactivated();
}

public override bool PreventBrushSelection
Expand Down
16 changes: 15 additions & 1 deletion Scripts/Tools/ResizeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,11 @@ public void OnRepaint(SceneView sceneView, Event e)
BRUSH_MENU_HEIGHT
);

#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = () => OnTopToolbarGUI(0);
#else
GUILayout.Window(140007, rectangle, OnTopToolbarGUI, "", style);
#endif

if (primaryTargetBrush != null)
{
Expand All @@ -1317,7 +1321,11 @@ public void OnRepaint(SceneView sceneView, Event e)
style = new GUIStyle(EditorStyles.toolbar);
style.fixedWidth = BRUSH_MENU_WIDTH;
style.fixedHeight = BRUSH_MENU_HEIGHT;
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window2 = () => OnBrushSettingsGUI(0);
#else
GUILayout.Window(140011, brushMenuRect, OnBrushSettingsGUI, "", style);
#endif
}
}

Expand All @@ -1327,7 +1335,11 @@ private void OnTopToolbarGUI(int windowID)
}

private void OnBrushSettingsGUI(int windowID) {
GUILayout.BeginHorizontal();
// can happen in overlays without selection.
if (primaryTargetBrush == null)
return;

GUILayout.BeginHorizontal();
GUILayout.Label("Brush Settings", EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
Expand Down Expand Up @@ -2475,6 +2487,8 @@ public override void ResetTool()

public override void Deactivated()
{
base.Deactivated();

// Make sure we get rid of any active custom cursor
SabreMouse.ResetCursor();
}
Expand Down
34 changes: 33 additions & 1 deletion Scripts/Tools/SurfaceEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ private enum AlignDirection

private List<Polygon> lastHitSet = new List<Polygon>();

#if UNITY_2021_2_OR_NEWER
private Rect alignButtonRect = new Rect(118, 140, 80, 45);
#else
private Rect alignButtonRect = new Rect(118, 110, 80, 45);
#endif

private Material lastMaterial = null;
private Color lastColor = Color.white;
Expand Down Expand Up @@ -1141,7 +1145,11 @@ private void OnRepaintGUI(SceneView sceneView, Event e)
// Set the style height to match the rectangle (so it stretches instead of tiling)
toolbar.fixedHeight = ToolbarRect.height;
// Draw the actual GUI via a Window
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = () => OnToolbarGUI(0);
#else
GUILayout.Window(140009, ToolbarRect, OnToolbarGUI, "", toolbar);
#endif
}

private void OnKeyAction(SceneView sceneView, Event e)
Expand Down Expand Up @@ -1468,7 +1476,11 @@ private void DrawExcludeBox()
}

GUILayout.BeginHorizontal(GUILayout.Width(50));
#if UNITY_2021_2_OR_NEWER
Rect rect = new Rect(66, 66, 60, 15);
#else
Rect rect = new Rect(72, 48, 60, 15);
#endif
bool newExcludeState = SabreGUILayout.ToggleMixed(rect, excludeState, excludeConflict, "Exclude");

EditorGUI.showMixedValue = false; // Reset mixed state
Expand Down Expand Up @@ -1539,7 +1551,11 @@ private void DrawManualTextBoxes()
GUIStyle textFieldStyle2 = SabreGUILayout.GetTextFieldStyle2();

// East Scale (u scale)
#if UNITY_2021_2_OR_NEWER
Rect rect = new Rect(138, 21, 60, 16);
#else
Rect rect = new Rect(138, 2, 60, 16);
#endif
if (SabreGUILayout.DrawUVField(rect, eastScale, ref uScaleString, "uScaleField", textFieldStyle1))
{
float newEastScale;
Expand All @@ -1557,7 +1573,11 @@ private void DrawManualTextBoxes()
}

// North scale (v scale)
#if UNITY_2021_2_OR_NEWER
rect = new Rect(138, 36, 60, 16);
#else
rect = new Rect(138, 17, 60, 16);
#endif
if (SabreGUILayout.DrawUVField(rect, northScale, ref vScaleString, "vScaleField", textFieldStyle1))
{
float newNorthScale;
Expand All @@ -1575,7 +1595,11 @@ private void DrawManualTextBoxes()
}

// North scale (v scale)
#if UNITY_2021_2_OR_NEWER
rect = new Rect(138, 54, 60, 16);
#else
rect = new Rect(138, 35, 60, 16);
#endif
if (SabreGUILayout.DrawUVField(rect, eastOffset, ref uOffsetString, "uOffsetField", textFieldStyle2))
{
float newEastOffset;
Expand All @@ -1592,7 +1616,11 @@ private void DrawManualTextBoxes()
}
}

#if UNITY_2021_2_OR_NEWER
rect = new Rect(138, 69, 60, 16);
#else
rect = new Rect(138, 50, 60, 16);
#endif
if (SabreGUILayout.DrawUVField(rect, northOffset, ref vOffsetString, "vOffsetField", textFieldStyle2))
{
float newNorthOffset;
Expand Down Expand Up @@ -1632,8 +1660,11 @@ private void OnToolbarGUI(int windowID)

GUISkin inspectorSkin = SabreGUILayout.GetInspectorSkin();

#if UNITY_2021_2_OR_NEWER
Rect rect = new Rect(138, 89, 60, 18);
#else
Rect rect = new Rect(138, 68, 60, 18);

#endif
if (GUI.Button(rect, "Color", inspectorSkin.button))
{
vertexColorWindow = VertexColorWindow.CreateAndShow(csgModel, this);
Expand Down Expand Up @@ -1979,6 +2010,7 @@ public override void OnSelectionChanged()

public override void Deactivated()
{
base.Deactivated();
}

public override bool BrushesHandleDrawing
Expand Down
8 changes: 7 additions & 1 deletion Scripts/Tools/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ public virtual void OnUndoRedoPerformed() {}
// Called when the selected brush changes
public abstract void ResetTool();

public abstract void Deactivated();
public virtual void Deactivated()
{
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = null;
SabreToolsOverlay.window2 = null;
#endif
}

public virtual bool BrushesHandleDrawing
{
Expand Down
1 change: 1 addition & 0 deletions Scripts/Tools/TransformModelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public override void ResetTool()

public override void Deactivated()
{
base.Deactivated();
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Scripts/Tools/VertexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,11 @@ public void OnRepaint (SceneView sceneView, Event e)
GUIStyle toolbar = new GUIStyle(EditorStyles.toolbar);
toolbar.normal.background = SabreCSGResources.ClearTexture;
toolbar.fixedHeight = rectangle.height;
#if UNITY_2021_2_OR_NEWER
SabreToolsOverlay.window1 = () => OnToolbarGUI(0);
#else
GUILayout.Window(140002, rectangle, OnToolbarGUI, "", toolbar);
#endif
}

void OnMouseDown (SceneView sceneView, Event e)
Expand Down Expand Up @@ -1493,7 +1497,7 @@ private void OnEdgeChamfer(bool popup)

public override void Deactivated ()
{

base.Deactivated();
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions Scripts/UI/SabreToolbarOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#if UNITY_2021_2_OR_NEWER

using UnityEditor;
using UnityEditor.Overlays;
using UnityEngine;

namespace Sabresaurus.SabreCSG
{
[Overlay(typeof(SceneView), k_Id, "SabreCSG Toolbar")]
public class SabreToolbarOverlay : IMGUIOverlay
{
private const string k_Id = "sabrecsg-toolbar-overlay";
public static SabreToolbarOverlay Instance;

public override void OnCreated()
{
base.OnCreated();

Instance = this;
}

public override void OnGUI()
{
var model = CSGModel.GetActiveCSGModel();

if (model)
{
Toolbar.CSGModel = model;

if (Toolbar.primitiveMenuShowing)
{
Toolbar.OnPrimitiveMenuGUI(0);
}

if (Toolbar.viewMenuShowing)
{
Toolbar.OnViewMenuGUI(0);
}

if (!string.IsNullOrEmpty(Toolbar.WarningMessage))
{
Toolbar.OnWarningToolbar(0);
}

Toolbar.OnBottomToolbarGUI(0);
}
}
}
}

#endif
11 changes: 11 additions & 0 deletions Scripts/UI/SabreToolbarOverlay.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Scripts/UI/SabreToolsOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if UNITY_2021_2_OR_NEWER

using UnityEditor;
using UnityEditor.Overlays;
using UnityEngine;

namespace Sabresaurus.SabreCSG
{
[Overlay(typeof(SceneView), k_Id, "SabreCSG Tools")]
public class SabreToolsOverlay : IMGUIOverlay
{
private const string k_Id = "sabrecsg-tools-overlay";
public static SabreToolsOverlay Instance;

public static System.Action window1;
public static System.Action window2;

public override void OnCreated()
{
base.OnCreated();

Instance = this;
}

public override void OnGUI()
{
var model = CSGModel.GetActiveCSGModel();
if (model)
{
Toolbar.CSGModel = model;
Toolbar.OnTopToolbarGUI(0);

window1?.Invoke();
window2?.Invoke();
}
}
}
}

#endif
11 changes: 11 additions & 0 deletions Scripts/UI/SabreToolsOverlay.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a703098

Please sign in to comment.