Esempio n. 1
0
        /// <summary>
        /// Draws the specified view type.
        /// </summary>
        private void DrawSelectedViewType(int index)
        {
            var viewType = m_CameraController.ViewTypes[index];

            InspectorUtility.DrawObject(viewType, true, true, target, true, SerializeViewTypes);

            if (Shared.Editor.Inspectors.Utility.InspectorUtility.Foldout(viewType, new GUIContent("States"), false))
            {
                // The View Type class derives from system.object at the base level and reorderable lists can only operate on Unity objects. To get around this restriction
                // create a dummy array within a Unity object that corresponds to the number of elements within the view type's state list. When the reorderable list is drawn
                // the view type object will be used so it's like the dummy object never existed.
                var selectedViewType = viewType as ViewType;
                var gameObject       = new GameObject();
                var stateIndexHelper = gameObject.AddComponent <StateInspectorHelper>();
                stateIndexHelper.StateIndexData = new int[selectedViewType.States.Length];
                for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i)
                {
                    stateIndexHelper.StateIndexData[i] = i;
                }
                var stateIndexSerializedObject = new SerializedObject(stateIndexHelper);
                m_ReorderableViewTypeStateList = StateInspector.DrawStates(m_ReorderableViewTypeStateList, serializedObject, stateIndexSerializedObject.FindProperty("m_StateIndexData"),
                                                                           GetSelectedViewTypeStateIndexKey(selectedViewType), OnViewTypeStateListDraw, OnViewTypeStateListAdd, OnViewTypeStateListReorder,
                                                                           OnViewTypeStateListRemove);
                DestroyImmediate(gameObject);
            }
        }
Esempio n. 2
0
 public override void OnInspectorGUI()
 {
     InspectorUtility.Setup(this.serializedObject.targetObject);
     InspectorUtility.DrawObject(this.serializedObject.targetObject);
     this.Repaint();
 }
