Пример #1
0
        /// <summary>
        /// The list has been reordered. Ensure the reorder is valid.
        /// </summary>
        private void OnEquipAnimatorAudioStateSetStateListReorder(ReorderableList list)
        {
            var animatorAudioState = m_Item.EquipAnimatorAudioStateSet.States[EditorPrefs.GetInt(SelectedEquipAnimatorAudioStateSetIndexKey)];

            // Use the dummy array in order to determine what element the selected index was swapped with.
            var copiedStates = new UltimateCharacterController.StateSystem.State[animatorAudioState.States.Length];

            Array.Copy(animatorAudioState.States, copiedStates, animatorAudioState.States.Length);
            for (int i = 0; i < animatorAudioState.States.Length; ++i)
            {
                var element = list.serializedProperty.GetArrayElementAtIndex(i);
                if (element.intValue != i)
                {
                    animatorAudioState.States[i] = copiedStates[element.intValue];
                    element.intValue             = i;
                }
            }

            var states = StateInspector.OnStateListReorder(animatorAudioState.States);

            if (animatorAudioState.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableEquipAnimatorAudioStateSetStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                animatorAudioState.States = states;
            }
        }
Пример #2
0
        /// <summary>
        /// Draws all of the added states.
        /// </summary>
        private void OnItemSetStateListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorGUI.BeginChangeCheck();
            if (m_ItemSetListIndex >= m_ItemSetManager.CategoryItemSets.Length ||
                EditorPrefs.GetInt(SelectedItemSetIndexKey, -1) == -1 ||
                EditorPrefs.GetInt(SelectedItemSetIndexKey, -1) >= m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].ItemSetList.Count)
            {
                m_ReorderableItemSetStateList[m_ItemSetListIndex].index = -1;
                return;
            }

            var itemSet = m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].ItemSetList[EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)];

            // The index may be out of range if the component was copied.
            if (index >= itemSet.States.Length)
            {
                m_ReorderableItemSetStateList[m_ItemSetListIndex].index = -1;
                return;
            }

            StateInspector.OnStateListDraw(itemSet, itemSet.States, rect, index);
            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                StateInspector.UpdateDefaultStateValues(itemSet.States);
            }
        }
Пример #3
0
        /// <summary>
        /// The list has been reordered. Ensure the reorder is valid.
        /// </summary>
        private void OnItemSetStateListReorder(ReorderableList list)
        {
            m_ItemSetListIndex = m_ReorderableListCategoryMap[list];
            var itemSet = m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].ItemSetList[EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)];

            // Use the dummy array in order to determine what element the selected index was swapped with.
            var copiedStates = new UltimateCharacterController.StateSystem.State[itemSet.States.Length];

            System.Array.Copy(itemSet.States, copiedStates, itemSet.States.Length);
            for (int i = 0; i < itemSet.States.Length; ++i)
            {
                var element = list.serializedProperty.GetArrayElementAtIndex(i);
                if (element.intValue != i)
                {
                    itemSet.States[i] = copiedStates[element.intValue];
                    element.intValue  = i;
                }
            }

            var states = StateInspector.OnStateListReorder(itemSet.States);

            if (itemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableItemSetStateList[m_ItemSetListIndex].serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                itemSet.States = states;
            }
        }
Пример #4
0
        /// <summary>
        /// The list has been reordered. Ensure the reorder is valid.
        /// </summary>
        private void OnAttributeStateListReorder(ReorderableList list)
        {
            var attribute = m_AttributeManager.Attributes[EditorPrefs.GetInt(SelectedAttributeIndexKey)];

            // Use the dummy array in order to determine what element the selected index was swapped with.
            var copiedStates = new Shared.StateSystem.State[attribute.States.Length];

            Array.Copy(attribute.States, copiedStates, attribute.States.Length);
            for (int i = 0; i < attribute.States.Length; ++i)
            {
                var element = list.serializedProperty.GetArrayElementAtIndex(i);
                if (element.intValue != i)
                {
                    attribute.States[i] = copiedStates[element.intValue];
                    element.intValue    = i;
                }
            }

            var states = StateInspector.OnStateListReorder(attribute.States);

            if (attribute.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableAttributeStateList.serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                attribute.States = states;
            }
        }
