10
10
using UnityEngine . EventSystems ;
11
11
using UnityEngine . SceneManagement ;
12
12
using UnityEngine . UI ;
13
+ using UnityExplorer ;
13
14
14
15
namespace UnityExplorer . Core . Runtime . Mono
15
16
{
@@ -18,7 +19,6 @@ public class MonoProvider : RuntimeProvider
18
19
public override void Initialize ( )
19
20
{
20
21
ExplorerCore . Context = RuntimeContext . Mono ;
21
- //Reflection = new MonoReflection();
22
22
TextureUtil = new MonoTextureUtil ( ) ;
23
23
}
24
24
@@ -28,60 +28,35 @@ public override void SetupEvents()
28
28
}
29
29
30
30
private void Application_logMessageReceived ( string condition , string stackTrace , LogType type )
31
- {
32
- ExplorerCore . LogUnity ( condition , type ) ;
33
- }
31
+ => ExplorerCore . LogUnity ( condition , type ) ;
34
32
35
- public override void StartCoroutine ( IEnumerator routine )
36
- {
37
- ExplorerBehaviour . Instance . StartCoroutine ( routine ) ;
38
- }
33
+ public override void StartCoroutine ( IEnumerator routine )
34
+ => ExplorerBehaviour . Instance . StartCoroutine ( routine ) ;
39
35
40
36
public override void Update ( )
41
37
{
42
-
43
38
}
44
39
45
- public override T AddComponent < T > ( GameObject obj , Type type )
46
- {
47
- return ( T ) obj . AddComponent ( type ) ;
48
- }
40
+ public override T AddComponent < T > ( GameObject obj , Type type )
41
+ => ( T ) obj . AddComponent ( type ) ;
49
42
50
- public override ScriptableObject CreateScriptable ( Type type )
51
- {
52
- return ScriptableObject . CreateInstance ( type ) ;
53
- }
43
+ public override ScriptableObject CreateScriptable ( Type type )
44
+ => ScriptableObject . CreateInstance ( type ) ;
54
45
55
46
public override void GraphicRaycast ( GraphicRaycaster raycaster , PointerEventData data , List < RaycastResult > list )
56
- {
57
- raycaster . Raycast ( data , list ) ;
58
- }
47
+ => raycaster . Raycast ( data , list ) ;
59
48
60
- public override string LayerToName ( int layer )
49
+ public override string LayerToName ( int layer )
61
50
=> LayerMask . LayerToName ( layer ) ;
62
51
63
- public override UnityEngine . Object [ ] FindObjectsOfTypeAll ( Type type )
52
+ public override UnityEngine . Object [ ] FindObjectsOfTypeAll ( Type type )
64
53
=> Resources . FindObjectsOfTypeAll ( type ) ;
65
54
66
- //private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.AllFlags);
67
-
68
- //public override int GetSceneHandle(Scene scene)
69
- //{
70
- // return (int)fi_Scene_handle.GetValue(scene);
71
- //}
55
+ public override GameObject [ ] GetRootGameObjects ( Scene scene )
56
+ => scene . isLoaded ? scene . GetRootGameObjects ( ) : new GameObject [ 0 ] ;
72
57
73
- public override GameObject [ ] GetRootGameObjects ( Scene scene )
74
- {
75
- if ( ! scene . isLoaded )
76
- return new GameObject [ 0 ] ;
77
-
78
- return scene . GetRootGameObjects ( ) ;
79
- }
80
-
81
- public override int GetRootCount ( Scene scene )
82
- {
83
- return scene . rootCount ;
84
- }
58
+ public override int GetRootCount ( Scene scene )
59
+ => scene . rootCount ;
85
60
86
61
public override void SetColorBlock ( Selectable selectable , Color ? normal = null , Color ? highlighted = null , Color ? pressed = null ,
87
62
Color ? disabled = null )
@@ -103,59 +78,42 @@ public override void SetColorBlock(Selectable selectable, Color? normal = null,
103
78
SetColorBlock ( selectable , colors ) ;
104
79
}
105
80
106
- public override void SetColorBlock ( Selectable selectable , ColorBlock colors )
107
- {
108
- selectable . colors = colors ;
109
- }
81
+ public override void SetColorBlock ( Selectable selectable , ColorBlock colors )
82
+ => selectable . colors = colors ;
110
83
}
111
84
}
112
85
113
86
public static class MonoExtensions
114
87
{
88
+ // Helpers to use the same style of AddListener that IL2CPP uses.
89
+
115
90
public static void AddListener ( this UnityEvent _event , Action listener )
116
- {
117
- _event . AddListener ( new UnityAction ( listener ) ) ;
118
- }
91
+ => _event . AddListener ( new UnityAction ( listener ) ) ;
119
92
120
93
public static void AddListener < T > ( this UnityEvent < T > _event , Action < T > listener )
121
- {
122
- _event . AddListener ( new UnityAction < T > ( listener ) ) ;
123
- }
94
+ => _event . AddListener ( new UnityAction < T > ( listener ) ) ;
124
95
125
96
public static void RemoveListener ( this UnityEvent _event , Action listener )
126
- {
127
- _event . RemoveListener ( new UnityAction ( listener ) ) ;
128
- }
97
+ => _event . RemoveListener ( new UnityAction ( listener ) ) ;
129
98
130
99
public static void RemoveListener < T > ( this UnityEvent < T > _event , Action < T > listener )
131
- {
132
- _event . RemoveListener ( new UnityAction < T > ( listener ) ) ;
133
- }
100
+ => _event . RemoveListener ( new UnityAction < T > ( listener ) ) ;
134
101
135
- public static void Clear ( this StringBuilder sb )
136
- {
137
- sb . Remove ( 0 , sb . Length ) ;
138
- }
102
+ // Doesn't exist in NET 3.5
139
103
140
- private static PropertyInfo pi_childControlHeight ;
104
+ public static void Clear ( this StringBuilder sb )
105
+ => sb . Remove ( 0 , sb . Length ) ;
141
106
142
- public static void SetChildControlHeight ( this HorizontalOrVerticalLayoutGroup group , bool value )
143
- {
144
- if ( pi_childControlHeight == null )
145
- pi_childControlHeight = group . GetType ( ) . GetProperty ( "childControlHeight" ) ;
107
+ // These properties don't exist in some earlier games, so null check before trying to set them.
146
108
147
- pi_childControlHeight ? . SetValue ( group , value , null ) ;
148
- }
109
+ public static void SetChildControlHeight ( this HorizontalOrVerticalLayoutGroup group , bool value )
110
+ => ReflectionUtility . GetPropertyInfo ( typeof ( HorizontalOrVerticalLayoutGroup ) , "childControlHeight" )
111
+ ? . SetValue ( group , value , null ) ;
149
112
150
- private static PropertyInfo pi_childControlWidth ;
151
113
152
114
public static void SetChildControlWidth ( this HorizontalOrVerticalLayoutGroup group , bool value )
153
- {
154
- if ( pi_childControlWidth == null )
155
- pi_childControlWidth = group . GetType ( ) . GetProperty ( "childControlWidth" ) ;
156
-
157
- pi_childControlWidth ? . SetValue ( group , value , null ) ;
158
- }
115
+ => ReflectionUtility . GetPropertyInfo ( typeof ( HorizontalOrVerticalLayoutGroup ) , "childControlWidth" )
116
+ ? . SetValue ( group , value , null ) ;
159
117
}
160
118
161
119
#endif
0 commit comments