Beispiel #1
0
        /// <summary>
        /// Draws the ItemTypes editor.
        /// </summary>
        private void DrawTab(StateTab tab)
        {
            if (null == tab.animationStateSet)
            {
                EditorGUILayout.HelpBox("An invalid animation collection was selected.", MessageType.Error);
            }
            var animationStates = tab.animationStateSet != null ? tab.animationStateSet.AnimationStates : null;

            EditorGUILayout.BeginHorizontal();
            GUI.SetNextControlName("AnimationStateName");
            m_AnimationStateName = EditorGUILayout.TextField("Name", m_AnimationStateName);
            GUI.enabled          = !string.IsNullOrEmpty(m_AnimationStateName) && (tab.treeView.TreeModal as AnimationStateModel).IsUniqueName(m_AnimationStateName);
            if (GUILayout.Button("Add", GUILayout.Width(100)) || (Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "AnimationStateName"))
            {
                // Create the new ItemType.
                var itemType = new Inventory.AnimationState();
                itemType.name = m_AnimationStateName;

                // Add the ItemType to the ItemCollection.
                Array.Resize(ref animationStates, animationStates != null ? animationStates.Length + 1 : 1);
                itemType.ID = animationStates.Length - 1;
                animationStates[animationStates.Length - 1] = itemType;
                tab.animationStateSet.AnimationStates       = animationStates;
                Debug.Log("Asset path: " + AssetDatabase.GetAssetPath(tab.animationStateSet));
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tab.animationStateSet));

                // Select the newly added item.
                tab.treeView.SetSelection(new List <int>()
                {
                    itemType.ID
                }, TreeViewSelectionOptions.FireSelectionChanged);

                // Reset.
                EditorUtility.SetDirty(m_AnimationStateCollection);
                EditorUtility.SetDirty(tab.animationStateSet);
                m_AnimationStateName = string.Empty;
                GUI.FocusControl("");
                tab.treeView.Reload();
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
            GUILayout.Space(5);

            if (animationStates != null && animationStates.Length > 0)
            {
                var guiRect = GUILayoutUtility.GetLastRect();
                var height  = m_MainManagerWindow.position.height - guiRect.yMax - 21;
                tab.treeView.searchString = tab.searchField.OnGUI(new Rect(0, guiRect.yMax, m_MainManagerWindow.position.width - m_MainManagerWindow.MenuWidth - 2, 20), tab.treeView.searchString);
                tab.treeView.OnGUI(new Rect(0, guiRect.yMax + 20, m_MainManagerWindow.position.width - m_MainManagerWindow.MenuWidth - 1, height));
                // OnGUI doesn't update the GUILayout rect so add a blank space to account for it.
                GUILayout.Space(height + 10);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Draws the identify, duplicate and delete buttons for the ItemType.
        /// </summary>
        /// <param name="rowRect">The rect of the ItemType row.</param>
        /// <param name="id">The id of the ItemType to draw the controls of.</param>
        /// <returns>True if the controls changed the ItemCollection.</returns>
        private bool DrawControls(Rect rowRect, int id)
        {
            var identifyRect = rowRect;

            identifyRect.x      = identifyRect.width - 68;
            identifyRect.width  = 20;
            identifyRect.y     += 4;
            identifyRect.height = 16;
            if (GUI.Button(identifyRect, InspectorStyles.InfoIcon, InspectorStyles.NoPaddingButtonStyle))
            {
                Selection.activeObject = m_AnimationStateSet;
                EditorGUIUtility.PingObject(Selection.activeObject);
            }

            var duplicateRect = rowRect;

            duplicateRect.x      = duplicateRect.width - 44;
            duplicateRect.width  = 20;
            duplicateRect.y     += 4;
            duplicateRect.height = 16;
            if (GUI.Button(duplicateRect, InspectorStyles.DuplicateIcon, InspectorStyles.NoPaddingButtonStyle))
            {
                var itemType       = m_AnimationStateSet.AnimationStates[id];
                var clonedItemType = new Inventory.AnimationState();
                // Generate a unique name for the item.
                var    index = 1;
                string name;
                do
                {
                    name = itemType.name + " (" + index + ")";
                    index++;
                } while (!IsUniqueName(name));
                clonedItemType.name = name;

                // Add the ItemType to the ItemCollection.
                var itemTypes = m_AnimationStateSet.AnimationStates;
                Array.Resize(ref itemTypes, itemTypes.Length + 1);
                clonedItemType.ID = itemTypes.Length - 1;
                itemTypes[itemTypes.Length - 1]     = clonedItemType;
                m_AnimationStateSet.AnimationStates = itemTypes;
                EditorUtility.SetDirty(m_AnimationStateSet);
                return(true);
            }

            var deleteRect = rowRect;

            deleteRect.x      = deleteRect.width - 20;
            deleteRect.width  = 18;
            deleteRect.y     += 4;
            deleteRect.height = 16;
            if (GUI.Button(deleteRect, InspectorStyles.DeleteIcon, InspectorStyles.NoPaddingButtonStyle))
            {
                if (m_BeforeModalChange != null)
                {
                    m_BeforeModalChange();
                }

                // Remove the ItemType.
                var itemTypes = new List <Inventory.AnimationState>(m_AnimationStateSet.AnimationStates);
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_AnimationStateSet));
                itemTypes.RemoveAt(id);
                m_AnimationStateSet.AnimationStates = itemTypes.ToArray();
                EditorUtility.SetDirty(m_AnimationStateSet);

                // Update all of the ItemIDs.
                for (int i = 0; i < itemTypes.Count; ++i)
                {
                    m_AnimationStateSet.AnimationStates[i].ID = i;
                }
                return(true);
            }
            return(false);
        }