Пример #5
0
        /// <summary>
        /// The list has been reordered. Ensure the reorder is valid.
        /// </summary>
        private void OnPickupSetStateListReorder(ReorderableList list)
        {
            var pickupSet = m_ItemPickup.ItemPickupSet[EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)];

            // Use the dummy array in order to determine what element the selected index was swapped with.
            var copiedStates = new Shared.StateSystem.State[pickupSet.ItemSet.States.Length];

            System.Array.Copy(pickupSet.ItemSet.States, copiedStates, pickupSet.ItemSet.States.Length);
            for (int i = 0; i < pickupSet.ItemSet.States.Length; ++i)
            {
                var element = list.serializedProperty.GetArrayElementAtIndex(i);
                if (element.intValue != i)
                {
                    pickupSet.ItemSet.States[i] = copiedStates[element.intValue];
                    element.intValue            = i;
                }
            }

            var states = StateInspector.OnStateListReorder(pickupSet.ItemSet.States);

            if (pickupSet.ItemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderablePickupSetStateList.serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                pickupSet.ItemSet.States = states;
            }
        }
Пример #6
0
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnPickupSetStateListRemove(ReorderableList list)
        {
            var pickupSet = m_ItemPickup.ItemPickupSet[EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)];
            var states    = StateInspector.OnStateListRemove(pickupSet.ItemSet.States, GetSelectedPickupSetStateIndexKey(EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)), list);

            if (pickupSet.ItemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderablePickupSetStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                pickupSet.ItemSet.States = states;
            }
        }
Пример #7
0
        /// <summary>
        /// Adds a new element to the state list which uses an existing preset.
        /// </summary>
        private void AddExistingAnimatorAudioStateSetStatePreset()
        {
            var animatorAudioState = m_ShootableWeapon.ReloadAnimatorAudioStateSet.States[EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)];
            var states             = StateInspector.AddExistingPreset(animatorAudioState.GetType(), animatorAudioState.States, m_ReorderableReloadAnimatorAudioStateSetStateList, GetSelectedAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)));

            if (animatorAudioState.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableReloadAnimatorAudioStateSetStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                animatorAudioState.States = states;
            }
        }
Пример #8
0
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnAttributeStateListRemove(ReorderableList list)
        {
            var attribute = m_AttributeManager.Attributes[EditorPrefs.GetInt(SelectedAttributeIndexKey)];
            var states    = StateInspector.OnStateListRemove(attribute.States, GetSelectedAttributeStateIndexKey(attribute), list);

            if (attribute.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableAttributeStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                attribute.States = states;
            }
        }
