private void DisplaySelectedSkillContent(SkillAsset skill)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("Parameters", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Skill Name", GUILayout.Width(100));
            skill.Name = EditorGUILayout.TextField(skill.Name);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Cooldown", GUILayout.Width(100));
            skill.Cooldown = EditorGUILayout.FloatField(skill.Cooldown);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Cast Time", GUILayout.Width(100));
            skill.CastTime = EditorGUILayout.FloatField(skill.CastTime);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Range", GUILayout.Width(100));
            skill.Range = EditorGUILayout.FloatField(skill.Range);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Duration", GUILayout.Width(100));
            skill.Delay = EditorGUILayout.FloatField(skill.Delay);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Interruptable", GUILayout.Width(100));
            skill.Interruptable = EditorGUILayout.Toggle(skill.Interruptable);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Unlocked Level", GUILayout.Width(100));
            skill.RequiredLevel = EditorGUILayout.IntField(skill.RequiredLevel);
            GUILayout.EndHorizontal();

            foreach (var extension in SkillEditorUtility.GetExtensions())
            {
                if (extension.CanHandleType(skill.GetType()))
                {
                    extension.OnGUI(skill);
                }
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Height(200));
            GUILayout.Label("Prerequisites", EditorStyles.boldLabel);

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

            for (int i = 0; i < skill.Prerequisites.Count; i++)
            {
                SkillPrerequisiteAsset prerequisite = skill.Prerequisites [i];
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (GUILayout.Button("-", EditorStyles.toolbarButton, GUILayout.Width(30)) &&
                    EditorUtility.DisplayDialog("Remove prerequisite", "Are you sure you want to delete the prerequisite?", "Delete", "Cancel"))
                {
                    skill.Prerequisites.RemoveAt(i);
                }
                GUILayout.Label("StatType", GUILayout.Width(100));
                //prerequisite.StatName = EditorGUILayout.TextField (prerequisite.StatName);

                var targetStatType = RPGStatTypeDatabase.Instance.Get(prerequisite.StatName, true);
                if (GUILayout.Button(targetStatType == null ? "Assign Type" : targetStatType.Name, EditorStyles.toolbarButton, GUILayout.Width(100)))
                {
                    XmlDatabaseEditorUtility.ShowContext(RPGStatTypeDatabase.Instance, (statTypeAsset) => {
                        prerequisite.StatName = statTypeAsset.Id;
                    }, typeof(RPGStatTypeWindow));
                }

                GUILayout.Label("StatValue", GUILayout.Width(100));
                prerequisite.StatValue = EditorGUILayout.IntField(prerequisite.StatValue);
                GUILayout.EndHorizontal();
            }

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

            if (GUILayout.Button("Add Prerequisite", EditorStyles.toolbarButton))
            {
                var newPrerequisite = new SkillPrerequisiteAsset();
                skill.Prerequisites.Add(newPrerequisite);
            }

            GUILayout.EndVertical();

            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("Effects", EditorStyles.boldLabel);
            skillEffectScroll = GUILayout.BeginScrollView(skillEffectScroll, false, true);

            GUILayout.BeginHorizontal();
            GUILayout.Label("", EditorStyles.boldLabel, GUILayout.Width(30));
            GUILayout.Label("Type", EditorStyles.boldLabel, GUILayout.Width(150));
            GUILayout.Label("Delay", EditorStyles.boldLabel, GUILayout.Width(50));
            GUILayout.EndHorizontal();

            for (int i = 0; i < skill.Effects.Count; i++)
            {
                //foreach(var effect in skill.Effects){
                EffectAsset effect = skill.Effects[i];
                GUILayout.BeginHorizontal(EditorStyles.toolbar);

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

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

                effect.Delay = EditorGUILayout.FloatField(effect.Delay, GUILayout.Width(50));
                GUILayout.EndHorizontal();


                if (SelectedEffectIndex == i)
                {
                    GUILayout.BeginVertical(EditorStyles.helpBox);
                    foreach (var extension in EffectEditorUtility.GetExtensions())
                    {
                        if (extension.CanHandleType(effect.GetType()))
                        {
                            extension.OnGUI(effect);
                        }
                    }
                    GUILayout.EndVertical();
                }
            }

            //Object source = null;
            //source = EditorGUILayout.ObjectField(source, typeof(Object), true);
            //AssetDatabase.GetAssetPath (source);


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

            if (GUILayout.Button("Add Effect", EditorStyles.toolbarButton))
            {
                if (typeof(PositionSkillAsset).IsAssignableFrom(skill.GetType()))
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetPositionEffectNames(), (index) => {
                        var skillEffectAsset = EffectEditorUtility.CreatePositionEffectAsset(index);
                        skill.Effects.Add(skillEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <SkillCollectionWindow> ();
                    }).ShowAsContext();
                }
                else if (typeof(TargetSkillAsset).IsAssignableFrom(skill.GetType()))
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetTargetEffectNames(), (index) => {
                        var skillEffectAsset = EffectEditorUtility.CreateTargetEffectAsset(index);
                        skill.Effects.Add(skillEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <SkillCollectionWindow> ();
                    }).ShowAsContext();
                }
                else
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetNames(), (index) => {
                        var skillEffectAsset = EffectEditorUtility.CreateAsset(index);
                        skill.Effects.Add(skillEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <SkillCollectionWindow> ();
                    }).ShowAsContext();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
