Skip to content

Commit

Permalink
fix: overlays do not exist in Unity 2019.2-2021.1
Browse files Browse the repository at this point in the history
close #207, close #208
  • Loading branch information
mob-sakai committed Jun 24, 2022
1 parent e1715af commit cd8e037
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Scripts/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,21 @@ public override void OnGUI()
static void Init()
{
#if !UNITY_2021_2_OR_NEWER
// static void Window(GUIContent title, WindowFunction sceneViewFunc, int order, UnityEngine.Object target, WindowDisplayOption option)
var miSceneViewOverlayWindow = Type.GetType("UnityEditor.SceneViewOverlay, UnityEditor")
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(x => x.Name == "Window" && x.GetParameters().Length == 5);
.First(x => x.Name == "Window" && 5 <= x.GetParameters().Length);
var windowFunction = (Action<UnityEngine.Object, SceneView>)WindowFunction;
var windowFunctionType = Type.GetType("UnityEditor.SceneViewOverlay+WindowFunction, UnityEditor");
var windowFunctionDelegate = Delegate.CreateDelegate(windowFunctionType, windowFunction.Method);
var windowTitle = new GUIContent(ObjectNames.NicifyVariableName(typeof(UIParticle).Name));
#if UNITY_2019_2_OR_NEWER
//public static void Window(GUIContent title, WindowFunction sceneViewFunc, int order, Object target, WindowDisplayOption option, EditorWindow window = null)
var sceneViewArgs = new object[] { windowTitle, windowFunctionDelegate, 599, null, 2, null };
#else
//public static void Window(GUIContent title, WindowFunction sceneViewFunc, int order, Object target, WindowDisplayOption option)
var sceneViewArgs = new object[] { windowTitle, windowFunctionDelegate, 599, null, 2 };
#endif

#if UNITY_2019_1_OR_NEWER
SceneView.duringSceneGui += _ => miSceneViewOverlayWindow.Invoke(null, sceneViewArgs);
#else
Expand Down

0 comments on commit cd8e037

Please sign in to comment.