Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit a5a07a0

Browse files
committed
Add RuntimeProvider method for setting Selectable.colors
1 parent e0fd682 commit a5a07a0

File tree

15 files changed

+102
-100
lines changed

15 files changed

+102
-100
lines changed

src/Core/Runtime/Il2Cpp/Il2CppProvider.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,22 @@ public static int GetRootCount(int handle)
160160
.Invoke(handle);
161161
}
162162

163-
internal static bool triedToGetProperties;
163+
internal static bool triedToGetColorBlockProps;
164164
internal static PropertyInfo _normalColorProp;
165165
internal static PropertyInfo _highlightColorProp;
166166
internal static PropertyInfo _pressedColorProp;
167167

168-
public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
168+
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null)
169169
{
170+
var colors = selectable.colors;
171+
170172
colors.colorMultiplier = 1;
171173

172174
object boxed = (object)colors;
173175

174-
if (!triedToGetProperties)
176+
if (!triedToGetColorBlockProps)
175177
{
176-
triedToGetProperties = true;
178+
triedToGetColorBlockProps = true;
177179

178180
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") is PropertyInfo norm && norm.CanWrite)
179181
_normalColorProp = norm;
@@ -209,11 +211,32 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null
209211
fi.SetValue(boxed, (Color)pressed);
210212
}
211213
}
212-
catch { }
214+
catch (Exception ex)
215+
{
216+
ExplorerCore.Log(ex);
217+
}
213218

214219
colors = (ColorBlock)boxed;
215220

216-
return colors;
221+
SetColorBlock(selectable, colors);
222+
}
223+
224+
public override void SetColorBlock(Selectable selectable, ColorBlock _colorBlock)
225+
{
226+
try
227+
{
228+
selectable = selectable.TryCast<Selectable>();
229+
230+
ReflectionUtility.GetPropertyInfo(typeof(Selectable), "m_Colors")
231+
.SetValue(selectable, _colorBlock, null);
232+
233+
ReflectionUtility.GetMethodInfo(typeof(Selectable), "OnSetProperty", new Type[0])
234+
.Invoke(selectable, new object[0]);
235+
}
236+
catch (Exception ex)
237+
{
238+
ExplorerCore.Log(ex);
239+
}
217240
}
218241

219242
public override void FindSingleton(string[] possibleNames, Type type, BF flags, List<object> instances)

src/Core/Runtime/Mono/MonoProvider.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ public override int GetRootCount(Scene scene)
8686
return scene.rootCount;
8787
}
8888

89-
public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
89+
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null)
9090
{
91+
var colors = selectable.colors;
92+
9193
if (normal != null)
9294
colors.normalColor = (Color)normal;
9395

@@ -97,7 +99,12 @@ public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null
9799
if (pressed != null)
98100
colors.pressedColor = (Color)pressed;
99101

100-
return colors;
102+
SetColorBlock(selectable, colors);
103+
}
104+
105+
public override void SetColorBlock(Selectable selectable, ColorBlock colors)
106+
{
107+
selectable.colors = colors;
101108
}
102109
}
103110
}

src/Core/Runtime/RuntimeProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public static void Init() =>
6262

6363
public abstract int GetRootCount(Scene scene);
6464

65-
public abstract ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null);
65+
public abstract void SetColorBlock(Selectable selectable, ColorBlock colors);
66+
67+
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null);
6668

6769
public virtual void FindSingleton(string[] s_instanceNames, Type type, BindingFlags flags, List<object> instances)
6870
{

src/UI/CacheObject/CacheMember.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,13 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
319319
default, new Color(1, 1, 1, 0));
320320
UIFactory.SetLayoutElement(evalGroupObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 5000);
321321

322-
var colors = new ColorBlock();
323-
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
324-
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));
325-
326322
var evalButton = UIFactory.CreateButton(evalGroupObj,
327323
"EvalButton",
328324
$"Evaluate ({ParamCount})",
329-
null,
330-
colors);
325+
null);
326+
327+
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f),
328+
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));
331329

332330
UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0);
333331

@@ -345,7 +343,7 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
345343
argsHolder.SetActive(true);
346344
m_isEvaluating = true;
347345
evalText.text = "Evaluate";
348-
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.3f, 0.6f, 0.3f));
346+
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.3f, 0.6f, 0.3f));
349347

350348
cancelButton.gameObject.SetActive(true);
351349
}
@@ -365,18 +363,17 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
365363
m_isEvaluating = false;
366364

367365
evalText.text = $"Evaluate ({ParamCount})";
368-
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.4f, 0.4f, 0.4f));
366+
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f));
369367
});
370368
}
371369
else if (this is CacheMethod)
372370
{
373371
// simple method evaluate button
374372

375-
var colors = new ColorBlock();
376-
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
373+
var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); });
374+
RuntimeProvider.Instance.SetColorBlock(evalButton, new Color(0.4f, 0.4f, 0.4f),
377375
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));
378376

379-
var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); }, colors);
380377
UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0);
381378
}
382379
}

src/UI/Inspectors/GameObjects/ChildList.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,13 @@ internal void AddChildListButton()
168168
s_childListToggles.Add(toggle);
169169
toggle.onValueChanged.AddListener((bool val) => { OnToggleClicked(thisIndex, val); });
170170

171-
ColorBlock mainColors = new ColorBlock();
172-
mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f),
173-
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));
174-
175171
var mainBtn = UIFactory.CreateButton(btnGroupObj,
176172
"MainButton",
177173
"",
178-
() => { OnChildListObjectClicked(thisIndex); },
179-
mainColors);
174+
() => { OnChildListObjectClicked(thisIndex); });
175+
176+
RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f),
177+
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));
180178