Ejemplo n.º 2
0
        public void OnGUI(object asset, ItemDatabaseWindow itemDBWindow)
        {
            GUILayout.BeginVertical();

            UsableItemAsset itemAsset = asset as UsableItemAsset;

            for (int i = 0; i < itemAsset.Effects.Count; i++)
            {
                EffectAsset effect = itemAsset.Effects[i];
                GUILayout.BeginHorizontal(EditorStyles.toolbar);

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

                bool clicked = GUILayout.Toggle(i == itemDBWindow.SelectedEffectIndex, effect.GetType().Name, ToggleButtonStyle, GUILayout.Width(150));
                if (clicked != (i == itemDBWindow.SelectedEffectIndex))
                {
                    if (clicked)
                    {
                        itemDBWindow.SelectedEffectIndex = i;
                        GUI.FocusControl(null);
                    }
                    else
                    {
                        itemDBWindow.SelectedEffectIndex = -1;
                    }
                }
                GUILayout.EndHorizontal();

                if (itemDBWindow.SelectedEffectIndex == i)
                {
                    GUILayout.BeginVertical();
                    foreach (var extension in EffectEditorUtility.GetExtensions())
                    {
                        if (extension.CanHandleType(effect.GetType()))
                        {
                            extension.OnGUI(effect);
                        }
                    }
                    GUILayout.EndVertical();
                }
            }

            if (GUILayout.Button("Add Effect", EditorStyles.toolbarButton))
            {
                Debug.Log(itemAsset.GetType().ToString());
                if (typeof(PositionUsableItemAsset).IsAssignableFrom(itemAsset.GetType()))
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetPositionEffectNames(), (index) => {
                        var itemEffectAsset = EffectEditorUtility.CreatePositionEffectAsset(index);
                        itemAsset.Effects.Add(itemEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <ItemDatabaseWindow> ();
                    }).ShowAsContext();
                }
                else if (typeof(TargetUsableItemAsset).IsAssignableFrom(itemAsset.GetType()))
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetTargetEffectNames(), (index) => {
                        var itemEffectAsset = EffectEditorUtility.CreateTargetEffectAsset(index);
                        itemAsset.Effects.Add(itemEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <ItemDatabaseWindow> ();
                    }).ShowAsContext();
                }
                else
                {
                    XmlDatabaseEditorUtility.GetGenericMenu(EffectEditorUtility.GetNames(), (index) => {
                        var skillEffectAsset = EffectEditorUtility.CreateAsset(index);
                        itemAsset.Effects.Add(skillEffectAsset);
                        EditorWindow.FocusWindowIfItsOpen <ItemDatabaseWindow> ();
                    }).ShowAsContext();
                }
            }

            GUILayout.EndVertical();
        }