예제 #1
0
        private void UpdateSelectedTree()
        {
            if (Selection.activeObject is ClassTree)
            {
                selectedTree      = Selection.activeObject as ClassTree;
                selectedAssetPath = AssetDatabase.GetAssetPath(selectedTree.GetInstanceID());

                if (!selectedTree.ContainsTier(1))
                {
                    selectedTree.AddTier(1, ClassTierType.Class);
                    selectedTree.AddNode(1);
                }

                selectedTree.Initialize();
            }
            else
            {
                selectedTree      = null;
                selectedAssetPath = "";
            }

            Repaint();
        }
예제 #2
0
        private void CreateContextMenu(Vector2 position)
        {
            GenericMenu menu = new GenericMenu();

            ClassTier targetTier = selectedTree.GetTierAt(position);

            if (targetTier != null)
            {
                ClassNode targetNode = selectedTree.GetNodeAt(position);
                if (targetNode != null)
                {
                    if (targetTier.level == 1 || targetTier.tierType == ClassTierType.Skill)
                    {
                        menu.AddDisabledItem(new GUIContent("Delete Node"));
                    }
                    else
                    {
                        menu.AddItem(
                            new GUIContent("Delete Node"),
                            false,
                            () =>
                        {
                            selectedTree.RemoveNode(targetNode);
                            EditorUtility.SetDirty(selectedTree);
                        }
                            );
                    }
                }
                else
                {
                    if (targetTier.level == 1 || targetTier.tierType == ClassTierType.Skill)
                    {
                        menu.AddDisabledItem(new GUIContent("Create Node"));
                    }
                    else
                    {
                        menu.AddItem(
                            new GUIContent("Create Node"),
                            false,
                            () =>
                        {
                            selectedTree.AddNode(targetTier.level);
                            EditorUtility.SetDirty(selectedTree);
                        }
                            );
                    }
                }

                menu.AddSeparator("");

                if (targetTier.level == 1)
                {
                    menu.AddDisabledItem(new GUIContent("Delete Tier"));
                }
                else
                {
                    menu.AddItem(
                        new GUIContent("Delete Tier"),
                        false,
                        () =>
                    {
                        selectedTree.RemoveTier(targetTier.level);
                        EditorUtility.SetDirty(selectedTree);
                    }
                        );
                }

                if (selectedTree.ContainsTier(targetTier.level + 1))
                {
                    menu.AddDisabledItem(new GUIContent("Add Subclass Tier Below"));
                    menu.AddDisabledItem(new GUIContent("Add Skill Tier Below"));
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Add Subclass Tier Below"));
                    menu.AddItem(
                        new GUIContent("Add Skill Tier Below"),
                        false,
                        () =>
                    {
                        selectedTree.AddTier(targetTier.level + 1, ClassTierType.Skill);
                        EditorUtility.SetDirty(selectedTree);
                    }
                        );
                }
            }
            else
            {
                // TODO: implement subclasses
                menu.AddDisabledItem(new GUIContent("Add Subclass Tier"));
                menu.AddItem(
                    new GUIContent("Add Skill Tier"),
                    false,
                    () =>
                {
                    int highestLevel = 0;
                    foreach (ClassTier tier in selectedTree.Layers.Values)
                    {
                        if (tier.level > highestLevel)
                        {
                            highestLevel = tier.level;
                        }
                    }
                    selectedTree.AddTier(highestLevel + 1, ClassTierType.Skill);
                    EditorUtility.SetDirty(selectedTree);
                }
                    );
            }

            menu.ShowAsContext();
        }