Skip to content

Commit 710b793

Browse files
committed
Unity 2022 internal reference workarounds through reflection.
1 parent 231ae9b commit 710b793

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Editor/StandardShaderGUI Plus.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ void DoEmissionArea(Material material)
309309

310310
if (material.globalIlluminationFlags.HasFlag(MaterialGlobalIlluminationFlags.EmissiveIsBlack))
311311
{
312-
material.GetPropertyState(MaterialSerializedProperty.LightmapFlags, out _, out _, out bool lockedByAncestor);
312+
System.Type MSP = System.Reflection.Assembly.Load("UnityEngine").GetType("UnityEngine.MaterialSerializedProperty");
313+
System.Type refbool = typeof(bool).MakeByRefType();
314+
if (MSP == null) { Debug.LogError($"{LOG_INFO} MaterialSerializedProperty enum wasn't found in the UnityEngine assembly via reflection! Please report it so I can take a look at it."); }
315+
System.Reflection.MethodInfo GPS = material.GetType().GetMethod("GetPropertyState", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, System.Reflection.CallingConventions.Any, new[] { MSP, refbool, refbool, refbool }, null);
316+
if (GPS == null) { Debug.LogError($"{LOG_INFO} GetPropertyState method wasn't found in the material via reflection! Please report it so I can take a look at it."); }
317+
object[] args = { MSP?.GetField("LightmapFlags").GetValue(null), false, false, false };
318+
GPS?.Invoke(material, args);
319+
bool lockedByAncestor = (bool)args[3]; // instead of out bool lockedByAncestor
313320
if (lockedByAncestor)
314321
EditorGUILayout.HelpBox("Emissive lighting is locked to black by a parent Material. Changing the emissive color will have no effect.", MessageType.Warning);
315322
}

0 commit comments

Comments
 (0)