Ejemplo n.º 1
0
 /// <summary>
 /// set up only one event
 /// </summary>
 protected virtual void SetupEvents()
 {
     if (Events.Count > 0)
     {
         InteractableTypesContainer interactableTypes = InteractableEvent.GetEventTypes();
         Events[0].Receiver      = InteractableEvent.GetReceiver(Events[0], interactableTypes);
         Events[0].Receiver.Host = this;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the event receiver instances from the Events list
        /// </summary>
        protected virtual void SetupEvents()
        {
            InteractableTypesContainer interactableTypes = InteractableEvent.GetEventTypes();

            for (int i = 0; i < Events.Count; i++)
            {
                Events[i].Receiver      = InteractableEvent.GetReceiver(Events[i], interactableTypes);
                Events[i].Receiver.Host = this;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create the event and setup the values from the inspector
        /// </summary>
        public static ReceiverBase GetReceiver(InteractableEvent iEvent, InteractableTypesContainer interactableTypes)
        {
#if UNITY_EDITOR
            int  index     = InspectorField.ReverseLookup(iEvent.ClassName, interactableTypes.ClassNames);
            Type eventType = interactableTypes.Types[index];
#else
            Type eventType = Type.GetType(iEvent.AssemblyQualifiedName);
#endif
            // apply the settings?
            ReceiverBase newEvent = (ReceiverBase)Activator.CreateInstance(eventType, iEvent.Event);
            InspectorGenericFields <ReceiverBase> .LoadSettings(newEvent, iEvent.Settings);

            return(newEvent);
        }
 protected void SetupEventOptions()
 {
     eventOptions = InteractableEvent.GetEventTypes();
 }
        /*
         * THEMES
         */

        protected void SetupThemeOptions()
        {
            themeOptions = InteractableProfileItem.GetThemeTypes();
        }
Ejemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();
            serializedObject.Update();

            InspectorUIUtility.DrawTitle("States");
            InspectorUIUtility.DrawNotice("Manage state configurations to drive Interactables or Transitions");

            // get the list of options and InteractableStates
            stateOptions = instance.StateOptions;

            SerializedProperty stateLogicName        = serializedObject.FindProperty("StateLogicName");
            SerializedProperty assemblyQualifiedName = serializedObject.FindProperty("AssemblyQualifiedName");
            int option = States.ReverseLookup(stateLogicName.stringValue, stateOptions.ClassNames);

            int newLogic = EditorGUILayout.Popup("State Model", option, stateOptions.ClassNames);

            if (option != newLogic)
            {
                stateLogicName.stringValue        = stateOptions.ClassNames[newLogic];
                assemblyQualifiedName.stringValue = stateOptions.AssemblyQualifiedNames[newLogic];
            }

            int bitCount = 0;

            for (int i = 0; i < stateList.arraySize; i++)
            {
                if (i == 0)
                {
                    bitCount += 1;
                }
                else
                {
                    bitCount += bitCount;
                }

                EditorGUILayout.BeginVertical("Box");
                SerializedProperty stateItem = stateList.GetArrayElementAtIndex(i);

                SerializedProperty name  = stateItem.FindPropertyRelative("Name");
                SerializedProperty index = stateItem.FindPropertyRelative("ActiveIndex");
                SerializedProperty bit   = stateItem.FindPropertyRelative("Bit");

                index.intValue = i;

                EditorGUILayout.BeginHorizontal();
                string[] stateEnums = GetStateOptions();
                int      enumIndex  = States.ReverseLookup(name.stringValue, stateEnums);

                int newEnumIndex = EditorGUILayout.Popup(name.stringValue + " (" + bitCount + ")", enumIndex, stateEnums);
                if (enumIndex != newEnumIndex)
                {
                    name.stringValue = stateEnums[newEnumIndex];
                }

                InspectorUIUtility.SmallButton(new GUIContent(InspectorUIUtility.Minus, "Remove State"), i, RemoveState);

                EditorGUILayout.EndHorizontal();

                // assign the bitcount based on location in the list
                bit.intValue = bitCount;

                EditorGUILayout.EndVertical();
            }

            InspectorUIUtility.FlexButton(new GUIContent("+", "Add Theme Property"), 0, AddState);

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 7
0
 public void SetupStateOptions()
 {
     StateOptions = InteractableTypeFinder.Find(candidateStateTypes, TypeRestriction.AllowBase);
 }
Ejemplo n.º 8
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);
            int newId = EditorGUILayout.Popup("Select Event Type", 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);
            }

            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);
        }