static UnityPropertyHandlerUtility() { if (ScriptAttributeUtility == null) { CouldNotFindTypeError(ScriptAttributeUtilityName); return; } if (PropertyHandlerCache == null) { CouldNotFindTypeError(PropertyHandlerCacheName); return; } if (PropertyHandler == null) { CouldNotFindTypeError(PropertyHandlerName); return; } var propertyHandlerCacheProperty = ScriptAttributeUtility.GetProperty(ScriptAttributeUtility_PropertyHandlerCacheName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); var setHandlerMethod = PropertyHandlerCache.GetMethod(PropertyHandlerCache_SetHandlerName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var onGUIMethod = PropertyHandler.GetMethod(PropertyHandler_OnGUIName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var drawerField = PropertyHandler.GetField(PropertyHandler_PropertyDrawerName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (propertyHandlerCacheProperty == null) { CouldNotFindMemberError(ScriptAttributeUtility, ScriptAttributeUtility_PropertyHandlerCacheName); return; } if (setHandlerMethod == null) { CouldNotFindMemberError(PropertyHandlerCache, PropertyHandlerCache_SetHandlerName); return; } if (onGUIMethod == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_OnGUIName); return; } if (drawerField == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_PropertyDrawerName); return; } ScriptAttributeUtility_GetPropertyHandlerCache = () => propertyHandlerCacheProperty.GetValue(null, null); PropertyHandlerCache_SetHandler = (instance, property, handler) => setHandlerMethod.Invoke(instance, new object[] { property, handler }); PropertyHandler_Create = () => Activator.CreateInstance(PropertyHandler); PropertyHandler_OnGUI = (instance, rect, property, label, includeChildren) => onGUIMethod.Invoke(instance, new object[] { rect, property, label, includeChildren }); PropertyHandler_SetPropertyDrawer = (instance, drawer) => drawerField.SetValue(instance, drawer); IsAvailable = true; }
static UnityPropertyHandlerUtility() { try { if (ScriptAttributeUtility == null) { CouldNotFindTypeError(ScriptAttributeUtilityName); return; } if (PropertyHandlerCache == null) { CouldNotFindTypeError(PropertyHandlerCacheName); return; } if (PropertyHandler == null) { CouldNotFindTypeError(PropertyHandlerName); return; } var propertyHandlerCacheProperty = ScriptAttributeUtility.GetProperty(ScriptAttributeUtility_PropertyHandlerCacheName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); var getHandler = ScriptAttributeUtility.GetMethod(ScriptAttributeUtility_GetHandlerName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(SerializedProperty) }, null); var setHandlerMethod = PropertyHandlerCache.GetMethod(PropertyHandlerCache_SetHandlerName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var onGUIMethod = PropertyHandler.GetMethod(PropertyHandler_OnGUIName, BindingFlags.Public | BindingFlags.Instance, null, new Type[4] { typeof(Rect), typeof(SerializedProperty), typeof(GUIContent), typeof(bool) }, null); var getHeightMethod = PropertyHandler.GetMethod(PropertyHandler_GetHeightName, BindingFlags.Public | BindingFlags.Instance, null, new Type[3] { typeof(SerializedProperty), typeof(GUIContent), typeof(bool) }, null); var drawerField = PropertyHandler.GetField(PropertyHandler_PropertyDrawerName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var addMenuItems = PropertyHandler.GetMethod(PropertyHandler_AddMenuItemsName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(SerializedProperty), typeof(GenericMenu) }, null); if (propertyHandlerCacheProperty == null) { CouldNotFindMemberError(ScriptAttributeUtility, ScriptAttributeUtility_PropertyHandlerCacheName); return; } if (getHandler == null) { CouldNotFindMemberError(ScriptAttributeUtility, ScriptAttributeUtility_GetHandlerName); return; } if (setHandlerMethod == null) { CouldNotFindMemberError(PropertyHandlerCache, PropertyHandlerCache_SetHandlerName); return; } if (onGUIMethod == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_OnGUIName); return; } if (getHeightMethod == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_GetHeightName); return; } if (drawerField == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_PropertyDrawerName); return; } if (addMenuItems == null) { CouldNotFindMemberError(PropertyHandler, PropertyHandler_AddMenuItemsName); return; } ScriptAttributeUtility_GetPropertyHandlerCache = () => propertyHandlerCacheProperty.GetValue(null, null); ScriptAttributeUtility_GetHandler_Func = (property) => getHandler.Invoke(null, new object[] { property }); PropertyHandlerCache_SetHandler = (instance, property, handler) => setHandlerMethod.Invoke(instance, new object[] { property, handler }); PropertyHandler_Create = () => Activator.CreateInstance(PropertyHandler); PropertyHandler_OnGUI = (instance, rect, property, label, includeChildren) => onGUIMethod.Invoke(instance, new object[] { rect, property, label, includeChildren }); PropertyHandler_GetHeight = (instance, property, label, includeChildren) => (float)getHeightMethod.Invoke(instance, new object[] { property, label, includeChildren }); PropertyHandler_SetPropertyDrawer = (instance, drawer) => drawerField.SetValue(instance, drawer); PropertyHandler_AddMenuItems_Func = (handler, property, menu) => addMenuItems.Invoke(handler, new object[] { property, menu }); IsAvailable = true; } catch (Exception ex) { Debug.LogException(new Exception("UnityPropertyHandlerUtility initialization failed with an exception; cannot correctly set internal Unity state for drawing of custom Unity property drawers - drawers which call EditorGUI.PropertyField or EditorGUILayout.PropertyField will be drawn partially twice.", ex)); } }