Skip to content

Commit 2763b85

Browse files
committed
fix(Project Inspector): Override column. Reset all override components
1 parent 4ecb9a5 commit 2763b85

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

Editor/Scripts/Hierarchy/ProjectInspectorWindow.cs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEditor.UIElements;
44
using UnityEngine.UIElements;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using OC.Communication;
78
using OC.VisualElements;
89
using 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

Comments
 (0)