@@ -12,22 +12,24 @@ namespace Explorer
12
12
public class GameObjectWindow : UIWindow
13
13
{
14
14
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 } )";
17
17
18
- public GameObject m_object ;
18
+ public GameObject TargetGO ;
19
+
20
+ private bool m_hideControls ;
19
21
20
22
// gui element holders
21
23
private string m_name ;
22
24
private string m_scene ;
23
25
24
26
private Transform [ ] m_children ;
25
27
private Vector2 m_transformScroll = Vector2 . zero ;
26
- private PageHelper ChildPages = new PageHelper ( ) ;
28
+ private readonly PageHelper ChildPages = new PageHelper ( ) ;
27
29
28
30
private Component [ ] m_components ;
29
31
private Vector2 m_compScroll = Vector2 . zero ;
30
- private PageHelper CompPages = new PageHelper ( ) ;
32
+ private readonly PageHelper CompPages = new PageHelper ( ) ;
31
33
32
34
private readonly Vector3 [ ] m_cachedInput = new Vector3 [ 3 ] ;
33
35
private float m_translateAmount = 0.3f ;
@@ -42,7 +44,7 @@ public class GameObjectWindow : UIWindow
42
44
private bool m_localContext ;
43
45
44
46
private readonly List < Component > m_cachedDestroyList = new List < Component > ( ) ;
45
- // private string m_addComponentInput = "";
47
+ private string m_addComponentInput = "" ;
46
48
47
49
private string m_setParentInput = "Enter a GameObject name or path" ;
48
50
@@ -52,12 +54,12 @@ public bool GetObjectAsGameObject()
52
54
53
55
if ( targetType == typeof ( GameObject ) )
54
56
{
55
- m_object = Target as GameObject ;
57
+ TargetGO = Target as GameObject ;
56
58
return true ;
57
59
}
58
60
else if ( targetType == typeof ( Transform ) )
59
61
{
60
- m_object = ( Target as Transform ) . gameObject ;
62
+ TargetGO = ( Target as Transform ) . gameObject ;
61
63
return true ;
62
64
}
63
65
@@ -73,10 +75,10 @@ public override void Init()
73
75
return ;
74
76
}
75
77
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 )
78
80
? "None (Asset/Resource)"
79
- : m_object . scene . name ;
81
+ : TargetGO . scene . name ;
80
82
81
83
CacheTransformValues ( ) ;
82
84
@@ -87,15 +89,15 @@ private void CacheTransformValues()
87
89
{
88
90
if ( m_localContext )
89
91
{
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 ;
92
94
}
93
95
else
94
96
{
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 ;
97
99
}
98
- m_cachedInput [ 2 ] = m_object . transform . localScale ;
100
+ m_cachedInput [ 2 ] = TargetGO . transform . localScale ;
99
101
}
100
102
101
103
public override void Update ( )
@@ -118,7 +120,7 @@ public override void Update()
118
120
}
119
121
}
120
122
121
- if ( ! m_object && ! GetObjectAsGameObject ( ) )
123
+ if ( ! TargetGO && ! GetObjectAsGameObject ( ) )
122
124
{
123
125
throw new Exception ( "Object is null!" ) ;
124
126
}
@@ -127,22 +129,22 @@ public override void Update()
127
129
{
128
130
if ( m_localContext )
129
131
{
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 ;
132
134
}
133
135
else
134
136
{
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 ;
137
139
}
138
- m_object . transform . localScale = m_frozenScale ;
140
+ TargetGO . transform . localScale = m_frozenScale ;
139
141
}
140
142
141
143
// update child objects
142
144
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 ++ )
144
146
{
145
- childList . Add ( m_object . transform . GetChild ( i ) ) ;
147
+ childList . Add ( TargetGO . transform . GetChild ( i ) ) ;
146
148
}
147
149
childList . Sort ( ( a , b ) => b . childCount . CompareTo ( a . childCount ) ) ;
148
150
m_children = childList . ToArray ( ) ;
@@ -151,7 +153,7 @@ public override void Update()
151
153
152
154
// update components
153
155
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 ) ;
155
157
156
158
m_components = compList . ToArray ( ) ;
157
159
@@ -221,7 +223,7 @@ public override void WindowFunction(int windowID)
221
223
{
222
224
if ( GUILayout . Button ( "<color=#00FF00>Send to Scene View</color>" , new GUILayoutOption [ ] { GUILayout . Width ( 150 ) } ) )
223
225
{
224
- ScenePage . Instance . SetTransformTarget ( m_object . transform ) ;
226
+ ScenePage . Instance . SetTransformTarget ( TargetGO . transform ) ;
225
227
MainMenu . SetCurrentPage ( 0 ) ;
226
228
}
227
229
}
@@ -233,12 +235,12 @@ public override void WindowFunction(int windowID)
233
235
234
236
GUILayout . BeginHorizontal ( null ) ;
235
237
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 )
238
240
{
239
241
if ( GUILayout . Button ( "<-" , new GUILayoutOption [ ] { GUILayout . Width ( 35 ) } ) )
240
242
{
241
- InspectGameObject ( m_object . transform . parent ) ;
243
+ InspectGameObject ( TargetGO . transform . parent ) ;
242
244
}
243
245
}
244
246
GUILayout . TextArea ( pathlabel , null ) ;
@@ -360,6 +362,28 @@ private void ComponentList(Rect m_rect)
360
362
}
361
363
GUILayout . EndHorizontal ( ) ;
362
364
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
+
363
387
GUI . skin . button . alignment = TextAnchor . MiddleLeft ;
364
388
if ( m_cachedDestroyList . Count > 0 )
365
389
{
@@ -439,21 +463,41 @@ private void BehaviourEnabledBtn(Behaviour obj)
439
463
440
464
private void GameObjectControls ( )
441
465
{
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
+
442
479
GUILayout . BeginVertical ( GUI . skin . box , new GUILayoutOption [ ] { GUILayout . Width ( 520 ) } ) ;
443
- GUILayout . Label ( "<b><size=15>GameObject Controls</size></b>" , null ) ;
444
480
445
481
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 ;
447
491
m_active = GUILayout . Toggle ( m_active , ( m_active ? "<color=lime>Enabled " : "<color=red>Disabled" ) + "</color>" ,
448
492
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 ) ; }
450
494
451
- UIHelpers . InstantiateButton ( m_object , 100 ) ;
495
+ UIHelpers . InstantiateButton ( TargetGO , 100 ) ;
452
496
453
497
if ( GUILayout . Button ( "Set DontDestroyOnLoad" , new GUILayoutOption [ ] { GUILayout . Width ( 170 ) } ) )
454
498
{
455
- GameObject . DontDestroyOnLoad ( m_object ) ;
456
- m_object . hideFlags |= HideFlags . DontUnloadUnusedAsset ;
499
+ GameObject . DontDestroyOnLoad ( TargetGO ) ;
500
+ TargetGO . hideFlags |= HideFlags . DontUnloadUnusedAsset ;
457
501
}
458
502
459
503
var lbl = m_freeze ? "<color=lime>Unfreeze</color>" : "<color=orange>Freeze Pos/Rot</color>" ;
@@ -474,7 +518,7 @@ private void GameObjectControls()
474
518
{
475
519
if ( GameObject . Find ( m_setParentInput ) is GameObject newparent )
476
520
{
477
- m_object . transform . parent = newparent . transform ;
521
+ TargetGO . transform . parent = newparent . transform ;
478
522
}
479
523
else
480
524
{
@@ -484,7 +528,7 @@ private void GameObjectControls()
484
528
485
529
if ( GUILayout . Button ( "Detach from parent" , new GUILayoutOption [ ] { GUILayout . Width ( 160 ) } ) )
486
530
{
487
- m_object . transform . parent = null ;
531
+ TargetGO . transform . parent = null ;
488
532
}
489
533
GUILayout . EndHorizontal ( ) ;
490
534
@@ -499,15 +543,15 @@ private void GameObjectControls()
499
543
{
500
544
if ( m_localContext )
501
545
{
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 ] ;
504
548
}
505
549
else
506
550
{
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 ] ;
509
553
}
510
- m_object . transform . localScale = m_cachedInput [ 2 ] ;
554
+ TargetGO . transform . localScale = m_cachedInput [ 2 ] ;
511
555
512
556
if ( m_freeze )
513
557
{
@@ -541,7 +585,7 @@ private void GameObjectControls()
541
585
542
586
if ( GUILayout . Button ( "<color=red><b>Destroy</b></color>" , new GUILayoutOption [ ] { GUILayout . Width ( 120 ) } ) )
543
587
{
544
- GameObject . Destroy ( m_object ) ;
588
+ GameObject . Destroy ( TargetGO ) ;
545
589
DestroyWindow ( ) ;
546
590
return ;
547
591
}
@@ -553,15 +597,15 @@ private void UpdateFreeze()
553
597
{
554
598
if ( m_localContext )
555
599
{
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 ;
558
602
}
559
603
else
560
604
{
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 ;
563
607
}
564
- m_frozenScale = m_object . transform . localScale ;
608
+ m_frozenScale = TargetGO . transform . localScale ;
565
609
}
566
610
567
611
private void BoolToggle ( ref bool value , string message )
@@ -586,7 +630,7 @@ private Vector3 TranslateControl(TranslateType mode, ref float amount, bool mult
586
630
GUILayout . Label ( $ "<color=cyan><b>{ ( m_localContext ? "Local " : "" ) } { mode } </b></color>:",
587
631
new GUILayoutOption [ ] { GUILayout . Width ( m_localContext ? 110 : 65 ) } ) ;
588
632
589
- var transform = m_object . transform ;
633
+ var transform = TargetGO . transform ;
590
634
switch ( mode )
591
635
{
592
636
case TranslateType . Position :
0 commit comments