@@ -12,22 +12,24 @@ namespace Explorer
1212 public class GameObjectWindow : UIWindow
1313 {
1414 public override string Title => WindowManager . TabView
15- ? $ "<color=cyan>[G]</color> { m_object . name } "
16- : $ "GameObject Inspector ({ m_object . name } )";
15+ ? $ "<color=cyan>[G]</color> { TargetGO . name } "
16+ : $ "GameObject Inspector ({ TargetGO . name } )";
1717
18- public GameObject m_object ;
18+ public GameObject TargetGO ;
19+
20+ private bool m_hideControls ;
1921
2022 // gui element holders
2123 private string m_name ;
2224 private string m_scene ;
2325
2426 private Transform [ ] m_children ;
2527 private Vector2 m_transformScroll = Vector2 . zero ;
26- private PageHelper ChildPages = new PageHelper ( ) ;
28+ private readonly PageHelper ChildPages = new PageHelper ( ) ;
2729
2830 private Component [ ] m_components ;
2931 private Vector2 m_compScroll = Vector2 . zero ;
30- private PageHelper CompPages = new PageHelper ( ) ;
32+ private readonly PageHelper CompPages = new PageHelper ( ) ;
3133
3234 private readonly Vector3 [ ] m_cachedInput = new Vector3 [ 3 ] ;
3335 private float m_translateAmount = 0.3f ;
@@ -42,7 +44,7 @@ public class GameObjectWindow : UIWindow
4244 private bool m_localContext ;
4345
4446 private readonly List < Component > m_cachedDestroyList = new List < Component > ( ) ;
45- // private string m_addComponentInput = "";
47+ private string m_addComponentInput = "" ;
4648
4749 private string m_setParentInput = "Enter a GameObject name or path" ;
4850
@@ -52,12 +54,12 @@ public bool GetObjectAsGameObject()
5254
5355 if ( targetType == typeof ( GameObject ) )
5456 {
55- m_object = Target as GameObject ;
57+ TargetGO = Target as GameObject ;
5658 return true ;
5759 }
5860 else if ( targetType == typeof ( Transform ) )
5961 {
60- m_object = ( Target as Transform ) . gameObject ;
62+ TargetGO = ( Target as Transform ) . gameObject ;
6163 return true ;
6264 }
6365
@@ -73,10 +75,10 @@ public override void Init()
7375 return ;
7476 }
7577
76- m_name = m_object . name ;
77- m_scene = string . IsNullOrEmpty ( m_object . scene . name )
78+ m_name = TargetGO . name ;
79+ m_scene = string . IsNullOrEmpty ( TargetGO . scene . name )
7880 ? "None (Asset/Resource)"
79- : m_object . scene . name ;
81+ : TargetGO . scene . name ;
8082
8183 CacheTransformValues ( ) ;
8284
@@ -87,15 +89,15 @@ private void CacheTransformValues()
8789 {
8890 if ( m_localContext )
8991 {
90- m_cachedInput [ 0 ] = m_object . transform . localPosition ;
91- m_cachedInput [ 1 ] = m_object . transform . localEulerAngles ;
92+ m_cachedInput [ 0 ] = TargetGO . transform . localPosition ;
93+ m_cachedInput [ 1 ] = TargetGO . transform . localEulerAngles ;
9294 }
9395 else
9496 {
95- m_cachedInput [ 0 ] = m_object . transform . position ;
96- m_cachedInput [ 1 ] = m_object . transform . eulerAngles ;
97+ m_cachedInput [ 0 ] = TargetGO . transform . position ;
98+ m_cachedInput [ 1 ] = TargetGO . transform . eulerAngles ;
9799 }
98- m_cachedInput [ 2 ] = m_object . transform . localScale ;
100+ m_cachedInput [ 2 ] = TargetGO . transform . localScale ;
99101 }
100102
101103 public override void Update ( )
@@ -118,7 +120,7 @@ public override void Update()
118120 }
119121 }
120122
121- if ( ! m_object && ! GetObjectAsGameObject ( ) )
123+ if ( ! TargetGO && ! GetObjectAsGameObject ( ) )
122124 {
123125 throw new Exception ( "Object is null!" ) ;
124126 }
@@ -127,22 +129,22 @@ public override void Update()
127129 {
128130 if ( m_localContext )
129131 {
130- m_object . transform . localPosition = m_frozenPosition ;
131- m_object . transform . localRotation = m_frozenRotation ;
132+ TargetGO . transform . localPosition = m_frozenPosition ;
133+ TargetGO . transform . localRotation = m_frozenRotation ;
132134 }
133135 else
134136 {
135- m_object . transform . position = m_frozenPosition ;
136- m_object . transform . rotation = m_frozenRotation ;
137+ TargetGO . transform . position = m_frozenPosition ;
138+ TargetGO . transform . rotation = m_frozenRotation ;
137139 }
138- m_object . transform . localScale = m_frozenScale ;
140+ TargetGO . transform . localScale = m_frozenScale ;
139141 }
140142
141143 // update child objects
142144 var childList = new List < Transform > ( ) ;
143- for ( int i = 0 ; i < m_object . transform . childCount ; i ++ )
145+ for ( int i = 0 ; i < TargetGO . transform . childCount ; i ++ )
144146 {
145- childList . Add ( m_object . transform . GetChild ( i ) ) ;
147+ childList . Add ( TargetGO . transform . GetChild ( i ) ) ;
146148 }
147149 childList . Sort ( ( a , b ) => b . childCount . CompareTo ( a . childCount ) ) ;
148150 m_children = childList . ToArray ( ) ;
@@ -151,7 +153,7 @@ public override void Update()
151153
152154 // update components
153155 var compList = new Il2CppSystem . Collections . Generic . List < Component > ( ) ;
154- m_object . GetComponentsInternal ( ReflectionHelpers . ComponentType , true , false , true , false , compList ) ;
156+ TargetGO . GetComponentsInternal ( ReflectionHelpers . ComponentType , true , false , true , false , compList ) ;
155157
156158 m_components = compList . ToArray ( ) ;
157159
@@ -221,7 +223,7 @@ public override void WindowFunction(int windowID)
221223 {
222224 if ( GUILayout . Button ( "<color=#00FF00>Send to Scene View</color>" , new GUILayoutOption [ ] { GUILayout . Width ( 150 ) } ) )
223225 {
224- ScenePage . Instance . SetTransformTarget ( m_object . transform ) ;
226+ ScenePage . Instance . SetTransformTarget ( TargetGO . transform ) ;
225227 MainMenu . SetCurrentPage ( 0 ) ;
226228 }
227229 }
@@ -233,12 +235,12 @@ public override void WindowFunction(int windowID)
233235
234236 GUILayout . BeginHorizontal ( null ) ;
235237 GUILayout . Label ( "Path:" , new GUILayoutOption [ ] { GUILayout . Width ( 50 ) } ) ;
236- string pathlabel = m_object . transform . GetGameObjectPath ( ) ;
237- if ( m_object . transform . parent != null )
238+ string pathlabel = TargetGO . transform . GetGameObjectPath ( ) ;
239+ if ( TargetGO . transform . parent != null )
238240 {
239241 if ( GUILayout . Button ( "<-" , new GUILayoutOption [ ] { GUILayout . Width ( 35 ) } ) )
240242 {
241- InspectGameObject ( m_object . transform . parent ) ;
243+ InspectGameObject ( TargetGO . transform . parent ) ;
242244 }
243245 }
244246 GUILayout . TextArea ( pathlabel , null ) ;
@@ -360,6 +362,28 @@ private void ComponentList(Rect m_rect)
360362 }
361363 GUILayout . EndHorizontal ( ) ;
362364
365+ GUILayout . BeginHorizontal ( null ) ;
366+ m_addComponentInput = GUILayout . TextField ( m_addComponentInput , new GUILayoutOption [ ] { GUILayout . Width ( 130 ) } ) ;
367+ if ( GUILayout . Button ( "Add Comp" , null ) )
368+ {
369+ if ( ReflectionHelpers . GetTypeByName ( m_addComponentInput ) is Type compType )
370+ {
371+ if ( typeof ( Component ) . IsAssignableFrom ( compType ) )
372+ {
373+ TargetGO . AddComponent ( Il2CppType . From ( compType ) ) ;
374+ }
375+ else
376+ {
377+ MelonLogger . LogWarning ( $ "Type '{ compType . Name } ' is not assignable from Component!") ;
378+ }
379+ }
380+ else
381+ {
382+ MelonLogger . LogWarning ( $ "Could not find a type by the name of '{ m_addComponentInput } '!") ;
383+ }
384+ }
385+ GUILayout . EndHorizontal ( ) ;
386+
363387 GUI . skin . button . alignment = TextAnchor . MiddleLeft ;
364388 if ( m_cachedDestroyList . Count > 0 )
365389 {
@@ -439,21 +463,41 @@ private void BehaviourEnabledBtn(Behaviour obj)
439463
440464 private void GameObjectControls ( )
441465 {
466+ if ( m_hideControls )
467+ {
468+ GUILayout . BeginHorizontal ( null ) ;
469+ GUILayout . Label ( "<b><size=15>GameObject Controls</size></b>" , new GUILayoutOption [ ] { GUILayout . Width ( 200 ) } ) ;
470+ if ( GUILayout . Button ( "^ Show ^" , new GUILayoutOption [ ] { GUILayout . Width ( 75 ) } ) )
471+ {
472+ m_hideControls = false ;
473+ }
474+ GUILayout . EndHorizontal ( ) ;
475+
476+ return ;
477+ }
478+
442479 GUILayout . BeginVertical ( GUI . skin . box , new GUILayoutOption [ ] { GUILayout . Width ( 520 ) } ) ;
443- GUILayout . Label ( "<b><size=15>GameObject Controls</size></b>" , null ) ;
444480
445481 GUILayout . BeginHorizontal ( null ) ;
446- bool m_active = m_object . activeSelf ;
482+ GUILayout . Label ( "<b><size=15>GameObject Controls</size></b>" , new GUILayoutOption [ ] { GUILayout . Width ( 200 ) } ) ;
483+ if ( GUILayout . Button ( "v Hide v" , new GUILayoutOption [ ] { GUILayout . Width ( 75 ) } ) )
484+ {
485+ m_hideControls = true ;
486+ }
487+ GUILayout . EndHorizontal ( ) ;
488+
489+ GUILayout . BeginHorizontal ( null ) ;
490+ bool m_active = TargetGO . activeSelf ;
447491 m_active = GUILayout . Toggle ( m_active , ( m_active ? "<color=lime>Enabled " : "<color=red>Disabled" ) + "</color>" ,
448492 new GUILayoutOption [ ] { GUILayout . Width ( 80 ) } ) ;
449- if ( m_object . activeSelf != m_active ) { m_object . SetActive ( m_active ) ; }
493+ if ( TargetGO . activeSelf != m_active ) { TargetGO . SetActive ( m_active ) ; }
450494
451- UIHelpers . InstantiateButton ( m_object , 100 ) ;
495+ UIHelpers . InstantiateButton ( TargetGO , 100 ) ;
452496
453497 if ( GUILayout . Button ( "Set DontDestroyOnLoad" , new GUILayoutOption [ ] { GUILayout . Width ( 170 ) } ) )
454498 {
455- GameObject . DontDestroyOnLoad ( m_object ) ;
456- m_object . hideFlags |= HideFlags . DontUnloadUnusedAsset ;
499+ GameObject . DontDestroyOnLoad ( TargetGO ) ;
500+ TargetGO . hideFlags |= HideFlags . DontUnloadUnusedAsset ;
457501 }
458502
459503 var lbl = m_freeze ? "<color=lime>Unfreeze</color>" : "<color=orange>Freeze Pos/Rot</color>" ;
@@ -474,7 +518,7 @@ private void GameObjectControls()
474518 {
475519 if ( GameObject . Find ( m_setParentInput ) is GameObject newparent )
476520 {
477- m_object . transform . parent = newparent . transform ;
521+ TargetGO . transform . parent = newparent . transform ;
478522 }
479523 else
480524 {
@@ -484,7 +528,7 @@ private void GameObjectControls()
484528
485529 if ( GUILayout . Button ( "Detach from parent" , new GUILayoutOption [ ] { GUILayout . Width ( 160 ) } ) )
486530 {
487- m_object . transform . parent = null ;
531+ TargetGO . transform . parent = null ;
488532 }
489533 GUILayout . EndHorizontal ( ) ;
490534
@@ -499,15 +543,15 @@ private void GameObjectControls()
499543 {
500544 if ( m_localContext )
501545 {
502- m_object . transform . localPosition = m_cachedInput [ 0 ] ;
503- m_object . transform . localEulerAngles = m_cachedInput [ 1 ] ;
546+ TargetGO . transform . localPosition = m_cachedInput [ 0 ] ;
547+ TargetGO . transform . localEulerAngles = m_cachedInput [ 1 ] ;
504548 }
505549 else
506550 {
507- m_object . transform . position = m_cachedInput [ 0 ] ;
508- m_object . transform . eulerAngles = m_cachedInput [ 1 ] ;
551+ TargetGO . transform . position = m_cachedInput [ 0 ] ;
552+ TargetGO . transform . eulerAngles = m_cachedInput [ 1 ] ;
509553 }
510- m_object . transform . localScale = m_cachedInput [ 2 ] ;
554+ TargetGO . transform . localScale = m_cachedInput [ 2 ] ;
511555
512556 if ( m_freeze )
513557 {
@@ -541,7 +585,7 @@ private void GameObjectControls()
541585
542586 if ( GUILayout . Button ( "<color=red><b>Destroy</b></color>" , new GUILayoutOption [ ] { GUILayout . Width ( 120 ) } ) )
543587 {
544- GameObject . Destroy ( m_object ) ;
588+ GameObject . Destroy ( TargetGO ) ;
545589 DestroyWindow ( ) ;
546590 return ;
547591 }
@@ -553,15 +597,15 @@ private void UpdateFreeze()
553597 {
554598 if ( m_localContext )
555599 {
556- m_frozenPosition = m_object . transform . localPosition ;
557- m_frozenRotation = m_object . transform . localRotation ;
600+ m_frozenPosition = TargetGO . transform . localPosition ;
601+ m_frozenRotation = TargetGO . transform . localRotation ;
558602 }
559603 else
560604 {
561- m_frozenPosition = m_object . transform . position ;
562- m_frozenRotation = m_object . transform . rotation ;
605+ m_frozenPosition = TargetGO . transform . position ;
606+ m_frozenRotation = TargetGO . transform . rotation ;
563607 }
564- m_frozenScale = m_object . transform . localScale ;
608+ m_frozenScale = TargetGO . transform . localScale ;
565609 }
566610
567611 private void BoolToggle ( ref bool value , string message )
@@ -586,7 +630,7 @@ private Vector3 TranslateControl(TranslateType mode, ref float amount, bool mult
586630 GUILayout . Label ( $ "<color=cyan><b>{ ( m_localContext ? "Local " : "" ) } { mode } </b></color>:",
587631 new GUILayoutOption [ ] { GUILayout . Width ( m_localContext ? 110 : 65 ) } ) ;
588632
589- var transform = m_object . transform ;
633+ var transform = TargetGO . transform ;
590634 switch ( mode )
591635 {
592636 case TranslateType . Position :
0 commit comments