33using UnityEngine ;
44using Explorer . UI . Shared ;
55using Explorer . UI . Main ;
6+ using Explorer . Unstrip . LayerMasks ;
67#if CPP
78using UnhollowerRuntimeLib ;
89#endif
@@ -17,6 +18,8 @@ public class GameObjectInspector : WindowBase
1718
1819 public GameObject TargetGO ;
1920
21+ public bool pendingDestroy ;
22+
2023 private static bool m_hideControls ;
2124
2225 // gui element holders
@@ -43,6 +46,8 @@ public class GameObjectInspector : WindowBase
4346 private bool m_autoUpdateTransform ;
4447 private bool m_localContext ;
4548
49+ private int m_layer ;
50+
4651 private readonly List < Component > m_cachedDestroyList = new List < Component > ( ) ;
4752 private string m_addComponentInput = "" ;
4853
@@ -104,16 +109,16 @@ public override void Update()
104109 {
105110 try
106111 {
112+ if ( pendingDestroy ) return ;
113+
107114 if ( Target == null )
108115 {
109- ExplorerCore . Log ( "Target is null!" ) ;
110- DestroyWindow ( ) ;
116+ DestroyOnException ( new Exception ( "Target was destroyed." ) ) ;
111117 return ;
112118 }
113119 if ( ! TargetGO && ! GetObjectAsGameObject ( ) )
114120 {
115- ExplorerCore . Log ( "Target was destroyed!" ) ;
116- DestroyWindow ( ) ;
121+ DestroyOnException ( new Exception ( "Target was destroyed." ) ) ;
117122 return ;
118123 }
119124
@@ -132,6 +137,8 @@ public override void Update()
132137 TargetGO . transform . localScale = m_frozenScale ;
133138 }
134139
140+ m_layer = TargetGO . layer ;
141+
135142 // update child objects
136143 var childList = new List < Transform > ( ) ;
137144 for ( int i = 0 ; i < TargetGO . transform . childCount ; i ++ )
@@ -163,6 +170,7 @@ public override void Update()
163170 private void DestroyOnException ( Exception e )
164171 {
165172 ExplorerCore . Log ( $ "Exception drawing GameObject Window: { e . GetType ( ) } , { e . Message } ") ;
173+ pendingDestroy = true ;
166174 DestroyWindow ( ) ;
167175 }
168176
@@ -204,6 +212,8 @@ private void ReflectObject(object obj)
204212
205213 public override void WindowFunction ( int windowID )
206214 {
215+ if ( pendingDestroy ) return ;
216+
207217 try
208218 {
209219 var rect = WindowManager . TabView ? TabViewWindow . Instance . m_rect : this . m_rect ;
@@ -250,6 +260,8 @@ public override void WindowFunction(int windowID)
250260 GUIUnstrip . TextArea ( m_name , new GUILayoutOption [ 0 ] ) ;
251261 GUILayout . EndHorizontal ( ) ;
252262
263+ LayerControls ( ) ;
264+
253265 // --- Horizontal Columns section ---
254266 GUIUnstrip . BeginHorizontal ( new GUILayoutOption [ 0 ] ) ;
255267
@@ -280,6 +292,34 @@ public override void WindowFunction(int windowID)
280292 }
281293 }
282294
295+ private void LayerControls ( )
296+ {
297+ GUIUnstrip . BeginHorizontal ( ) ;
298+ GUILayout . Label ( "Layer:" , new GUILayoutOption [ ] { GUILayout . Width ( 50 ) } ) ;
299+
300+ if ( GUILayout . Button ( "<" , new GUILayoutOption [ ] { GUILayout . Width ( 30 ) } ) )
301+ {
302+ if ( m_layer > 0 )
303+ {
304+ m_layer -- ;
305+ if ( TargetGO ) TargetGO . layer = m_layer ;
306+ }
307+ }
308+ if ( GUILayout . Button ( ">" , new GUILayoutOption [ ] { GUILayout . Width ( 30 ) } ) )
309+ {
310+ if ( m_layer < 32 )
311+ {
312+ m_layer ++ ;
313+ if ( TargetGO ) TargetGO . layer = m_layer ;
314+ }
315+ }
316+
317+ GUILayout . Label ( $ "{ m_layer } (<color=cyan>{ LayerMaskUnstrip . LayerToName ( m_layer ) } </color>)",
318+ new GUILayoutOption [ ] { GUILayout . Width ( 200 ) } ) ;
319+
320+ GUILayout . EndHorizontal ( ) ;
321+ }
322+
283323 private void TransformList ( Rect m_rect )
284324 {
285325 GUIUnstrip . BeginVertical ( GUIContent . none , GUI . skin . box , null ) ;
0 commit comments