public override void OnInspectorGUI()
    {
        OSSkillTree tree = (OSSkillTree)target;

        tree.definitions = (OSDefinitions)EditorGUILayout.ObjectField("Definitions", tree.definitions, typeof(OSDefinitions), false);

        if (!tree.definitions)
        {
            GUI.color = Color.red;
            EditorGUILayout.LabelField("You need to link an OSDefinitions prefab with this item", EditorStyles.boldLabel);
            GUI.color = Color.white;
        }
        else
        {
            tree.eventHandler = (GameObject)EditorGUILayout.ObjectField("Event handler", tree.eventHandler, typeof(GameObject), true);

            EditorGUILayout.Space();

            string[] rootStrings = new string [tree.roots.Length];

            for (int i = 0; i < rootStrings.Length; i++)
            {
                rootStrings[i] = tree.roots[i].name;
            }

            EditorGUILayout.BeginHorizontal();

            rootIndex = EditorGUILayout.Popup("Root", rootIndex, rootStrings);

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
            {
                if (tree.roots.Length > 1)
                {
                    List <OSSkillTree.Root> tmp = new List <OSSkillTree.Root> (tree.roots);

                    tmp.RemoveAt(rootIndex);

                    tree.roots = tmp.ToArray();

                    rootIndex = Mathf.Clamp(0, tree.roots.Length - 1, rootIndex);
                }
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndHorizontal();

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <OSSkillTree.Root> tmp = new List <OSSkillTree.Root> (tree.roots);

                OSSkillTree.Root newRoot = new OSSkillTree.Root();
                newRoot.name = "New Root";
                tmp.Add(newRoot);

                rootIndex = tree.roots.Length;

                tree.roots = tmp.ToArray();
            }
            GUI.backgroundColor = Color.white;

            if (tree.roots.Length < 1)
            {
                return;
            }

            GUILayout.Space(20);

            tree.roots[rootIndex].name = EditorGUILayout.TextField("Name", tree.roots[rootIndex].name);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Skills");

            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(20);

            EditorGUILayout.BeginVertical();

            foreach (OSSkillTree.Skill skill in tree.roots[rootIndex].skills)
            {
                skill.name        = EditorGUILayout.TextField("Name", skill.name);
                skill.description = EditorGUILayout.TextField("Description", skill.description);
                skill.level       = EditorGUILayout.IntField("Level", skill.level);
                skill.mpCost      = EditorGUILayout.FloatField("MP Cost", skill.mpCost);
                skill.active      = EditorGUILayout.Toggle("Active", skill.active);
                skill.enabled     = EditorGUILayout.Toggle("Enabled", skill.enabled);

                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Attributes", GUILayout.Width(100));

                EditorGUILayout.BeginHorizontal();

                GUILayout.Space(20);

                EditorGUILayout.BeginVertical();

                int i = 0;

                foreach (OSAttribute attr in skill.attributes)
                {
                    EditorGUILayout.BeginHorizontal();

                    attr.definitions = tree.definitions;
                    attr.index       = EditorGUILayout.Popup(attr.index, tree.definitions.GetAttributeStrings());
                    attr.value       = EditorGUILayout.FloatField(attr.value);
                    EditorGUILayout.LabelField(attr.suffix, GUILayout.Width(80));

                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                    {
                        List <OSAttribute> tmpAttr = new List <OSAttribute> (skill.attributes);

                        tmpAttr.RemoveAt(i);

                        skill.attributes = tmpAttr.ToArray();
                        return;
                    }
                    GUI.backgroundColor = Color.white;

                    EditorGUILayout.EndHorizontal();

                    i++;
                }

                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    List <OSAttribute> tmpAttr = new List <OSAttribute> (skill.attributes);

                    tmpAttr.Add(new OSAttribute(tree.definitions));

                    skill.attributes = tmpAttr.ToArray();
                }
                GUI.backgroundColor = Color.white;

                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();

                GUILayout.Space(20);
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <OSSkillTree.Skill> skillTmp = new List <OSSkillTree.Skill> (tree.roots[rootIndex].skills);

                OSSkillTree.Skill newSkill = new OSSkillTree.Skill();
                newSkill.name = "New Skill";
                skillTmp.Add(newSkill);

                tree.roots[rootIndex].skills = skillTmp.ToArray();
            }
            GUI.backgroundColor = Color.white;
        }

        if (GUI.changed)
        {
            OSInventoryInspector.SavePrefab(target);
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        OSDefinitions definitions = (OSDefinitions)target;

        EditorGUILayout.LabelField("Resource", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.TextField("Path", definitions.prefabPath);

        if (!definitions.gameObject.activeInHierarchy)
        {
            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("Update", GUILayout.Width(60)))
            {
                string path = AssetDatabase.GetAssetPath(definitions.gameObject);
                if (path.Contains("Assets/Resources/"))
                {
                    path = path.Replace("Assets/Resources/", "");
                    path = path.Replace(".prefab", "");

                    definitions.prefabPath = path;

                    resourceWarning = false;
                }
                else
                {
                    resourceWarning = true;
                }
            }
            GUI.backgroundColor = Color.white;
        }

        EditorGUILayout.EndHorizontal();

        if (resourceWarning)
        {
            definitions.prefabPath = "";
            GUI.color = Color.red;
            EditorGUILayout.LabelField("Object not in /Resources folder!", EditorStyles.boldLabel);
            GUI.color = Color.white;
        }

        EditorGUILayout.Space();

        // Categories
        EditorGUILayout.LabelField("Categories", EditorStyles.boldLabel);

        List <OSCategory> tmpCat;
        List <string>     tmpStr;

        for (int c = 0; c < definitions.categories.Length; c++)
        {
            EditorGUILayout.BeginHorizontal();

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
            {
                tmpCat = new List <OSCategory> (definitions.categories);

                tmpCat.RemoveAt(c);

                definitions.categories = tmpCat.ToArray();
                return;
            }
            GUI.backgroundColor = Color.white;

            definitions.categories[c].id = EditorGUILayout.TextField(definitions.categories[c].id);

            EditorGUILayout.EndHorizontal();

            for (int sc = 0; sc < definitions.categories[c].subcategories.Length; sc++)
            {
                EditorGUILayout.BeginHorizontal();

                GUILayout.Space(104);

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    tmpStr = new List <string> (definitions.categories[c].subcategories);

                    tmpStr.RemoveAt(sc);

                    definitions.categories[c].subcategories = tmpStr.ToArray();
                    return;
                }
                GUI.backgroundColor = Color.white;

                definitions.categories[c].subcategories[sc] = EditorGUILayout.TextField(definitions.categories[c].subcategories[sc]);

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(104);
            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                tmpStr = new List <string> (definitions.categories[c].subcategories);

                tmpStr.Add("Subcategory");

                definitions.categories[c].subcategories = tmpStr.ToArray();
                return;
            }
            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
        {
            tmpCat = new List <OSCategory> (definitions.categories);

            tmpCat.Add(new OSCategory());

            definitions.categories = tmpCat.ToArray();
        }
        GUI.backgroundColor = Color.white;

        EditorGUILayout.Space();

        // Attributes
        EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);

        List <OSAttributeDefinition> tmpAttr;

        for (int a = 0; a < definitions.attributes.Length; a++)
        {
            EditorGUILayout.BeginHorizontal();

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
            {
                tmpAttr = new List <OSAttributeDefinition> (definitions.attributes);

                tmpAttr.RemoveAt(a);

                definitions.attributes = tmpAttr.ToArray();
                return;
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.BeginVertical();

            definitions.attributes[a].name   = EditorGUILayout.TextField("Name", definitions.attributes[a].name);
            definitions.attributes[a].suffix = EditorGUILayout.TextField("Suffix", definitions.attributes[a].suffix);

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
        {
            tmpAttr = new List <OSAttributeDefinition> (definitions.attributes);

            tmpAttr.Add(new OSAttributeDefinition());

            definitions.attributes = tmpAttr.ToArray();
        }
        GUI.backgroundColor = Color.white;

        EditorGUILayout.Space();

        // Ammunitions
        EditorGUILayout.LabelField("Ammunitions", EditorStyles.boldLabel);

        List <OSAmmunition> tmpAmmo;

        for (int a = 0; a < definitions.ammunitions.Length; a++)
        {
            EditorGUILayout.BeginHorizontal();

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
            {
                tmpAmmo = new List <OSAmmunition> (definitions.ammunitions);

                tmpAmmo.RemoveAt(a);

                definitions.ammunitions = tmpAmmo.ToArray();
                return;
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.BeginVertical();

            definitions.ammunitions[a].name       = EditorGUILayout.TextField("Name", definitions.ammunitions[a].name);
            definitions.ammunitions[a].projectile = (OSProjectile)EditorGUILayout.ObjectField("Projectile", definitions.ammunitions[a].projectile, typeof(OSProjectile), false);

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
        {
            tmpAmmo = new List <OSAmmunition> (definitions.ammunitions);

            tmpAmmo.Add(new OSAmmunition());

            definitions.ammunitions = tmpAmmo.ToArray();
        }
        GUI.backgroundColor = Color.white;

        // Currencies
        EditorGUILayout.LabelField("Currencies", EditorStyles.boldLabel);

        List <OSCurrency> tmpCurrency;

        for (int a = 0; a < definitions.currencies.Length; a++)
        {
            EditorGUILayout.BeginHorizontal();

            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
            {
                tmpCurrency = new List <OSCurrency> (definitions.currencies);

                tmpCurrency.RemoveAt(a);

                definitions.currencies = tmpCurrency.ToArray();
                return;
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.BeginVertical();

            definitions.currencies[a].name = EditorGUILayout.TextField("Name", definitions.currencies[a].name);

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
        {
            tmpCurrency = new List <OSCurrency> (definitions.currencies);

            tmpCurrency.Add(new OSCurrency());

            definitions.currencies = tmpCurrency.ToArray();
        }
        GUI.backgroundColor = Color.white;

        if (GUI.changed)
        {
            OSInventoryInspector.SavePrefab(target);
        }
    }
Beispiel #3
0
    public override void OnInspectorGUI()
    {
        OSItem item = (OSItem)target;

        // Meta
        EditorGUILayout.LabelField("Id", EditorStyles.boldLabel);
        item.id          = EditorGUILayout.TextField("Name", item.id);
        item.description = EditorGUILayout.TextField("Description", item.description);
        item.definitions = (OSDefinitions)EditorGUILayout.ObjectField("Definitions", item.definitions, typeof(OSDefinitions), false);

        if (!item.definitions)
        {
            GUI.color = Color.red;
            EditorGUILayout.LabelField("You need to link an OSDefinitions prefab with this item", EditorStyles.boldLabel);
            GUI.color = Color.white;
        }
        else
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Resource", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.TextField("Path", item.prefabPath);

            if (!item.gameObject.activeInHierarchy)
            {
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("Update", GUILayout.Width(60)))
                {
                    string path = AssetDatabase.GetAssetPath(item.gameObject);
                    if (path.Contains("Assets/Resources/"))
                    {
                        path = path.Replace("Assets/Resources/", "");
                        path = path.Replace(".prefab", "");

                        item.prefabPath = path;

                        resourceWarning = false;
                    }
                    else
                    {
                        resourceWarning = true;
                    }
                }
                GUI.backgroundColor = Color.white;
            }

            EditorGUILayout.EndHorizontal();

            if (resourceWarning)
            {
                item.prefabPath = "";
                GUI.color       = Color.red;
                EditorGUILayout.LabelField("Object not in /Resources folder!", EditorStyles.boldLabel);
                GUI.color = Color.white;
            }

            // Category
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Category", EditorStyles.boldLabel);

            item.catIndex = EditorGUILayout.Popup("Category", item.catIndex, item.definitions.GetCategoryStrings());

            if (item.subcatIndex >= item.definitions.categories [item.catIndex].subcategories.Length)
            {
                item.subcatIndex = 0;
            }

            item.subcatIndex = EditorGUILayout.Popup("Subcategory", item.subcatIndex, item.definitions.categories [item.catIndex].subcategories);

            // Slot
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Slot properties", EditorStyles.boldLabel);
            item.stackable = EditorGUILayout.Toggle("Stackable", item.stackable);
            item.canDrop   = EditorGUILayout.Toggle("Can drop", item.canDrop);

            item.slotSize.x = EditorGUILayout.IntField("Width", item.slotSize.x);
            item.slotSize.y = EditorGUILayout.IntField("Height", item.slotSize.y);

            if (item.slotSize.x < 1)
            {
                item.slotSize.x = 1;
            }
            if (item.slotSize.y < 1)
            {
                item.slotSize.y = 1;
            }

            // Attributes
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();

            for (int i = 0; i < item.attributes.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    List <OSAttribute> tmpAttr = new List <OSAttribute> (item.attributes);

                    tmpAttr.RemoveAt(i);

                    item.attributes = tmpAttr.ToArray();
                    return;
                }
                GUI.backgroundColor = Color.white;

                item.attributes[i].definitions = item.definitions;
                item.attributes[i].index       = EditorGUILayout.Popup(item.attributes[i].index, item.definitions.GetAttributeStrings());
                item.attributes[i].value       = EditorGUILayout.FloatField(item.attributes[i].value);
                EditorGUILayout.LabelField(item.attributes[i].suffix, GUILayout.Width(80));

                EditorGUILayout.EndHorizontal();
            }

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <OSAttribute> tmpAttr = new List <OSAttribute> (item.attributes);

                tmpAttr.Add(new OSAttribute(item.definitions));

                item.attributes = tmpAttr.ToArray();
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            // Sounds
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Sounds", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();

            for (int i = 0; i < item.sounds.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("x", GUILayout.Width(28), GUILayout.Height(14)))
                {
                    List <AudioClip> tmpSound = new List <AudioClip> (item.sounds);

                    tmpSound.RemoveAt(i);

                    item.sounds = tmpSound.ToArray();
                    return;
                }
                GUI.backgroundColor = Color.white;

                item.sounds[i] = (AudioClip)EditorGUILayout.ObjectField(item.sounds[i], typeof(AudioClip), false);

                EditorGUILayout.EndHorizontal();
            }

            GUI.backgroundColor = Color.green;
            if (GUILayout.Button("+", GUILayout.Width(28), GUILayout.Height(14)))
            {
                List <AudioClip> tmpSound = new List <AudioClip> (item.sounds);

                tmpSound.Add(null);

                item.sounds = tmpSound.ToArray();
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            // Ammunition
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Ammunition", EditorStyles.boldLabel, GUILayout.Width(80));
            item.ammunition.enabled = EditorGUILayout.Toggle(item.ammunition.enabled);
            EditorGUILayout.EndHorizontal();

            if (item.ammunition.enabled)
            {
                item.ammunition.index  = EditorGUILayout.Popup("Type", item.ammunition.index, item.definitions.GetAmmunitionStrings());
                item.ammunition.value  = EditorGUILayout.IntField("Amount", item.ammunition.value);
                item.ammunition.max    = EditorGUILayout.IntField("Maximum", item.ammunition.max);
                item.ammunition.spread = EditorGUILayout.IntField("Spread", item.ammunition.spread);
                item.ammunition.item   = item;
            }

            // Textures
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Textures", EditorStyles.boldLabel);

            item.thumbnail = (Texture2D)EditorGUILayout.ObjectField("Thumbnail", item.thumbnail as Object, typeof(Texture2D), false);
            item.preview   = (Texture2D)EditorGUILayout.ObjectField("Preview", item.preview as Object, typeof(Texture2D), false);

            if (GUI.changed)
            {
                OSInventoryInspector.SavePrefab(target);
            }
        }
    }