1010using UnityEngine . EventSystems ;
1111using UnityEngine . SceneManagement ;
1212using UnityEngine . UI ;
13+ using UnityExplorer ;
1314
1415namespace UnityExplorer . Core . Runtime . Mono
1516{
@@ -18,7 +19,6 @@ public class MonoProvider : RuntimeProvider
1819 public override void Initialize ( )
1920 {
2021 ExplorerCore . Context = RuntimeContext . Mono ;
21- //Reflection = new MonoReflection();
2222 TextureUtil = new MonoTextureUtil ( ) ;
2323 }
2424
@@ -28,60 +28,35 @@ public override void SetupEvents()
2828 }
2929
3030 private void Application_logMessageReceived ( string condition , string stackTrace , LogType type )
31- {
32- ExplorerCore . LogUnity ( condition , type ) ;
33- }
31+ => ExplorerCore . LogUnity ( condition , type ) ;
3432
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 ) ;
3935
4036 public override void Update ( )
4137 {
42-
4338 }
4439
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 ) ;
4942
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 ) ;
5445
5546 public override void GraphicRaycast ( GraphicRaycaster raycaster , PointerEventData data , List < RaycastResult > list )
56- {
57- raycaster . Raycast ( data , list ) ;
58- }
47+ => raycaster . Raycast ( data , list ) ;
5948
60- public override string LayerToName ( int layer )
49+ public override string LayerToName ( int layer )
6150 => LayerMask . LayerToName ( layer ) ;
6251
63- public override UnityEngine . Object [ ] FindObjectsOfTypeAll ( Type type )
52+ public override UnityEngine . Object [ ] FindObjectsOfTypeAll ( Type type )
6453 => Resources . FindObjectsOfTypeAll ( type ) ;
6554
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 ] ;
7257
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 ;
8560
8661 public override void SetColorBlock ( Selectable selectable , Color ? normal = null , Color ? highlighted = null , Color ? pressed = null ,
8762 Color ? disabled = null )
@@ -103,59 +78,42 @@ public override void SetColorBlock(Selectable selectable, Color? normal = null,
10378 SetColorBlock ( selectable , colors ) ;
10479 }
10580
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 ;
11083 }
11184}
11285
11386public static class MonoExtensions
11487{
88+ // Helpers to use the same style of AddListener that IL2CPP uses.
89+
11590 public static void AddListener ( this UnityEvent _event , Action listener )
116- {
117- _event . AddListener ( new UnityAction ( listener ) ) ;
118- }
91+ => _event . AddListener ( new UnityAction ( listener ) ) ;
11992
12093 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 ) ) ;
12495
12596 public static void RemoveListener ( this UnityEvent _event , Action listener )
126- {
127- _event . RemoveListener ( new UnityAction ( listener ) ) ;
128- }
97+ => _event . RemoveListener ( new UnityAction ( listener ) ) ;
12998
13099 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 ) ) ;
134101
135- public static void Clear ( this StringBuilder sb )
136- {
137- sb . Remove ( 0 , sb . Length ) ;
138- }
102+ // Doesn't exist in NET 3.5
139103
140- private static PropertyInfo pi_childControlHeight ;
104+ public static void Clear ( this StringBuilder sb )
105+ => sb . Remove ( 0 , sb . Length ) ;
141106
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.
146108
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 ) ;
149112
150- private static PropertyInfo pi_childControlWidth ;
151113
152114 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 ) ;
159117}
160118
161119#endif
0 commit comments