Пример #9
0
        /// <summary>
        /// Adds a new element to the state list which uses an existing preset.
        /// </summary>
        private void AddExistingViewTypePreset()
        {
            var attribute = m_AttributeManager.Attributes[EditorPrefs.GetInt(SelectedAttributeIndexKey)];
            var states    = StateInspector.AddExistingPreset(attribute.GetType(), attribute.States, m_ReorderableAttributeStateList, GetSelectedAttributeStateIndexKey(attribute));

            if (attribute.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableAttributeStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                attribute.States = states;
            }
        }
        /// <summary>
        /// Creates a new preset and adds it to a new state in the list.
        /// </summary>
        private void CreateAnimatorAudioStateSetStatePreset()
        {
            var animatorAudioState = m_UsableItem.UseAnimatorAudioStateSet.States[EditorPrefs.GetInt(SelectedUseAnimatorAudioStateSetIndexKey)];
            var states             = StateInspector.CreatePreset(animatorAudioState, animatorAudioState.States, m_ReorderableUseAnimatorAudioStateSetStateList, GetSelectedAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedUseAnimatorAudioStateSetIndexKey)));

            if (animatorAudioState.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableUseAnimatorAudioStateSetStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                animatorAudioState.States = states;
            }
        }
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnAnimatorAudioStateSetStateListRemove(ReorderableList list)
        {
            var animatorAudioState = m_ShootableWeapon.ReloadAnimatorAudioStateSet.States[EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)];
            var states             = StateInspector.OnStateListRemove(animatorAudioState.States, GetSelectedAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)), list);

            if (animatorAudioState.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableReloadAnimatorAudioStateSetStateList.serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                animatorAudioState.States = states;
            }
        }
        /// <summary>
        /// Draws the specified item set.
        /// </summary>
        private void DrawSelectedPickupSet(ItemPickupBase.PickupSet pickupSet, int index)
        {
            GUILayout.Label("Pickup Set " + index, Shared.Editor.Inspectors.Utility.InspectorStyles.CenterBoldLabel);

            pickupSet.Item = (GameObject)EditorGUILayout.ObjectField("Item", pickupSet.Item, typeof(GameObject), false);
            if (pickupSet.Item != null)
            {
                // Automatically fill in the ItemDefinition for the specified item.
                var item = pickupSet.Item.GetComponent <Item>();
                if (item != null && item.SlotID < pickupSet.ItemSet.Slots.Length && pickupSet.ItemSet.Slots[item.SlotID] != item.ItemDefinition)
                {
                    pickupSet.ItemSet.Slots[item.SlotID] = item.ItemDefinition;
                    EditorUtility.SetDirty(target);
                }
            }

            GUI.enabled = pickupSet.Item == null && !Application.isPlaying;
            DrawAvailableCategories(pickupSet, new Rect());
            GUI.enabled = !Application.isPlaying;

            pickupSet.ItemSet.State = EditorGUILayout.TextField(new GUIContent("State", "Optionally specify a state that the character should switch to when the Item Set is active."), pickupSet.ItemSet.State);
            // Draws all of the slots ItemIdentifiers.
            for (int i = 0; i < m_SlotCount; ++i)
            {
                pickupSet.ItemSet.Slots[i] = (ItemDefinitionBase)EditorGUILayout.ObjectField("Slot " + i, pickupSet.ItemSet.Slots[i], typeof(ItemDefinitionBase), false);
            }
            pickupSet.Default               = EditorGUILayout.Toggle(new GUIContent("Default", "True if the ItemSet is the default Item Set."), pickupSet.Default);
            pickupSet.ItemSet.Enabled       = EditorGUILayout.Toggle(new GUIContent("Enabled", "True if the ItemSet can be equipped."), pickupSet.ItemSet.Enabled);
            pickupSet.ItemSet.CanSwitchTo   = EditorGUILayout.Toggle(new GUIContent("Can Switch To", "True if the ItemSet can be switched to by the EquipNext/EquipPrevious abilities."), pickupSet.ItemSet.CanSwitchTo);
            pickupSet.ItemSet.DisabledIndex = EditorGUILayout.IntField(new GUIContent("Disabled Index", "The ItemSet that should be activated if the current ItemSet is disabled."), pickupSet.ItemSet.DisabledIndex);

            if (Shared.Editor.Inspectors.Utility.InspectorUtility.Foldout(pickupSet, new GUIContent("States"), false))
            {
                // 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();
                try {
                    var stateIndexHelper = gameObject.AddComponent <StateInspectorHelper>();
                    stateIndexHelper.StateIndexData = new int[pickupSet.ItemSet.States.Length];
                    for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i)
                    {
                        stateIndexHelper.StateIndexData[i] = i;
                    }
                    var stateIndexSerializedObject = new SerializedObject(stateIndexHelper);
                    m_ReorderablePickupSetStateList = StateInspector.DrawStates(m_ReorderablePickupSetStateList, serializedObject,
                                                                                stateIndexSerializedObject.FindProperty("m_StateIndexData"),
                                                                                GetSelectedPickupSetStateIndexKey(index), OnPickupSetStateListDraw, OnPickupSetStateListAdd,
                                                                                OnPickupSetStateListReorder, OnPickupSetStateListRemove);
                } catch (System.Exception /*e*/) { }
                DestroyImmediate(gameObject);
            }
        }
        /// <summary>
        /// Creates a new preset and adds it to a new state in the list.
        /// </summary>
        private void CreateViewTypePreset()
        {
            var viewType = m_CameraController.ViewTypes[EditorPrefs.GetInt(SelectedViewTypeIndexKey)];
            var states   = StateInspector.CreatePreset(viewType, viewType.States, m_ReorderableViewTypeStateList, GetSelectedViewTypeStateIndexKey(viewType));

            if (viewType.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableViewTypeStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                viewType.States = states;
                SerializeViewTypes();
            }
        }
