1
1
using System ;
2
+ using System . Linq ;
2
3
using System . Reflection ;
3
4
using UnityEditor ;
4
5
using UnityEngine ;
@@ -7,36 +8,64 @@ namespace MeshTilesetsEditor
7
8
{
8
9
public class SceneOverlayWindow
9
10
{
11
+ public delegate void WindowFunction ( SceneView sceneView ) ;
12
+
10
13
private object sceneOverlayWindow ;
11
- private MethodInfo showWindow ;
14
+ private MethodInfo windowMethod ;
15
+ private object [ ] windowMethodParams ;
12
16
public UnityEngine . Object target ;
13
17
14
18
// public delegate void ShowWindowFunc(object overlayWindow);
15
19
public delegate void OnWindowGUICallback ( UnityEngine . Object target , SceneView sceneView ) ;
16
-
20
+
17
21
public SceneOverlayWindow ( GUIContent title , OnWindowGUICallback onWindowGUI , UnityEngine . Object target , int priority = int . MaxValue )
18
22
{
19
23
this . target = target ;
20
24
var unityEditor = Assembly . GetAssembly ( typeof ( UnityEditor . SceneView ) ) ;
25
+
26
+ #if UNITY_2019_3 || UNITY_2019_4
27
+ var overlayWindowType = unityEditor . GetType ( "UnityEditor.SceneViewOverlay+OverlayWindow" ) ;
28
+ #elif UNITY_2020_1_OR_NEWER
21
29
var overlayWindowType = unityEditor . GetType ( "UnityEditor.OverlayWindow" ) ;
30
+ #endif
22
31
var sceneViewOverlayType = unityEditor . GetType ( "UnityEditor.SceneViewOverlay" ) ;
23
32
var windowFuncType = sceneViewOverlayType . GetNestedType ( "WindowFunction" ) ;
24
- var windowFunc = Delegate . CreateDelegate ( windowFuncType , onWindowGUI . Target , onWindowGUI . Method ) ;
33
+ var sceneViewFuncDelegate = Delegate . CreateDelegate ( windowFuncType , onWindowGUI . Target , onWindowGUI . Method ) ;
34
+
25
35
var windowDisplayOptionType = sceneViewOverlayType . GetNestedType ( "WindowDisplayOption" ) ;
36
+ var windowDisplayOption = Enum . Parse ( windowDisplayOptionType , "OneWindowPerTarget" ) ;
37
+
38
+ #if UNITY_2019_3 || UNITY_2019_4
39
+ windowMethod = sceneViewOverlayType . GetMethods ( System . Reflection . BindingFlags . Static | System . Reflection . BindingFlags . Public ) . FirstOrDefault ( t => t . Name == "Window" && t . GetParameters ( ) . Length == 6 ) ;
40
+ #elif UNITY_2020_1_OR_NEWER
41
+ //public static void ShowWindow(OverlayWindow window)
42
+ windowMethod = sceneViewOverlayType . GetMethod ( "ShowWindow" , System . Reflection . BindingFlags . Static | System . Reflection . BindingFlags . Public ) ;
43
+ #endif
44
+
45
+ #if UNITY_2019_3 || UNITY_2019_4
46
+ windowMethodParams = new object [ ]
47
+ {
48
+ title , sceneViewFuncDelegate , priority , target , windowDisplayOption , null
49
+ } ;
50
+ #elif UNITY_2020_1_OR_NEWER
51
+ //public OverlayWindow(GUIContent title, SceneViewOverlay.WindowFunction guiFunction, int primaryOrder, Object target, SceneViewOverlay.WindowDisplayOption option)
26
52
sceneOverlayWindow = Activator . CreateInstance ( overlayWindowType ,
27
53
title ,
28
54
windowFunc ,
29
55
int . MaxValue , this . target ,
30
- Enum . Parse ( windowDisplayOptionType , "OneWindowPerTarget" ) //SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget
56
+ windowDisplayOption //SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget
31
57
) ;
32
- showWindow = sceneViewOverlayType . GetMethod ( "ShowWindow" , BindingFlags . Static | BindingFlags . Public ) ;
33
-
58
+ windowMethodParams = new object [ ] { overlayWindow } ;
59
+ #endif
60
+
61
+ //showWindow = sceneViewOverlayType.GetMethod("ShowWindow", BindingFlags.Static | BindingFlags.Public);
34
62
// showWindow = Delegate.CreateDelegate(typeof(ShowWindowFunc), showSceneViewOverlay) as ShowWindowFunc;
35
63
}
36
64
37
65
public void ShowWindow ( )
38
66
{
39
- this . showWindow . Invoke ( null , new object [ ] { sceneOverlayWindow } ) ;
67
+ if ( windowMethod != null )
68
+ windowMethod . Invoke ( null , windowMethodParams ) ;
40
69
}
41
70
42
71
}
0 commit comments