Ejemplo n.º 1
0
        /// <summary>
        /// Draws the Categories editor.
        /// </summary>
        private void DrawCategories()
        {
            var categories = m_ItemCollection.Categories;

            if (categories == null)
            {
                // At least one category needs to exist.
                var category = ScriptableObject.CreateInstance <Category>();
                category.ID   = Category.GenerateID();
                category.name = "Items";
                categories    = m_ItemCollection.Categories = new Category[] { category };

                AssetDatabase.AddObjectToAsset(category, AssetDatabase.GetAssetPath(m_ItemCollection));
                AssetDatabase.SaveAssets();
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_ItemCollection));
            }

            EditorGUILayout.BeginHorizontal();
            GUI.SetNextControlName("CategoryName");
            m_CategoryName = EditorGUILayout.TextField("Name", m_CategoryName);
            GUI.enabled    = !string.IsNullOrEmpty(m_CategoryName) && (m_CategoryTreeView.TreeModal as CategoryCollectionModal).IsUniqueName(m_CategoryName);
            if (GUILayout.Button("Add", GUILayout.Width(100)) || (Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "CategoryName"))
            {
                // Create the new Category.
                var category = ScriptableObject.CreateInstance <Category>();
                category.ID   = Category.GenerateID();
                category.name = m_CategoryName;

                // Add the Category to the ItemCollection.
                Array.Resize(ref categories, categories.Length + 1);
                categories[categories.Length - 1] = category;
                m_ItemCollection.Categories       = categories;
                AssetDatabase.AddObjectToAsset(category, m_ItemCollection);

                // Reset.
                EditorUtility.SetDirty(m_ItemCollection);
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_ItemCollection));
                m_CategoryName = string.Empty;
                GUI.FocusControl("");
                m_CategoryTreeView.Reload();
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
            GUILayout.Space(5);

            if (categories != null)
            {
                var guiRect = GUILayoutUtility.GetLastRect();
                var height  = m_MainManagerWindow.position.height - guiRect.yMax - 21;
                m_CategoryTreeView.searchString = m_CategorySearchField.OnGUI(new Rect(0, guiRect.yMax, m_MainManagerWindow.position.width - m_MainManagerWindow.MenuWidth - 2, 20), m_CategoryTreeView.searchString);
                m_CategoryTreeView.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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the ItemTypes editor.
        /// </summary>
        private void DrawItemTypes()
        {
            var itemTypes = m_ItemCollection.ItemTypes;

            EditorGUILayout.BeginHorizontal();
            GUI.SetNextControlName("ItemTypeName");
            m_ItemTypeName = EditorGUILayout.TextField("Name", m_ItemTypeName);
            GUI.enabled    = !string.IsNullOrEmpty(m_ItemTypeName) && (m_ItemTypeTreeView.TreeModal as ItemTypeCollectionModal).IsUniqueName(m_ItemTypeName);
            if (GUILayout.Button("Add", GUILayout.Width(100)) || (Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "ItemTypeName"))
            {
                // Create the new ItemType.
                var itemType = ScriptableObject.CreateInstance <ItemType>();
                itemType.name = m_ItemTypeName;
                if (m_ItemCollection.Categories != null && m_ItemCollection.Categories.Length > 0)
                {
                    itemType.CategoryIDs = new uint[] { m_ItemCollection.Categories[0].ID };
                }

                // Add the ItemType to the ItemCollection.
                Array.Resize(ref itemTypes, itemTypes != null ? itemTypes.Length + 1 : 1);
                itemType.ID = (uint)itemTypes.Length - 1;
                itemTypes[itemTypes.Length - 1] = itemType;
                m_ItemCollection.ItemTypes      = itemTypes;
                AssetDatabase.AddObjectToAsset(itemType, m_ItemCollection);
                AssetDatabase.SaveAssets();
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(m_ItemCollection));

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

                // Reset.
                EditorUtility.SetDirty(m_ItemCollection);
                m_ItemTypeName = string.Empty;
                GUI.FocusControl("");
                m_ItemTypeTreeView.Reload();
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
            GUILayout.Space(5);

            if (itemTypes != null && itemTypes.Length > 0)
            {
                var guiRect = GUILayoutUtility.GetLastRect();
                var height  = m_MainManagerWindow.position.height - guiRect.yMax - 21;
                m_ItemTypeTreeView.searchString = m_ItemTypeSearchField.OnGUI(new Rect(0, guiRect.yMax, m_MainManagerWindow.position.width - m_MainManagerWindow.MenuWidth - 2, 20), m_ItemTypeTreeView.searchString);
                m_ItemTypeTreeView.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);
            }
        }
Ejemplo n.º 3
0
    private void OnGUI()
    {
        if (!valid)
        {
            return;
        }
        InitIfNeeded();

        m_retIdx = EditorGUILayout.Popup("Playable Director", m_retIdx, m_list);
        EditorGUI.BeginChangeCheck();
        m_trackIdx = EditorGUILayout.Popup("Tracks", m_trackIdx, m_tracks);
        if (EditorGUI.EndChangeCheck() && m_trackIdx != 0)
        {
            Selection.activeObject = m_animTracks[m_trackIdx - 1];
        }
        selected = (GameObject)EditorGUILayout.ObjectField("Rig Object", selected, typeof(GameObject), true);
        GUILayout.Space(10);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Load Selected Anim Clip(s)", GUILayout.Height(30)))
        {
            foreach (var obj in Selection.objects)
            {
                var clip = obj as AnimationClip;
                if (clip != null)
                {
                    animClips.Add(clip);
                }
            }
            animClips = animClips.OrderBy(n => n.name).ToList();
            m_TreeView.SetList(animClips);
            animClips.Clear();
        }
        if (GUILayout.Button("Clear List", GUILayout.Height(30)))
        {
            ClearList();
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(5);

        GUILayout.Label("Loaded animation clip:");

        m_TreeView.OnGUI(treeViewRect);

        GUILayout.BeginArea(bottomRect);

        if (GUILayout.Button("IMPORT CLIP", GUILayout.Height(35)))
        {
            if (selected != null && m_directorList[m_retIdx] != null)
            {
                ConstructTimeline();
                EnableAlwaysAnimate(selected);
                ClearList();
            }
            else
            {
                Debug.LogWarning("Missing director or scene object or animation clip");
            }
        }
        GUILayout.EndArea();
    }