Пример #14
0
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnViewTypeStateListRemove(ReorderableList list)
        {
            var viewType = m_CameraController.ViewTypes[EditorPrefs.GetInt(SelectedViewTypeIndexKey)];
            var states   = StateInspector.OnStateListRemove(viewType.States, GetSelectedViewTypeStateIndexKey(viewType), list);

            if (viewType.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableViewTypeStateList.serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                viewType.States = states;
                SerializeViewTypes();
            }
        }
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnItemSetStateListRemove(ReorderableList list)
        {
            m_ItemSetListIndex = m_ReorderableListCategoryMap[list];
            var itemSet = m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].ItemSetList[EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)];
            var states  = StateInspector.OnStateListRemove(itemSet.States, GetSelectedItemSetStateIndexKey(EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)), list);

            if (itemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableItemSetStateList[m_ItemSetListIndex].serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                itemSet.States = states;
            }
        }
Пример #16
0
        /// <summary>
        /// Adds a new element to the state list which uses an existing preset.
        /// </summary>
        private void AddExistingPickupSetPreset()
        {
            var pickupSet = m_ItemPickup.ItemPickupSet[EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)];
            var states    = StateInspector.AddExistingPreset(pickupSet.ItemSet.GetType(), pickupSet.ItemSet.States, m_ReorderablePickupSetStateList,
                                                             GetSelectedPickupSetStateIndexKey(EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)));

            if (pickupSet.ItemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderablePickupSetStateList.serializedProperty);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                pickupSet.ItemSet.States = states;
            }
        }
        /// <summary>
        /// Adds a new element to the state list which uses an existing preset.
        /// </summary>
        private void AddExistingItemSetPreset()
        {
            m_ItemSetListIndex = m_ItemSetListIndexAdd;
            var itemSet = m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].ItemSetList[EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)];
            var states  = StateInspector.AddExistingPreset(itemSet.GetType(), itemSet.States, m_ReorderableItemSetStateList[m_ItemSetListIndex],
                                                           GetSelectedItemSetStateIndexKey(EditorPrefs.GetInt(SelectedItemSetIndexKey, -1)));

            if (itemSet.States.Length != states.Length)
            {
                InspectorUtility.SynchronizePropertyCount(states, m_ReorderableItemSetStateList[m_ItemSetListIndex].serializedProperty);
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                itemSet.States = states;
            }
        }
Пример #18
0
        /// <summary>
        /// Draws all of the added states.
        /// </summary>
        private void OnPickupSetStateListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorGUI.BeginChangeCheck();
            var pickupSet = m_ItemPickup.ItemPickupSet[EditorPrefs.GetInt(SelectedPickupSetIndexKey, -1)];

            // The index may be out of range if the component was copied.
            if (index >= pickupSet.ItemSet.States.Length)
            {
                m_ReorderablePickupSetStateList.index = -1;
                return;
            }

            StateInspector.OnStateListDraw(pickupSet.ItemSet, pickupSet.ItemSet.States, rect, index);
            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                StateInspector.UpdateDefaultStateValues(pickupSet.ItemSet.States);
            }
        }
        /// <summary>
        /// Draws all of the added states.
        /// </summary>
        private void OnAnimatorAudioStateSetStateListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorGUI.BeginChangeCheck();
            var animatorAudioState = m_ShootableWeapon.ReloadAnimatorAudioStateSet.States[EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)];

            // The index may be out of range if the component was copied.
            if (index >= animatorAudioState.States.Length)
            {
                m_ReorderableReloadAnimatorAudioStateSetStateList.index = -1;
                EditorPrefs.SetInt(GetSelectedAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)), m_ReorderableReloadAnimatorAudioStateSetStateList.index);
                return;
            }

            StateInspector.OnStateListDraw(animatorAudioState, animatorAudioState.States, rect, index);
            if (EditorGUI.EndChangeCheck())
            {
                Shared.Editor.Utility.EditorUtility.RecordUndoDirtyObject(target, "Change Value");
                StateInspector.UpdateDefaultStateValues(animatorAudioState.States);
            }
        }
Пример #20
0
        /// <summary>
        /// Draws all of the added states.
        /// </summary>
        private void OnAttributeStateListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorGUI.BeginChangeCheck();
            var attribute = m_AttributeManager.Attributes[EditorPrefs.GetInt(SelectedAttributeIndexKey)];

            // The index may be out of range if the component was copied.
            if (index >= m_AttributeManager.Attributes[EditorPrefs.GetInt(SelectedAttributeIndexKey)].States.Length)
            {
                m_ReorderableAttributeStateList.index = -1;
                EditorPrefs.SetInt(GetSelectedAttributeStateIndexKey(attribute), m_ReorderableAttributeStateList.index);
                return;
            }

            StateInspector.OnStateListDraw(attribute, attribute.States, rect, index);
            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");

                StateInspector.UpdateDefaultStateValues(attribute.States);
            }
        }
