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

Commit 7a2b4aa

Browse files
committed
Fix setting color block when partially stripped
1 parent 3762d14 commit 7a2b4aa

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/Core/Runtime/Il2Cpp/Il2CppProvider.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,56 @@ public static int GetRootCount(int handle)
160160
.Invoke(handle);
161161
}
162162

163-
internal static bool? s_doPropertiesExist;
163+
internal static bool triedToGetProperties;
164+
internal static PropertyInfo _normalColorProp;
165+
internal static PropertyInfo _highlightColorProp;
166+
internal static PropertyInfo _pressedColorProp;
164167

165168
public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
166169
{
167-
if (s_doPropertiesExist == null)
168-
{
169-
var prop = ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") as PropertyInfo;
170-
s_doPropertiesExist = prop != null && prop.CanWrite;
171-
}
172-
173170
colors.colorMultiplier = 1;
174171

175172
object boxed = (object)colors;
176173

177-
if (s_doPropertiesExist == true)
174+
if (!triedToGetProperties)
178175
{
179-
if (normal != null)
180-
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor").SetValue(boxed, (Color)normal);
181-
if (pressed != null)
182-
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "pressedColor").SetValue(boxed, (Color)pressed);
183-
if (highlighted != null)
184-
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "highlightedColor").SetValue(boxed, (Color)highlighted);
176+
triedToGetProperties = true;
177+
178+
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") is PropertyInfo norm && norm.CanWrite)
179+
_normalColorProp = norm;
180+
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "highlightedColor") is PropertyInfo high && high.CanWrite)
181+
_highlightColorProp = high;
182+
if (ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "pressedColor") is PropertyInfo pres && pres.CanWrite)
183+
_pressedColorProp = pres;
185184
}
186-
else if (s_doPropertiesExist == false)
185+
186+
try
187187
{
188188
if (normal != null)
189-
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_NormalColor").SetValue(boxed, (Color)normal);
190-
if (pressed != null)
191-
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_PressedColor").SetValue(boxed, (Color)pressed);
189+
{
190+
if (_normalColorProp != null)
191+
_normalColorProp.SetValue(boxed, (Color)normal);
192+
else if (ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_NormalColor") is FieldInfo fi)
193+
fi.SetValue(boxed, (Color)normal);
194+
}
195+
192196
if (highlighted != null)
193-
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_HighlightedColor").SetValue(boxed, (Color)highlighted);
197+
{
198+
if (_highlightColorProp != null)
199+
_highlightColorProp.SetValue(boxed, (Color)highlighted);
200+
else if (ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_HighlightedColor") is FieldInfo fi)
201+
fi.SetValue(boxed, (Color)highlighted);
202+
}
203+
204+
if (pressed != null)
205+
{
206+
if (_pressedColorProp != null)
207+
_pressedColorProp.SetValue(boxed, (Color)pressed);
208+
else if (ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_PressedColor") is FieldInfo fi)
209+
fi.SetValue(boxed, (Color)pressed);
210+
}
194211
}
212+
catch { }
195213

196214
colors = (ColorBlock)boxed;
197215

0 commit comments

Comments
 (0)