11using UnityEditor ;
2+ using UnityEngine ;
23using UnityEngine . UIElements ;
34
45namespace QuickEye . WebTools . Editor
@@ -13,44 +14,52 @@ public static void Select(RequestData request, bool readOnly)
1314 }
1415
1516 private ExchangeInspector _inspectorController ;
16- private VisualElement _fullWindowRoot ;
1717
1818 public override VisualElement CreateInspectorGUI ( )
1919 {
2020 var root = GetRoot ( ) ;
21- InitViewController ( ) ;
21+ InitViewController ( root ) ;
2222 return root ;
2323 }
2424
25- private void InitViewController ( )
25+ private void InitViewController ( VisualElement root )
2626 {
2727 var uxml = AssetDatabase . LoadAssetAtPath < VisualTreeAsset > (
2828 "Packages/com.quickeye.http-debugger/Editor/UIAssets/ExchangeInspector.uxml" ) ;
29- uxml . CloneTree ( _fullWindowRoot ) ;
30- _inspectorController = new ExchangeInspector ( _fullWindowRoot ) ;
31- var readOnly = serializedObject . FindProperty ( "isReadOnly" ) . boolValue ;
29+ uxml . CloneTree ( root ) ;
30+ _inspectorController = new ExchangeInspector ( root ) ;
3231 _inspectorController . Setup ( serializedObject ) ;
3332 }
3433
3534 private VisualElement GetRoot ( )
3635 {
3736 var root = new VisualElement ( ) ;
38- _fullWindowRoot = new VisualElement ( ) ;
39- StretchVe ( _fullWindowRoot ) ;
37+ root . name = "exchange-inspector" ;
38+
39+ var styleSheet = AssetDatabase . LoadAssetAtPath < StyleSheet > (
40+ "Packages/com.quickeye.http-debugger/Editor/UIAssets/ExchangeInspector.style.uss" ) ;
4041
4142 root . RegisterCallback < AttachToPanelEvent > ( evt =>
4243 {
43- var fullParent = evt . destinationPanel . visualTree . Q ( null , "unity-inspector-main-container" ) ;
44- fullParent . Add ( _fullWindowRoot ) ;
44+ EnableClassForAllParents ( root , "exchange-inspector-ancestor" , true ) ;
45+ evt . destinationPanel . visualTree . styleSheets . Add ( styleSheet ) ;
46+ } ) ;
47+ root . RegisterCallback < DetachFromPanelEvent > ( evt =>
48+ {
49+ //change to destination panel to cause an exception
50+ evt . originPanel ? . visualTree ? . styleSheets . Remove ( styleSheet ) ;
4551 } ) ;
46- root . RegisterCallback < DetachFromPanelEvent > ( evt => { _fullWindowRoot . RemoveFromHierarchy ( ) ; } ) ;
4752 return root ;
4853 }
4954
50- private static void StretchVe ( VisualElement ve )
55+ private static void EnableClassForAllParents ( VisualElement root , string className , bool enabled )
5156 {
52- ve . style . position = Position . Absolute ;
53- ve . style . bottom = ve . style . top = ve . style . left = ve . style . right = 0 ;
57+ root = root . hierarchy . parent ;
58+ while ( root != null )
59+ {
60+ root . EnableInClassList ( className , enabled ) ;
61+ root = root . hierarchy . parent ;
62+ }
5463 }
5564
5665 public override bool UseDefaultMargins ( ) => false ;
0 commit comments