// Origin: https://forum.unity.com/threads/get-a-general-object-value-from-serializedproperty.327098/ public static FieldInfo GetFieldInfoAndStaticType(this SerializedProperty self, out Type type) { if (m_GetFieldInfoAndStaticTypeFromProperty == null) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var t in assembly.GetTypes()) { if (t.Name == "ScriptAttributeUtility") { MethodInfo mi = t.GetMethod("GetFieldInfoAndStaticTypeFromProperty", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); m_GetFieldInfoAndStaticTypeFromProperty = (GetFieldInfoAndStaticTypeFromProperty)Delegate.CreateDelegate(typeof(GetFieldInfoAndStaticTypeFromProperty), mi); break; } } if (m_GetFieldInfoAndStaticTypeFromProperty != null) { break; } } if (m_GetFieldInfoAndStaticTypeFromProperty == null) { UnityEngine.Debug.LogError("GetFieldInfoAndStaticType::Reflection failed!"); type = null; return(null); } } return(m_GetFieldInfoAndStaticTypeFromProperty(self, out type)); }
static ManagedReferenceContextMenu() { _getFieldInfoAndStaticTypeFromProperty = CreateDelegate <GetFieldInfoAndStaticTypeFromProperty>("ScriptAttributeUtility", nameof(GetFieldInfoAndStaticTypeFromProperty)); _getFieldInfoFromProperty = CreateDelegate <GetFieldInfoFromProperty>("ScriptAttributeUtility", nameof(GetFieldInfoFromProperty)); }