Exemplo n.º 1
0
        public void SetupCollection(SkillCollectionAsset collectionAsset)
        {
            IsCollectionSetup = true;

            if (collectionAsset != null)
            {
                SkillDict.Clear();

                // add all skills to the collection
                foreach (var skillAsset in collectionAsset.Skills)
                {
                    if (!SkillDict.ContainsKey(skillAsset.Name))
                    {
                        Skill newSkill = skillAsset.CreateInstance();
                        newSkill.Owner = this.gameObject;
                        SkillDict.Add(skillAsset.Name, newSkill);
                    }
                    else
                    {
                        Debug.Log("attempted to add a skill with the same name...");
                    }
                }
            }
        }
        protected override void DisplayAssetGUI(EntityAsset asset)
        {
            GUILayout.BeginVertical("Box");

            GUILayout.BeginHorizontal();

            //asset.Icon = (Sprite)EditorGUILayout.ObjectField(asset.Icon, typeof(Sprite), false,
            //	GUILayout.Width(72), GUILayout.Height(72));

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Name", GUILayout.Width(100));
            asset.Name = EditorGUILayout.TextField(asset.Name);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Gambit Collection ", GUILayout.Width(100));

            GambitCollectionAsset gambitCollectionAsset = GambitCollectionDatabase.Instance.Get(asset.GambitCollectionId);

            if (GUILayout.Button(gambitCollectionAsset == null?"Assign Gambit Collection":gambitCollectionAsset.Name))
            {
                XmlDatabaseEditorUtility.ShowContext(GambitCollectionDatabase.Instance, (gambitColAsset) => {
                    if (EditorUtility.DisplayDialog("Change gambit collection", "Are you sure you want to change the associated gambit collection? Changing gambit collection might result in unsynchronized skill collection", "Change", "Cancel"))
                    {
                        asset.GambitCollectionId = gambitColAsset.Id;
                    }
                });
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Skill Collection ", GUILayout.Width(100));

            SkillCollectionAsset skillCollectionAsset = SkillCollectionDatabase.Instance.Get(asset.SkillCollectionId);

            if (GUILayout.Button(skillCollectionAsset == null?"Assign Skill Collection":skillCollectionAsset.Name))
            {
                XmlDatabaseEditorUtility.ShowContext(SkillCollectionDatabase.Instance, (skillColAsset) => {
                    if (EditorUtility.DisplayDialog("Change skill collection", "Are you sure you want to change the associated skill collection? Changing skill collection might result in loss of skill data in gambits.", "Change", "Cancel"))
                    {
                        asset.SkillCollectionId = skillColAsset.Id;
                    }
                });
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Description", GUILayout.Width(100));
            asset.Description = EditorGUILayout.TextField(asset.Description);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Tag", GUILayout.Width(100));
            asset.Tag = (int)(PerceptionTags)(EditorGUILayout.EnumFlagsField((PerceptionTags)asset.Tag));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Alert Mask", GUILayout.Width(100));
            asset.AlertMask = (int)(PerceptionTags)(EditorGUILayout.EnumFlagsField((PerceptionTags)asset.AlertMask));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Vision", GUILayout.Width(100));
            asset.Vision = EditorGUILayout.FloatField(asset.Vision);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Exemplo n.º 3
0
        protected override void DisplayAssetGUI(GambitCollectionAsset asset)
        {
            GUILayout.BeginVertical();

            var selectedCollection = GambitCollectionDatabase.Instance.Get(SelectedAssetId);

            if (selectedCollection != null)
            {
                GUILayout.Label(selectedCollection.Name, EditorStyles.toolbarButton);

                GUILayout.BeginHorizontal();
                GUILayout.Label("ID: " + selectedCollection.Id.ToString() + ", Name ", GUILayout.Width(100));
                selectedCollection.Name = EditorGUILayout.TextField(selectedCollection.Name);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Skill Collection ", GUILayout.Width(100));

                SkillCollectionAsset skillCollectionAsset = SkillCollectionDatabase.Instance.Get(asset.SkillCollectionId);
                if (GUILayout.Button(skillCollectionAsset == null?"Assign Skill Collection":skillCollectionAsset.Name))
                {
                    XmlDatabaseEditorUtility.ShowContext(SkillCollectionDatabase.Instance, (skillColAsset) => {
                        if (EditorUtility.DisplayDialog("Change skill collection", "Are you sure you want to change the associated skill collection? Changing skill collection might result in loss of skill data in gambits.", "Change", "Cancel"))
                        {
                            asset.SkillCollectionId = skillColAsset.Id;
                        }
                    });
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginVertical(EditorStyles.helpBox);

                GUILayout.BeginHorizontal();
                GUILayout.Label("", EditorStyles.boldLabel, GUILayout.Width(30));
                GUILayout.Label("Priority", EditorStyles.boldLabel, GUILayout.Width(100));
                GUILayout.Label("Type", EditorStyles.boldLabel, GUILayout.Width(200));
                GUILayout.Label("Skill", EditorStyles.boldLabel, GUILayout.Width(150));
                GUILayout.Label("Use Limit", EditorStyles.boldLabel, GUILayout.Width(100));
                GUILayout.EndHorizontal();

                gambitSelectionScroll = GUILayout.BeginScrollView(gambitSelectionScroll, false, true);

                for (int i = 0; i < asset.Gambits.Count; i++)
                {
                    GambitAsset gambitAsset = asset.Gambits [i];
                    GUILayout.BeginHorizontal(EditorStyles.toolbar);

                    if (GUILayout.Button("-", EditorStyles.toolbarButton, GUILayout.Width(30)) &&
                        EditorUtility.DisplayDialog("Remove Gambit", "Are you sure you want to delete the gambit?", "Delete", "Cancel"))
                    {
                        asset.Gambits.RemoveAt(i);
                    }

                    gambitAsset.Priority = EditorGUILayout.IntField(gambitAsset.Priority, GUILayout.Width(100));

                    bool clicked = GUILayout.Toggle(i == SelectedGambitIndex, gambitAsset.GetType().Name, ToggleButtonStyle, GUILayout.Width(200));
                    if (clicked != (i == SelectedGambitIndex))
                    {
                        if (clicked)
                        {
                            SelectedGambitIndex = i;
                            GUI.FocusControl(null);
                        }
                        else
                        {
                            SelectedGambitIndex = -1;
                        }
                    }

                    if (skillCollectionAsset == null)
                    {
                        GUI.enabled = false;
                        GUILayout.Button("None", EditorStyles.toolbarButton, GUILayout.Width(150));
                    }
                    else
                    {
                        GUI.enabled = true;

                        bool skillFound = false;
                        int  iterator   = 0;
                        while (!skillFound && (iterator < skillCollectionAsset.Skills.Count))
                        {
                            if (skillCollectionAsset.Skills [iterator].Name == gambitAsset.SkillId)
                            {
                                skillFound = true;
                                break;
                            }
                            else
                            {
                                iterator++;
                            }
                        }
                        string skillLabel = skillFound?gambitAsset.SkillId:"Missing";

                        if (GUILayout.Button(gambitAsset.SkillId == ""? "Assign Skill" : skillLabel, EditorStyles.toolbarButton, GUILayout.Width(150)))
                        {
                            List <string> skillList = new List <string> ();
                            if (typeof(PositionGambitAsset).IsAssignableFrom(gambitAsset.GetType()))
                            {
                                for (int j = 0; j < skillCollectionAsset.Skills.Count; j++)
                                {
                                    if (!typeof(TargetSkillAsset).IsAssignableFrom(skillCollectionAsset.Skills [j].GetType()))
                                    {
                                        skillList.Add(skillCollectionAsset.Skills [j].Name);
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < skillCollectionAsset.Skills.Count; j++)
                                {
                                    if (!typeof(PositionSkillAsset).IsAssignableFrom(skillCollectionAsset.Skills [j].GetType()))
                                    {
                                        skillList.Add(skillCollectionAsset.Skills [j].Name);
                                    }
                                }
                            }

                            string [] skillNames = skillList.ToArray();
                            XmlDatabaseEditorUtility.GetGenericMenu(skillNames, (index) => {
                                gambitAsset.SkillId = skillNames[index];
                            }).ShowAsContext();
                        }
                    }

                    GUI.enabled = true;

                    gambitAsset.MaxUse = EditorGUILayout.IntField(gambitAsset.MaxUse);

                    GUILayout.EndHorizontal();

                    if (SelectedGambitIndex == i)
                    {
                        foreach (var editorExtension in GambitEditorUtility.GetExtensions())
                        {
                            if (editorExtension.CanHandleType(gambitAsset.GetType()))
                            {
                                editorExtension.OnGUI(gambitAsset);
                            }
                        }

                        DisplayGambitGUI(gambitAsset);
                    }
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndScrollView();

                if (GUILayout.Button("Add Gambit", EditorStyles.toolbarButton))
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(GambitEditorUtility.GetNames(), (index) => {
                        var gambitAsset = GambitEditorUtility.CreateAsset(index);
                        asset.Gambits.Add(gambitAsset);
                        EditorWindow.FocusWindowIfItsOpen <GambitCollectionWindow> ();
                    }).ShowAsContext();
                }

                GUILayout.EndVertical();
            }

            GUILayout.EndVertical();
        }