Esempio n. 3
0
        /// <summary>
        /// Draws the Ability fields related to input.
        /// </summary>
        /// <param name="target">The object that is being drawn.</param>
        /// <param name="parent">The Unity Object that the object belongs to.</param>
        protected void DrawInputFieldsFields(object target, Object parent)
        {
            var startTypeValue = (Ability.AbilityStartType)EditorGUILayout.EnumPopup(new GUIContent("Start Type", InspectorUtility.GetFieldTooltip(target, "m_StartType")), InspectorUtility.GetFieldValue <Ability.AbilityStartType>(target, "m_StartType"));

            InspectorUtility.SetFieldValue(target, "m_StartType", startTypeValue);
            if (startTypeValue == Ability.AbilityStartType.Custom)
            {
                PopulateAbilityStarterTypes();
                if (s_AbilityStarterTypeCache != null)
                {
                    EditorGUI.indentLevel++;
                    var selected    = 0;
                    var forceUpdate = true;
                    if (m_Ability.StarterData != null && !string.IsNullOrEmpty(m_Ability.StarterData.ObjectType))
                    {
                        for (int i = 0; i < s_AbilityStarterTypeCache.Count; ++i)
                        {
                            if (s_AbilityStarterTypeCache[i].FullName == m_Ability.StarterData.ObjectType)
                            {
                                selected    = i;
                                forceUpdate = false;
                                break;
                            }
                        }
                    }
                    var newSelected = EditorGUILayout.Popup("Starter", selected, s_AbilityStarterTypeName.ToArray());
                    if (newSelected != selected || forceUpdate)
                    {
                        // Use the Sequence selector as the default (or recoil in the case of a melee weapon).
                        if (forceUpdate)
                        {
                            for (int i = 0; i < s_AbilityStarterTypeCache.Count; ++i)
                            {
                                if (s_AbilityStarterTypeCache[i].FullName == "Opsive.UltimateCharacterController.Character.Abilities.Starters.ComboTimeout")
                                {
                                    newSelected = i;
                                    break;
                                }
                            }
                            GUI.changed = true;
                        }
                        var starter = System.Activator.CreateInstance(s_AbilityStarterTypeCache[newSelected]) as AbilityStarter;
                        m_Ability.StarterData = Shared.Utility.Serialization.Serialize(starter);
                    }

                    if (m_Ability.Starter != null)
                    {
                        EditorGUI.indentLevel++;
                        InspectorUtility.DrawObject(m_Ability.Starter, false, true, parent, false, () =>
                        {
                            m_Ability.StarterData = Shared.Utility.Serialization.Serialize <AbilityStarter>(m_Ability.Starter);
                        });
                        EditorGUI.indentLevel--;
                    }

                    EditorGUI.indentLevel--;
                }
            }
            else if ((target as Ability).Starter != null)
            {
                (target as Ability).StarterData = null;
            }
            var stopTypeValue = (Ability.AbilityStopType)EditorGUILayout.EnumPopup(new GUIContent("Stop Type", InspectorUtility.GetFieldTooltip(target, "m_StopType")), InspectorUtility.GetFieldValue <Ability.AbilityStopType>(target, "m_StopType"));

            InspectorUtility.SetFieldValue(target, "m_StopType", stopTypeValue);

            EditorGUI.indentLevel++;
            // The input name field only needs to be shown if the start/stop type is set to a value which requires the button press.
            if ((startTypeValue != Ability.AbilityStartType.Automatic && startTypeValue != Ability.AbilityStartType.Manual && startTypeValue != Ability.AbilityStartType.Custom) ||
                (stopTypeValue != Ability.AbilityStopType.Automatic && stopTypeValue != Ability.AbilityStopType.Manual))
            {
                EditorGUI.BeginChangeCheck();
                // Draw a custom array inspector for the input names.
                var inputNames = InspectorUtility.GetFieldValue <string[]>(target, "m_InputNames");
                if (inputNames == null || inputNames.Length == 0)
                {
                    inputNames = new string[1];
                }
                for (int i = 0; i < inputNames.Length; ++i)
                {
                    EditorGUILayout.BeginHorizontal();
                    var fieldName = " ";
                    if (i == 0)
                    {
                        fieldName = "Input Name";
                    }
                    inputNames[i] = EditorGUILayout.TextField(new GUIContent(fieldName, InspectorUtility.GetFieldTooltip(target, "m_InputName")), inputNames[i]);

                    if (i == inputNames.Length - 1)
                    {
                        if (i > 0 && GUILayout.Button(InspectorStyles.RemoveIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(18)))
                        {
                            System.Array.Resize(ref inputNames, inputNames.Length - 1);
                        }
                        if (GUILayout.Button(InspectorStyles.AddIcon, InspectorStyles.NoPaddingButtonStyle, GUILayout.Width(18)))
                        {
                            System.Array.Resize(ref inputNames, inputNames.Length + 1);
                            inputNames[inputNames.Length - 1] = inputNames[inputNames.Length - 2];
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    InspectorUtility.SetFieldValue(target, "m_InputNames", inputNames);
                    GUI.changed = true;
                }

                // Only show the duration and wait for release options with a LongPress start/stop type.
                if (startTypeValue == Ability.AbilityStartType.LongPress || stopTypeValue == Ability.AbilityStopType.LongPress)
                {
                    var duration = EditorGUILayout.FloatField(new GUIContent("Long Press Duration", InspectorUtility.GetFieldTooltip(target, "m_LongPressDuration")), InspectorUtility.GetFieldValue <float>(target, "m_LongPressDuration"));
                    InspectorUtility.SetFieldValue(target, "m_LongPressDuration", duration);

                    var waitForRelease = EditorGUILayout.Toggle(new GUIContent("Wait For Long Press Release", InspectorUtility.GetFieldTooltip(target, "m_WaitForLongPressRelease")),
                                                                InspectorUtility.GetFieldValue <bool>(target, "m_WaitForLongPressRelease"));
                    InspectorUtility.SetFieldValue(target, "m_WaitForLongPressRelease", waitForRelease);
                }
            }
            EditorGUI.indentLevel--;
        }
Esempio n. 4
0
        /// <summary>
        /// Draws the AnimatorAudioStateSet.
        /// </summary>
        public static void DrawAnimatorAudioStateSet(UnityEngine.Object target, AnimatorAudioStateSet animatorAudioStateSet, string animatorAudioStateSetFieldName, bool randomDefaultSelector,
                                                     ref ReorderableList reorderableList, ReorderableList.ElementCallbackDelegate drawCallback, ReorderableList.SelectCallbackDelegate selectCallback,
                                                     ReorderableList.AddCallbackDelegate addCallback, ReorderableList.RemoveCallbackDelegate removeCallback, string preferencesKey,
                                                     ref ReorderableList reorderableAudioList, ReorderableList.ElementCallbackDelegate drawAudioElementCallback,
                                                     ReorderableList.AddCallbackDelegate addAudioCallback, ReorderableList.RemoveCallbackDelegate removeAudioCallback,
                                                     ref ReorderableList reorderableStateList, ReorderableList.ElementCallbackDelegate stateDrawElementCallback,
                                                     ReorderableList.AddCallbackDelegate stateAddCallback, ReorderableList.ReorderCallbackDelegate stateReorderCallback,
                                                     ReorderableList.RemoveCallbackDelegate stateRemoveCallback, string statePreferencesKey)
        {
            PopulateAnimatorAudioStateSelectorTypes();
            if (s_SelectorTypeNameCache != null)
            {
                var selected    = 0;
                var forceUpdate = true;
                if (animatorAudioStateSet.AnimatorAudioStateSelectorData != null && !string.IsNullOrEmpty(animatorAudioStateSet.AnimatorAudioStateSelectorData.ObjectType))
                {
                    for (int i = 0; i < s_SelectorTypeCache.Count; ++i)
                    {
                        if (s_SelectorTypeCache[i].FullName == animatorAudioStateSet.AnimatorAudioStateSelectorData.ObjectType)
                        {
                            selected    = i;
                            forceUpdate = false;
                            break;
                        }
                    }
                }
                var newSelected = EditorGUILayout.Popup("Selector", selected, s_SelectorTypeNameCache.ToArray());
                if (newSelected != selected || forceUpdate)
                {
                    // Use the Sequence selector as the default (or recoil in the case of a melee weapon).
                    if (forceUpdate)
                    {
                        for (int i = 0; i < s_SelectorTypeCache.Count; ++i)
                        {
                            if ((randomDefaultSelector && s_SelectorTypeCache[i].FullName == "Opsive.UltimateCharacterController.Items.AnimatorAudioStates.Sequence") ||
                                (!randomDefaultSelector && s_SelectorTypeCache[i].FullName == "Opsive.UltimateCharacterController.Items.AnimatorAudioStates.ConstantRecoil"))
                            {
                                newSelected = i;
                                break;
                            }
                        }
                    }
                    var animatorAudioOutputSelector = Activator.CreateInstance(s_SelectorTypeCache[newSelected]) as AnimatorAudioStateSelector;
                    animatorAudioStateSet.AnimatorAudioStateSelectorData = Serialization.Serialize(animatorAudioOutputSelector);
                    InspectorUtility.SetDirty(target);
                }
            }

            if (animatorAudioStateSet.AnimatorAudioStateSelector != null)
            {
                EditorGUI.indentLevel++;
                InspectorUtility.DrawObject(animatorAudioStateSet.AnimatorAudioStateSelector, false, true, target, false, () => {
                    animatorAudioStateSet.AnimatorAudioStateSelectorData = Serialization.Serialize(animatorAudioStateSet.AnimatorAudioStateSelector);
                    InspectorUtility.SetDirty(target);
                });
                EditorGUI.indentLevel--;
            }

            if (animatorAudioStateSet.States == null || animatorAudioStateSet.States.Length == 0)
            {
                animatorAudioStateSet.States = new AnimatorAudioStateSet.AnimatorAudioState[] { new AnimatorAudioStateSet.AnimatorAudioState() };
            }

            var serializedObject   = new SerializedObject(target);
            var serializedProperty = serializedObject.FindProperty(animatorAudioStateSetFieldName).FindPropertyRelative("m_States");

            if (reorderableList == null)
            {
                reorderableList = new ReorderableList(animatorAudioStateSet.States, typeof(AnimatorAudioStateSet.AnimatorAudioState), false, true, true, animatorAudioStateSet.States.Length > 1);
                reorderableList.drawHeaderCallback  = OnAnimatorAudioStateListHeaderDraw;
                reorderableList.drawElementCallback = drawCallback;
                reorderableList.onSelectCallback    = selectCallback;
                reorderableList.onAddCallback       = addCallback;
                reorderableList.onRemoveCallback    = removeCallback;
                reorderableList.serializedProperty  = serializedProperty;
                if (EditorPrefs.GetInt(preferencesKey, -1) != -1)
                {
                    reorderableList.index = EditorPrefs.GetInt(preferencesKey, -1);
                }
            }

            // ReorderableLists do not like indentation.
            var indentLevel = EditorGUI.indentLevel;

            while (EditorGUI.indentLevel > 0)
            {
                EditorGUI.indentLevel--;
            }

            var listRect = GUILayoutUtility.GetRect(0, reorderableList.GetHeight());

            // Indent the list so it lines up with the rest of the content.
            listRect.x    += InspectorUtility.IndentWidth * indentLevel;
            listRect.xMax -= InspectorUtility.IndentWidth * indentLevel;
            EditorGUI.BeginChangeCheck();
            var prevPref = EditorPrefs.GetInt(preferencesKey, 0);

            reorderableList.DoList(listRect);
            while (EditorGUI.indentLevel < indentLevel)
            {
                EditorGUI.indentLevel++;
            }
            if (EditorGUI.EndChangeCheck() || prevPref != EditorPrefs.GetInt(preferencesKey, 0))
            {
                reorderableList      = null;
                reorderableAudioList = null;
                reorderableStateList = null;
                return;
            }

            if (EditorPrefs.GetInt(preferencesKey, 0) >= animatorAudioStateSet.States.Length)
            {
                EditorPrefs.SetInt(preferencesKey, 0);
            }

            serializedProperty = serializedProperty.GetArrayElementAtIndex(EditorPrefs.GetInt(preferencesKey, 0));
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("m_AllowDuringMovement"));
            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("m_RequireGrounded"));
            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("m_StateName"));
            EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("m_ItemSubstateIndex"));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }

            var animatorAudioState = animatorAudioStateSet.States[EditorPrefs.GetInt(preferencesKey, 0)];

            AudioClipSetInspector.DrawAudioClipSet(animatorAudioState.AudioClipSet, serializedProperty.FindPropertyRelative("m_AudioClipSet"), ref reorderableAudioList, drawAudioElementCallback, addAudioCallback, removeAudioCallback);
            if (InspectorUtility.Foldout(animatorAudioState, new GUIContent("States"), false))
            {
                EditorGUI.indentLevel--;
                // The MovementType class derives from system.object at the base level and reorderable lists can only operate on Unity objects. To get around this restriction
                // create a dummy array within a Unity object that corresponds to the number of elements within the ability's state list. When the reorderable list is drawn
                // the ability object will be used so it's like the dummy object never existed.
                var gameObject       = new GameObject();
                var stateIndexHelper = gameObject.AddComponent <StateInspectorHelper>();
                stateIndexHelper.StateIndexData = new int[animatorAudioState.States.Length];
                for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i)
                {
                    stateIndexHelper.StateIndexData[i] = i;
                }
                var stateIndexSerializedObject = new SerializedObject(stateIndexHelper);
                reorderableStateList = StateInspector.DrawStates(reorderableStateList, new SerializedObject(target), stateIndexSerializedObject.FindProperty("m_StateIndexData"),
                                                                 statePreferencesKey, stateDrawElementCallback, stateAddCallback,
                                                                 stateReorderCallback, stateRemoveCallback);
                GameObject.DestroyImmediate(gameObject);
                EditorGUI.indentLevel++;
            }
            GUILayout.Space(5);
        }