33using UnityEditor . UIElements ;
44using UnityEngine . UIElements ;
55using System . Collections . Generic ;
6+ using System . Linq ;
67using OC . Communication ;
78using OC . VisualElements ;
89using UnityEngine . SceneManagement ;
@@ -107,20 +108,22 @@ private MultiColumnTreeView CreateMultiColumnTreeView()
107108 } ;
108109
109110 columnLink . makeCell += MakeCellLink ;
110- columnLink . bindCell += ( element , i ) =>
111- {
112- var item = multiColumnTreeView . GetItemDataForIndex < HierarchyItem > ( i ) ;
113- if ( element is not Toggle toggle ) return ;
114- toggle . SetEnabled ( false ) ;
115- toggle . style . display = item . Component == null ? DisplayStyle . None : DisplayStyle . Flex ;
116- } ;
117-
118111 columnLink . bindCell += BindCellLink ;
119112 columnLink . unbindCell += UnbindCellLink ;
120113
114+ var columnOverride = new Column ( )
115+ {
116+ title = "Override" ,
117+ stretchable = false
118+ } ;
119+ columnOverride . makeCell += MakeCellOverride ;
120+ columnOverride . bindCell += BindCellOverride ;
121+ columnLink . unbindCell += UnbindCellOverride ;
122+
121123 multiColumnTreeView . columns . Add ( columnHierarchy ) ;
122124 multiColumnTreeView . columns . Add ( columnPath ) ;
123125 multiColumnTreeView . columns . Add ( columnLink ) ;
126+ multiColumnTreeView . columns . Add ( columnOverride ) ;
124127
125128 multiColumnTreeView . selectionChanged += OnSelectionChanged ;
126129 multiColumnTreeView . itemsChosen += OnItemsChosen ;
@@ -135,6 +138,13 @@ VisualElement MakeCellLink()
135138 return toggle ;
136139 }
137140
141+ VisualElement MakeCellOverride ( )
142+ {
143+ var toggle = new Toggle ( ) ;
144+ toggle . SetEnabled ( false ) ;
145+ return toggle ;
146+ }
147+
138148 void BindCellLink ( VisualElement visualElement , int i )
139149 {
140150 var item = multiColumnTreeView . GetItemDataForIndex < HierarchyItem > ( i ) ;
@@ -159,6 +169,31 @@ void UnbindCellLink(VisualElement visualElement, int i)
159169 if ( visualElement is not Toggle toggle ) return ;
160170 toggle . UnbindProperty ( ) ;
161171 }
172+
173+ void BindCellOverride ( VisualElement visualElement , int i )
174+ {
175+ var item = multiColumnTreeView . GetItemDataForIndex < HierarchyItem > ( i ) ;
176+ if ( visualElement is not Toggle toggle ) return ;
177+
178+ if ( item . Component == null )
179+ {
180+ toggle . style . display = DisplayStyle . None ;
181+ return ;
182+ }
183+
184+ if ( item . Component is not IDevice device ) return ;
185+
186+ toggle . style . display = DisplayStyle . Flex ;
187+
188+ toggle . SetValueWithoutNotify ( device . Override . Value ) ;
189+ toggle . BindProperty ( device . Override ) ;
190+ }
191+
192+ void UnbindCellOverride ( VisualElement visualElement , int i )
193+ {
194+ if ( visualElement is not Toggle toggle ) return ;
195+ toggle . UnbindProperty ( ) ;
196+ }
162197 }
163198
164199 private void OnItemsChosen ( IEnumerable < object > obj )
@@ -218,8 +253,12 @@ private void ApplySearchFilter(string filter)
218253
219254 private void ResetOverride ( )
220255 {
221- //TODO
222- Debug . Log ( $ "Reset Override") ;
256+ var devices = FindObjectsOfType < MonoBehaviour > ( ) . OfType < IDevice > ( ) . ToList ( ) ;
257+ foreach ( var item in devices . Where ( item => item . Override . Value ) )
258+ {
259+ item . Override . Value = false ;
260+ Logging . Logger . Log ( LogType . Warning , $ "Component Override is DISABLED: { item . Link . ScenePath } ") ;
261+ }
223262 }
224263 }
225264}
0 commit comments