Пример #21
0
 /// <summary>
 /// Adds a new state element to the list.
 /// </summary>
 private void OnViewTypeStateListAdd(ReorderableList list)
 {
     StateInspector.OnStateListAdd(AddExistingViewTypePreset, CreateViewTypePreset);
 }
Пример #22
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);
        }
Пример #23
0
        /// <summary>
        /// Draws the specified attribute.
        /// </summary>
        private void DrawSelectedAttribute(int index)
        {
            EditorGUI.BeginChangeCheck();

            var attributesProperty = PropertyFromName("m_Attributes");
            var attributeProperty  = attributesProperty.GetArrayElementAtIndex(index);

            if (attributeProperty == null)
            {
                return;
            }

            // The name must be unique.
            var name        = attributeProperty.FindPropertyRelative("m_Name");
            var desiredName = EditorGUILayout.TextField(new GUIContent("Name", "The name of the attribute."), name.stringValue);

            if (name.stringValue != desiredName && IsUniqueName(m_AttributeManager.Attributes, desiredName))
            {
                name.stringValue = desiredName;
            }
            var minValue = attributeProperty.FindPropertyRelative("m_MinValue");
            var maxValue = attributeProperty.FindPropertyRelative("m_MaxValue");

            EditorGUILayout.PropertyField(minValue);
            if (minValue.floatValue > maxValue.floatValue)
            {
                maxValue.floatValue = minValue.floatValue;
            }
            EditorGUILayout.PropertyField(maxValue);
            if (maxValue.floatValue < minValue.floatValue)
            {
                minValue.floatValue = maxValue.floatValue;
            }

            var value = attributeProperty.FindPropertyRelative("m_Value");

            EditorGUILayout.PropertyField(value);
            if (maxValue.floatValue < value.floatValue)
            {
                value.floatValue = maxValue.floatValue;
            }
            else if (minValue.floatValue > value.floatValue)
            {
                value.floatValue = minValue.floatValue;
            }
            if (value.floatValue > maxValue.floatValue)
            {
                maxValue.floatValue = value.floatValue;
            }
            else if (value.floatValue < minValue.floatValue)
            {
                minValue.floatValue = value.floatValue;
            }
            var autoUpdateValueType = attributeProperty.FindPropertyRelative("m_AutoUpdateValueType");

            EditorGUILayout.PropertyField(autoUpdateValueType);
            if (autoUpdateValueType.intValue != (int)Attribute.AutoUpdateValue.None)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateStartDelay"));
                EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateInterval"));
                EditorGUILayout.PropertyField(attributeProperty.FindPropertyRelative("m_AutoUpdateAmount"));
                EditorGUI.indentLevel--;
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
            }

            var attribute = m_AttributeManager.Attributes[index];

            if (InspectorUtility.Foldout(attribute, new GUIContent("States"), false))
            {
                // The Attribute 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 selectedAttribute = attribute as Attribute;
                var gameObject        = new GameObject();
                var stateIndexHelper  = gameObject.AddComponent <StateInspectorHelper>();
                stateIndexHelper.StateIndexData = new int[selectedAttribute.States.Length];
                for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i)
                {
                    stateIndexHelper.StateIndexData[i] = i;
                }
                var stateIndexSerializedObject = new SerializedObject(stateIndexHelper);
                m_ReorderableAttributeStateList = StateInspector.DrawStates(m_ReorderableAttributeStateList, serializedObject, stateIndexSerializedObject.FindProperty("m_StateIndexData"),
                                                                            GetSelectedAttributeStateIndexKey(selectedAttribute), OnAttributeStateListDraw, OnAttributeStateListAdd, OnAttributeStateListReorder,
                                                                            OnAttributeStateListRemove);
                DestroyImmediate(gameObject);
            }
        }
 /// <summary>
 /// Adds a new state element to the list.
 /// </summary>
 private void OnAnimatorAudioStateSetStateListAdd(ReorderableList list)
 {
     StateInspector.OnStateListAdd(AddExistingAnimatorAudioStateSetStatePreset, CreateAnimatorAudioStateSetStatePreset);
 }
 /// <summary>
 /// Adds a new state element to the list.
 /// </summary>
 private void OnItemSetStateListAdd(ReorderableList list)
 {
     m_ItemSetListIndexAdd = m_ReorderableListCategoryMap[list];
     StateInspector.OnStateListAdd(AddExistingItemSetPreset, CreateItemSetPreset);
 }
        /// <summary>
        /// Draws the specified item set.
        /// </summary>
        private void DrawSelectedItemSet(ItemSet itemSet, int index)
        {
            GUILayout.Label("Item Set " + index, Shared.Editor.Inspectors.Utility.InspectorStyles.CenterBoldLabel);

            itemSet.State = EditorGUILayout.TextField(new GUIContent("State", "Optionally specify a state that the character should switch to when the Item Set is active."), itemSet.State);

            // Draws all of the slots ItemDefinitions.
            for (int i = 0; i < m_InventoryBase.SlotCount; ++i)
            {
                var itemDefinition = (ItemDefinitionBase)EditorGUILayout.ObjectField("Slot " + i, itemSet.Slots[i], typeof(ItemDefinitionBase), false);
                // The ItemIdentifier must belong to the parent category.
                if (itemDefinition != null && m_ItemSetManager.IsCategoryMember(itemDefinition, m_ItemSetListIndex))
                {
                    itemSet.Slots[i] = itemDefinition;
                    if (Application.isPlaying)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.LabelField("Item Identifier", itemSet.ItemIdentifiers[i] == null ? "(none)" : itemSet.ItemIdentifiers[i].ToString());
                        EditorGUI.indentLevel--;
                    }
                }
                else
                {
                    itemSet.Slots[i] = null;
                    if (itemDefinition != null)
                    {
                        Debug.LogError($"Error: Unable to add ItemDefinition {itemDefinition.name}. The ItemDefinition category doesn't match the parent category.");
                    }
                }
            }

            var isDefaultIndex       = m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].DefaultItemSetIndex == index;
            var isDefaultIndexToggle = EditorGUILayout.Toggle(new GUIContent("Default", "True if the Item Set is the default Item Set."), isDefaultIndex);

            if (isDefaultIndex != isDefaultIndexToggle)
            {
                m_ItemSetManager.CategoryItemSets[m_ItemSetListIndex].DefaultItemSetIndex = isDefaultIndexToggle ? index : -1;
            }

            itemSet.Enabled       = EditorGUILayout.Toggle(new GUIContent("Enabled", "True if the Item Set can be equipped."), itemSet.Enabled);
            itemSet.CanSwitchTo   = EditorGUILayout.Toggle(new GUIContent("Can Switch To", "True if the ItemSet can be switched to by the EquipNext/EquipPrevious abilities."), itemSet.CanSwitchTo);
            itemSet.DisabledIndex = EditorGUILayout.IntField(new GUIContent("Disabled Index", "The ItemSet that should be activated if the current ItemSet is disabled."), itemSet.DisabledIndex);

            if (Shared.Editor.Inspectors.Utility.InspectorUtility.Foldout(itemSet, new GUIContent("States"), false))
            {
                // 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[itemSet.States.Length];
                for (int i = 0; i < stateIndexHelper.StateIndexData.Length; ++i)
                {
                    stateIndexHelper.StateIndexData[i] = i;
                }
                var stateIndexSerializedObject = new SerializedObject(stateIndexHelper);
                m_ReorderableItemSetStateList[m_ItemSetListIndex] = StateInspector.DrawStates(m_ReorderableItemSetStateList[m_ItemSetListIndex], serializedObject,
                                                                                              stateIndexSerializedObject.FindProperty("m_StateIndexData"),
                                                                                              GetSelectedItemSetStateIndexKey(index), OnItemSetStateListDraw, OnItemSetStateListAdd,
                                                                                              OnItemSetStateListReorder, OnItemSetStateListRemove);
                if (!m_ReorderableListCategoryMap.ContainsKey(m_ReorderableItemSetStateList[m_ItemSetListIndex]))
                {
                    m_ReorderableListCategoryMap.Add(m_ReorderableItemSetStateList[m_ItemSetListIndex], m_ItemSetListIndex);
                }
                DestroyImmediate(gameObject);
            }
        }
Пример #27
0
 /// <summary>
 /// Adds a new state element to the list.
 /// </summary>
 private void OnPickupSetStateListAdd(ReorderableList list)
 {
     StateInspector.OnStateListAdd(AddExistingPickupSetPreset, CreatePickupSetPreset);
 }