private static void ConnectCallbacks(ReorderableListBase list, ReorderableListExposedAttribute attribute) { var listTarget = list.SerializedObject; var fieldInfo = list.List.GetFieldInfo(); var returnType = fieldInfo.FieldType.GetEnumeratedType(); var methodName = attribute.OverrideNewElementMethodName; var methodInfo = RetriveValidMethod(listTarget, methodName, returnType); if (methodInfo == null) { return; } list.overrideNewElementCallback = (index) => { return(methodInfo.Invoke(listTarget.targetObject, null)); }; //TODO: add more useful callbacks to expose MethodInfo RetriveValidMethod(SerializedObject target, string methodName, Type expectedReturnType = null) { if (string.IsNullOrEmpty(methodName)) { return(null); } var methodInfo = ReflectionUtility.GetObjectMethod(methodName, target); if (methodInfo == null) { ToolboxEditorLog.AttributeUsageWarning(attribute, string.Format("{0} method not found.", methodName)); return(null); } var parameters = methodInfo.GetParameters(); if (parameters.Length > 0) { ToolboxEditorLog.AttributeUsageWarning(attribute, string.Format("{0} method not found.", methodName)); return(null); } if (expectedReturnType != null && expectedReturnType != methodInfo.ReturnType) { ToolboxEditorLog.AttributeUsageWarning(attribute, string.Format("{0} method returns invalid type. Expected - {1}.", methodName, expectedReturnType)); return(null); } return(methodInfo); } }
private static void ConnectCallbacks(ReorderableListBase list, ReorderableListExposedAttribute attribute) { var listTarget = list.SerializedObject; var fieldInfo = list.List.GetFieldInfo(); var returnType = fieldInfo.FieldType.GetEnumeratedType(); var methodName = attribute.OverrideNewElementMethodName; var methodInfo = FindMethod(listTarget, methodName, returnType); if (methodInfo == null) { return; } list.overrideNewElementCallback = (index) => { return(methodInfo.Invoke(listTarget.targetObject, null)); }; }
private void OnEnable() { currentTarget = target as ToolboxEditorSettings; //internal properties cached by 'EditorPrefs' hierarchyAnimBool = new AnimBool(EditorPrefs.GetBool(string.Format("{0}.HierarchyEnabled", nameof(ToolboxEditorSettings)), false)); projectAnimBool = new AnimBool(EditorPrefs.GetBool(string.Format("{0}.ProjectEnabled", nameof(ToolboxEditorSettings)), false)); inspectorAnimBool = new AnimBool(EditorPrefs.GetBool(string.Format("{0}.InspectorEnabled", nameof(ToolboxEditorSettings)), false)); enabledToShowDrawerType = EditorPrefs.GetInt(string.Format("{0}.PickedDrawerType", nameof(ToolboxEditorSettings)), 0); var repaintAction = new UnityAction(() => { //NOTE: we have to repaint our editor and already focused (probably ProjectSettings) window Repaint(); EditorWindow.focusedWindow.Repaint(); }); hierarchyAnimBool.valueChanged.AddListener(repaintAction); projectAnimBool.valueChanged.AddListener(repaintAction); inspectorAnimBool.valueChanged.AddListener(repaintAction); //hierarchy-related properties useToolboxHierarchyProperty = serializedObject.FindProperty("useToolboxHierarchy"); drawHorizontalLinesProperty = serializedObject.FindProperty("drawHorizontalLines"); showSelectionsCountProperty = serializedObject.FindProperty("showSelectionsCount"); #if UNITY_2019_3_OR_NEWER rowDataItemsList = CreateClearList(serializedObject.FindProperty("rowDataTypes"), hasHeader: false, elementLabel: "Position"); #else rowDataItemsList = CreateLinedList(serializedObject.FindProperty("rowDataTypes"), hasHeader: false, elementLabel: "Position"); #endif //project-related properties useToolboxFoldersProperty = serializedObject.FindProperty("useToolboxFolders"); largeIconScaleProperty = serializedObject.FindProperty("largeIconScale"); smallIconScaleProperty = serializedObject.FindProperty("smallIconScale"); largeIconPaddingProperty = serializedObject.FindProperty("largeIconPadding"); smallIconPaddingProperty = serializedObject.FindProperty("smallIconPadding"); #if UNITY_2019_3_OR_NEWER customFoldersList = CreateClearList(serializedObject.FindProperty("customFolders"), hasHeader: false); #else customFoldersList = CreateLinedList(serializedObject.FindProperty("customFolders"), hasHeader: false); #endif //inspector-related properties useToolboxDrawersProperty = serializedObject.FindProperty("useToolboxDrawers"); drawerHandlersLists = new ReorderableListBase[5]; #if UNITY_2019_3_OR_NEWER drawerHandlersLists[0] = CreateClearList(serializedObject.FindProperty("decoratorDrawerHandlers"), hasHeader: false); drawerHandlersLists[1] = CreateClearList(serializedObject.FindProperty("conditionDrawerHandlers"), hasHeader: false); drawerHandlersLists[2] = CreateClearList(serializedObject.FindProperty("selfPropertyDrawerHandlers"), hasHeader: false); drawerHandlersLists[3] = CreateClearList(serializedObject.FindProperty("listPropertyDrawerHandlers"), hasHeader: false); drawerHandlersLists[4] = CreateClearList(serializedObject.FindProperty("targetTypeDrawerHandlers"), hasHeader: false); #else drawerHandlersLists[0] = CreateLinedList(serializedObject.FindProperty("decoratorDrawerHandlers"), hasHeader: false); drawerHandlersLists[1] = CreateLinedList(serializedObject.FindProperty("conditionDrawerHandlers"), hasHeader: false); drawerHandlersLists[2] = CreateLinedList(serializedObject.FindProperty("selfPropertyDrawerHandlers"), hasHeader: false); drawerHandlersLists[3] = CreateLinedList(serializedObject.FindProperty("listPropertyDrawerHandlers"), hasHeader: false); drawerHandlersLists[4] = CreateLinedList(serializedObject.FindProperty("targetTypeDrawerHandlers"), hasHeader: false); #endif drawerHandlersLongNames = new[] { "Decorator", "Condition", "Property (Self)", "Property (List)", "Target Type" }; drawerHandlersShortNames = new[] { "Decorator", "Condition", "Prop. Self", "Prop. List", "Type" }; drawerHandlersInfoLabels = new[] { "", "", "", "", "" }; }