Beispiel #1
0
        public SceneOverlayWindow(GUIContent title, OnWindowGUICallback onWindowGUI, UnityEngine.Object target, int priority = int.MaxValue)
        {
            this.target = target;
            var unityEditor             = Assembly.GetAssembly(typeof(UnityEditor.SceneView));
            var overlayWindowType       = unityEditor.GetType("UnityEditor.OverlayWindow");
            var sceneViewOverlayType    = unityEditor.GetType("UnityEditor.SceneViewOverlay");
            var windowFuncType          = sceneViewOverlayType.GetNestedType("WindowFunction");
            var windowFunc              = Delegate.CreateDelegate(windowFuncType, onWindowGUI.Target, onWindowGUI.Method);
            var windowDisplayOptionType = sceneViewOverlayType.GetNestedType("WindowDisplayOption");

            sceneOverlayWindow = Activator.CreateInstance(overlayWindowType,
                                                          title,
                                                          windowFunc,
                                                          int.MaxValue, this.target,
                                                          Enum.Parse(windowDisplayOptionType, "OneWindowPerTarget") //SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget
                                                          );
            showWindow = sceneViewOverlayType.GetMethod("ShowWindow", BindingFlags.Static | BindingFlags.Public);

            // showWindow = Delegate.CreateDelegate(typeof(ShowWindowFunc), showSceneViewOverlay) as ShowWindowFunc;
        }
Beispiel #2
0
        public SceneOverlayWindow(GUIContent title, OnWindowGUICallback onWindowGUI, UnityEngine.Object target, int priority = int.MaxValue)
        {
            this.target = target;
            var unityEditor = Assembly.GetAssembly(typeof(UnityEditor.SceneView));

            // Credit to @LogicalError for the Unity 2019 code path
            // (Original: https://github.com/RadicalCSG/Chisel.Prototype/blob/master/Packages/com.chisel.editor/Chisel/Editor/Editor/Scene/Overlays/ChiselOverlay.cs)
#if UNITY_2019_3 || UNITY_2019_4
            var overlayWindowType = unityEditor.GetType("UnityEditor.SceneViewOverlay+OverlayWindow");
#elif UNITY_2020_1_OR_NEWER
            var overlayWindowType = unityEditor.GetType("UnityEditor.OverlayWindow");
#endif
            var sceneViewOverlayType  = unityEditor.GetType("UnityEditor.SceneViewOverlay");
            var windowFuncType        = sceneViewOverlayType.GetNestedType("WindowFunction");
            var sceneViewFuncDelegate = Delegate.CreateDelegate(windowFuncType, onWindowGUI.Target, onWindowGUI.Method);

            var windowDisplayOptionType = sceneViewOverlayType.GetNestedType("WindowDisplayOption");
            var windowDisplayOption     = Enum.Parse(windowDisplayOptionType, "OneWindowPerTarget");

#if UNITY_2019_3 || UNITY_2019_4
            windowMethod       = sceneViewOverlayType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).FirstOrDefault(t => t.Name == "Window" && t.GetParameters().Length == 6);
            windowMethodParams = new object[]
            {
                title, sceneViewFuncDelegate, priority, target, windowDisplayOption, null
            };
#elif UNITY_2020_1_OR_NEWER
            //public static void ShowWindow(OverlayWindow window)
            windowMethod = sceneViewOverlayType.GetMethod("ShowWindow", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            //public OverlayWindow(GUIContent title, SceneViewOverlay.WindowFunction guiFunction, int primaryOrder, Object target, SceneViewOverlay.WindowDisplayOption option)
            sceneOverlayWindow = Activator.CreateInstance(overlayWindowType,
                                                          title,
                                                          sceneViewFuncDelegate,
                                                          int.MaxValue, this.target,
                                                          windowDisplayOption //SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget
                                                          );
            windowMethodParams = new object[] { sceneOverlayWindow };
#endif
        }