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

Fixed Unity 2019 having no GUI among other issues. #235

Merged
merged 4 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions Scripts/CSGModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,13 @@ private void OnEditorUpdate()
}
}

/// <summary>
/// Used to determined whether we are subscribed to the "During scene GUI" event.
/// Recompilations will reset this variable to false and we can rebind.
/// </summary>
[NonSerialized]
private bool isSubscribedToDuringSceneGui = false;

protected override void Update()
{
if (editMode && !anyCSGModelsInEditMode)
Expand All @@ -1342,10 +1349,15 @@ protected override void Update()

// Make sure the events we need to listen for are all bound (recompilation removes listeners, so it is
// necessary to rebind dynamically)
if (!EditorHelper.SceneViewHasDelegate(OnSceneGUI))
if (!isSubscribedToDuringSceneGui)
{
// Then resubscribe and repaint
isSubscribedToDuringSceneGui = true;
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui += OnSceneGUI;
#else
SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
SceneView.RepaintAll();
}

Expand Down Expand Up @@ -1429,7 +1441,11 @@ private void OnDestroy()
EditorApplication.update -= OnEditorUpdate;
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyItemGUI;
EditorApplication.projectWindowItemOnGUI -= OnProjectItemGUI;
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif
Undo.undoRedoPerformed -= OnUndoRedoPerformed;

GridManager.UpdateGrid();
Expand All @@ -1438,8 +1454,13 @@ private void OnDestroy()
public void RebindToOnSceneGUI()
{
// Unbind the delegate, then rebind to ensure our method gets called last
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
SceneView.duringSceneGui += OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
}

public void ExportOBJ(bool limitToSelection)
Expand Down Expand Up @@ -2045,7 +2066,11 @@ private void ApplyModelAttributes(GameObject newGameObject, bool isVisual)
if (buildSettings.GenerateLightmapUVs)
{
UnityEditor.StaticEditorFlags staticFlags = UnityEditor.GameObjectUtility.GetStaticEditorFlags(newGameObject);
#if UNITY_2019_1_OR_NEWER
staticFlags |= UnityEditor.StaticEditorFlags.ContributeGI;
#else
staticFlags |= UnityEditor.StaticEditorFlags.LightmapStatic;
#endif
UnityEditor.GameObjectUtility.SetStaticEditorFlags(newGameObject, staticFlags);
}
}
Expand Down Expand Up @@ -2117,7 +2142,7 @@ void OnDrawGizmosSelected()
}
#endif
#endif
}
}
}

#endif
2 changes: 1 addition & 1 deletion Scripts/Compatibility/Editor/UnityEventDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_2018_OR_NEWER
#if !UNITY_2018_1_OR_NEWER
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
28 changes: 20 additions & 8 deletions Scripts/Editor/Utilities/UtilityShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,28 @@ static void CSG4Split()
if(EditorHelper.GetSceneViewCamera(sceneView) == EditorHelper.SceneViewCamera.Other)
{
sceneView.orthographic = false;
sceneView.m_SceneLighting = true;
}
else
#if UNITY_2019_1_OR_NEWER
sceneView.sceneLighting = true;
#else
sceneView.m_SceneLighting = true;
#endif
}
else
{
sceneView.orthographic = true;
sceneView.m_SceneLighting = false;
SceneView.SceneViewState state = GetSceneViewState(sceneView);
state.Toggle(false);
}
}
#if UNITY_2019_1_OR_NEWER
sceneView.sceneLighting = false;
#else
sceneView.m_SceneLighting = false;
#endif
SceneView.SceneViewState state = GetSceneViewState(sceneView);
#if UNITY_2019_1_OR_NEWER
state.SetAllEnabled(false);
#else
state.Toggle(false);
#endif
}
}
SceneView.RepaintAll();
}

Expand Down
13 changes: 8 additions & 5 deletions Scripts/Extensions/EditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public static bool HasDelegate (System.Delegate mainDelegate, System.Delegate ta
}
}

public static bool SceneViewHasDelegate(SceneView.OnSceneFunc targetDelegate)
{
return HasDelegate(SceneView.onSceneGUIDelegate, targetDelegate);
}
/// <summary>
/// DO NOT USE - only here for compatibility with old third party plugins!
/// </summary>
public static bool SceneViewHasDelegate(SceneView.OnSceneFunc targetDelegate)
{
return HasDelegate(SceneView.onSceneGUIDelegate, targetDelegate);
}

public enum SceneViewCamera { Top, Bottom, Left, Right, Front, Back, Other };
public enum SceneViewCamera { Top, Bottom, Left, Right, Front, Back, Other };

public static SceneViewCamera GetSceneViewCamera(SceneView sceneView)
{
Expand Down
29 changes: 18 additions & 11 deletions Scripts/UI/CSGGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ public static class CSGGrid
const float MAJOR_LINE_DISTANCE = 200;
const float MINOR_LINE_DISTANCE = 50;

public static void Activate()
public static void Activate()
{
if(!EditorHelper.SceneViewHasDelegate(OnSceneGUI))
{
// Then resubscribe and repaint
SceneView.onSceneGUIDelegate += OnSceneGUI;
}
// resubscribe to the scene GUI updates.
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
SceneView.duringSceneGui += OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif

CSGModel[] csgModels = Object.FindObjectsOfType<CSGModel>();
CSGModel[] csgModels = Object.FindObjectsOfType<CSGModel>();

// Make sure the grid draws behind the CSG Model drawing. This requires us to ask the CSG Model to reregister
for (int i = 0; i < csgModels.Length; i++)
Expand All @@ -39,10 +42,14 @@ public static void Activate()

public static void Deactivate()
{
SceneView.onSceneGUIDelegate -= OnSceneGUI;
}

static void OnSceneGUI(SceneView sceneView)
#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif
}

static void OnSceneGUI(SceneView sceneView)
{
Event e = Event.current;

Expand Down