Example #1
0
        public static void RenderEventSettings(SerializedProperty eventItem, int index, InteractableTypesContainer options, InspectorUIUtility.MultiListButtonEvent changeEvent, InspectorUIUtility.ListButtonEvent removeEvent)
        {
            EditorGUILayout.BeginVertical("Box");
            SerializedProperty uEvent                = eventItem.FindPropertyRelative("Event");
            SerializedProperty eventName             = eventItem.FindPropertyRelative("Name");
            SerializedProperty className             = eventItem.FindPropertyRelative("ClassName");
            SerializedProperty assemblyQualifiedName = eventItem.FindPropertyRelative("AssemblyQualifiedName");
            SerializedProperty hideEvents            = eventItem.FindPropertyRelative("HideUnityEvents");

            // show event dropdown
            int id = InspectorUIUtility.ReverseLookup(className.stringValue, options.ClassNames);

            Rect       position    = EditorGUILayout.GetControlRect();
            GUIContent selectLable = new GUIContent("Select Event Type", "Select the event type from the list");

            EditorGUI.BeginProperty(position, selectLable, className);
            {
                int newId = EditorGUI.Popup(position, selectLable.text, id, options.ClassNames);

                if (id != newId || String.IsNullOrEmpty(className.stringValue))
                {
                    className.stringValue             = options.ClassNames[newId];
                    assemblyQualifiedName.stringValue = options.AssemblyQualifiedNames[newId];

                    changeEvent(new int[] { index, newId }, eventItem);
                }
            }
            EditorGUI.EndProperty();

            if (!hideEvents.boolValue)
            {
                EditorGUILayout.PropertyField(uEvent, new GUIContent(eventName.stringValue));
            }

            // show event properties
            EditorGUI.indentLevel = indentOnSectionStart + 1;
            SerializedProperty eventSettings = eventItem.FindPropertyRelative("Settings");

            for (int j = 0; j < eventSettings.arraySize; j++)
            {
                SerializedProperty propertyField = eventSettings.GetArrayElementAtIndex(j);
                bool isEvent = InspectorFieldsUtility.IsPropertyType(propertyField, InspectorField.FieldTypes.Event);

                if (!hideEvents.boolValue || !isEvent)
                {
                    InspectorFieldsUtility.DisplayPropertyField(eventSettings.GetArrayElementAtIndex(j));
                }
            }
            EditorGUI.indentLevel = indentOnSectionStart;

            EditorGUILayout.Space();

            if (removeEvent != null)
            {
                InspectorUIUtility.FlexButton(new GUIContent("Remove Event"), index, removeEvent);
            }

            EditorGUILayout.EndVertical();
        }
        /// <summary>
        /// Render event properties for the given event item. If item has been removed, returns true. False otherwise
        /// </summary>
        /// <param name="eventItem">serialized property of the event item to render properties from</param>
        /// <param name="index">index of event item in higher order list</param>
        /// <param name="options">Event type options</param>
        /// <param name="changeEvent">Function to call if event properties have changed</param>
        /// <param name="removeEvent">Function to call if event requested to be removed</param>
        /// <returns>If item has been removed, returns true. False otherwise</returns>
        public static bool RenderEventSettings(SerializedProperty eventItem, int index, InteractableTypesContainer options, InspectorUIUtility.MultiListButtonEvent changeEvent, InspectorUIUtility.ListButtonEvent removeEvent)
        {
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                SerializedProperty uEvent                = eventItem.FindPropertyRelative("Event");
                SerializedProperty eventName             = eventItem.FindPropertyRelative("Name");
                SerializedProperty className             = eventItem.FindPropertyRelative("ClassName");
                SerializedProperty assemblyQualifiedName = eventItem.FindPropertyRelative("AssemblyQualifiedName");
                SerializedProperty hideEvents            = eventItem.FindPropertyRelative("HideUnityEvents");

                // show event dropdown
                int id = InspectorUIUtility.ReverseLookup(className.stringValue, options.ClassNames);

                using (new EditorGUILayout.HorizontalScope())
                {
                    Rect position = EditorGUILayout.GetControlRect();
                    EditorGUI.BeginProperty(position, SelectEventLabel, className);
                    {
                        int newId = EditorGUI.Popup(position, id, options.ClassNames);

                        if (id != newId || String.IsNullOrEmpty(className.stringValue))
                        {
                            className.stringValue             = options.ClassNames[newId];
                            assemblyQualifiedName.stringValue = options.AssemblyQualifiedNames[newId];

                            changeEvent(new int[] { index, newId }, eventItem);
                        }
                    }
                    EditorGUI.EndProperty();

                    if (removeEvent != null)
                    {
                        if (InspectorUIUtility.FlexButton(new GUIContent("Remove Event"), index, removeEvent))
                        {
                            return(true);
                        }
                    }
                }
                EditorGUILayout.Space();

                if (!hideEvents.boolValue)
                {
                    EditorGUILayout.PropertyField(uEvent, new GUIContent(eventName.stringValue));
                }

                // show event properties
                SerializedProperty eventSettings = eventItem.FindPropertyRelative("Settings");
                for (int j = 0; j < eventSettings.arraySize; j++)
                {
                    SerializedProperty propertyField = eventSettings.GetArrayElementAtIndex(j);
                    bool isEvent = InspectorFieldsUtility.IsPropertyType(propertyField, InspectorField.FieldTypes.Event);

                    if (!hideEvents.boolValue || !isEvent)
                    {
                        InspectorFieldsUtility.DisplayPropertyField(eventSettings.GetArrayElementAtIndex(j));
                    }
                }
            }

            return(false);
        }