181179
UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 9999);
182180

src/UI/Inspectors/GameObjects/ComponentList.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,13 @@ internal void AddCompListButton()
165165

166166
// Main component button
167167

168-
ColorBlock mainColors = new ColorBlock();
169-
mainColors = RuntimeProvider.Instance.SetColorBlock(mainColors, new Color(0.07f, 0.07f, 0.07f),
170-
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));
171-
172168
var mainBtn = UIFactory.CreateButton(groupObj,
173169
"MainButton",
174170
"",
175-
() => { OnCompListObjectClicked(thisIndex); },
176-
mainColors);
171+
() => { OnCompListObjectClicked(thisIndex); });
172+
173+
RuntimeProvider.Instance.SetColorBlock(mainBtn, new Color(0.07f, 0.07f, 0.07f),
174+
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.05f, 0.05f, 0.05f));
177175

178176
UIFactory.SetLayoutElement(mainBtn.gameObject, minHeight: 25, flexibleHeight: 0, minWidth: 25, flexibleWidth: 999);
179177

src/UI/Inspectors/GameObjects/GameObjectControls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ internal GameObject ConstructEditorRow(GameObject parent, ControlEditor editor,
408408
var sliderObj = UIFactory.CreateSlider(rowObject, "VectorSlider", out Slider slider);
409409
UIFactory.SetLayoutElement(sliderObj, minHeight: 20, flexibleHeight: 0, minWidth: 200, flexibleWidth: 9000);
410410
sliderObj.transform.Find("Fill Area").gameObject.SetActive(false);
411-
slider.colors = RuntimeProvider.Instance.SetColorBlock(slider.colors, new Color(0.65f, 0.65f, 0.65f));
411+
RuntimeProvider.Instance.SetColorBlock(slider, new Color(0.65f, 0.65f, 0.65f));
412412
slider.minValue = -2;
413413
slider.maxValue = 2;
414414
slider.value = 0;

src/UI/Inspectors/InspectorManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ public void UnsetInspectorTab()
130130
public void OnSetInspectorTab(InspectorBase inspector)
131131
{
132132
Color activeColor = new Color(0, 0.25f, 0, 1);
133-
inspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton.colors, activeColor, activeColor);
133+
RuntimeProvider.Instance.SetColorBlock(inspector.m_tabButton, activeColor, activeColor);
134134
}
135135

136136
public void OnUnsetInspectorTab()
137137
{
138-
m_activeInspector.m_tabButton.colors = RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton.colors,
138+
RuntimeProvider.Instance.SetColorBlock(m_activeInspector.m_tabButton,
139139
new Color(0.2f, 0.2f, 0.2f, 1), new Color(0.1f, 0.3f, 0.1f, 1));
140140
}
141141

src/UI/Inspectors/Reflection/InstanceInspector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public InstanceInspector(object target) : base(target) { }
3030
internal void OnScopeFilterClicked(MemberScopes type, Button button)
3131
{
3232
if (m_lastActiveScopeButton)
33-
m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.2f, 0.2f));
33+
RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.2f, 0.2f));
3434

3535
m_scopeFilter = type;
3636
m_lastActiveScopeButton = button;
3737

38-
m_lastActiveScopeButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton.colors, new Color(0.2f, 0.6f, 0.2f));
38+
RuntimeProvider.Instance.SetColorBlock(m_lastActiveScopeButton, new Color(0.2f, 0.6f, 0.2f));
3939

4040
FilterMembers(null, true);
4141
m_sliderScroller.m_slider.value = 1f;
@@ -240,11 +240,11 @@ private void AddFilterButton(GameObject parent, MemberScopes type, bool setEnabl
240240

241241
btn.onClick.AddListener(() => { OnScopeFilterClicked(type, btn); });
242242

243-
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f));
243+
RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f));
244244

245245
if (setEnabled)
246246
{
247-
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f));
247+
RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f));
248248
m_scopeFilter = type;
249249
m_lastActiveScopeButton = btn;
250250
}

src/UI/Inspectors/Reflection/ReflectionInspector.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ public override void Update()
241241
internal void OnMemberFilterClicked(MemberTypes type, Button button)
242242
{
243243
if (m_lastActiveMemButton)
244-
m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.2f, 0.2f));
244+
RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.2f, 0.2f));
245245

246246
m_memberFilter = type;
247247
m_lastActiveMemButton = button;
248248

249-
m_lastActiveMemButton.colors = RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton.colors, new Color(0.2f, 0.6f, 0.2f));
249+
RuntimeProvider.Instance.SetColorBlock(m_lastActiveMemButton, new Color(0.2f, 0.6f, 0.2f));
250250

251251
FilterMembers(null, true);
252252
m_sliderScroller.m_slider.value = 1f;
@@ -461,11 +461,11 @@ private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnable
461461
UIFactory.SetLayoutElement(btn.gameObject, minHeight: 25, minWidth: 70);
462462
btn.onClick.AddListener(() => { OnMemberFilterClicked(type, btn); });
463463

464-
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, highlighted: new Color(0.3f, 0.7f, 0.3f));
464+
RuntimeProvider.Instance.SetColorBlock(btn, highlighted: new Color(0.3f, 0.7f, 0.3f));
465465

466466
if (setEnabled)
467467
{
468-
btn.colors = RuntimeProvider.Instance.SetColorBlock(btn.colors, new Color(0.2f, 0.6f, 0.2f));
468+
RuntimeProvider.Instance.SetColorBlock(btn, new Color(0.2f, 0.6f, 0.2f));
469469
m_memberFilter = type;
470470
m_lastActiveMemButton = btn;
471471
}

0 commit comments

Comments
 (0)