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

Commit a1c2dfb

Browse files
committed
Add support for setting disabled color on ColoBlock
1 parent a5a07a0 commit a1c2dfb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/Core/Runtime/Il2Cpp/Il2CppProvider.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ public static int GetRootCount(int handle)
164164
internal static PropertyInfo _normalColorProp;
165165
internal static PropertyInfo _highlightColorProp;
166166
internal static PropertyInfo _pressedColorProp;
167+
internal static PropertyInfo _disabledColorProp;
167168

168-
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null)
169+
public override void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,
170+
Color? disabled = null)
169171
{
170172
var colors = selectable.colors;
171173

@@ -183,6 +185,8 @@ public override void SetColorBlock(Selectable selectable, Color? normal = null,
183185
_highlightColorProp = high;
184186
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "pressedColor") is PropertyInfo pres && pres.CanWrite)
185187
_pressedColorProp = pres;
188+
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "disabledColor") is PropertyInfo disa && disa.CanWrite)
189+
_disabledColorProp = disa;
186190
}
187191

188192
try
@@ -210,6 +214,14 @@ public override void SetColorBlock(Selectable selectable, Color? normal = null,
210214
else if (ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_PressedColor") is FieldInfo fi)
211215
fi.SetValue(boxed, (Color)pressed);
212216
}
217+
218+
if (disabled != null)
219+
{
220+
if (_disabledColorProp != null)
221+
_disabledColorProp.SetValue(boxed, (Color)disabled);
222+
else if (ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_DisabledColor") is FieldInfo fi)
223+
fi.SetValue(boxed, (Color)disabled);
224+
}
213225
}
214226
catch (Exception ex)
215227
{

src/Core/Runtime/Mono/MonoProvider.cs

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

89-
public override void SetColorBlock(Selectable selectable, 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,
90+
Color? disabled = null)
9091
{
9192
var colors = selectable.colors;
9293

@@ -99,6 +100,9 @@ public override void SetColorBlock(Selectable selectable, Color? normal = null,
99100
if (pressed != null)
100101
colors.pressedColor = (Color)pressed;
101102

103+
if (disabled != null)
104+
colors.disabledColor = (Color)disabled;
105+
102106
SetColorBlock(selectable, colors);
103107
}
104108

src/Core/Runtime/RuntimeProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public static void Init() =>
6464

6565
public abstract void SetColorBlock(Selectable selectable, ColorBlock colors);
6666

67-
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null);
67+
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,
68+
Color? disabled = null);
6869

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

0 commit comments

Comments
 (0)