Example #1
0
    private void AddItemGUI()
    {
        EditorGUI.indentLevel = 1;

        EditorGUILayout.LabelField("Add Item", EditorStyles.boldLabel);

        EditorGUI.indentLevel = 2;

        var name   = EditorGUILayout.TextField("Name:", addItem.name);
        var icon   = EditorGUILayout.TextField("Icon:", addItem.icon);
        var sprite = EditorGUILayout.TextField("Sprite:", addItem.sprite);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        if (GUILayout.Button("Add Item"))
        {
            ResourcesLoader.SaveObject("Assets/Resources/Entities/Items/", addItem.name, addItem);
            ItemEntities.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel = 1;

        if (GUI.changed)
        {
            addItem.name   = name;
            addItem.icon   = icon;
            addItem.sprite = sprite;
        }
    }
Example #2
0
    private void EditItemGUI()
    {
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField("Edit Item", EditorStyles.boldLabel);
        EditorGUI.indentLevel = 2;
        string[] values       = ItemEntities.items.Values.Select(x => x.Name).ToArray <string>();
        int      index        = values.ToList().IndexOf(editItem.Name);
        int      currentIndex = EditorGUILayout.Popup("Select Item", index, values);
        var      icon         = EditorGUILayout.TextField("Icon:", editItem.icon);
        var      sprite       = EditorGUILayout.TextField("Sprite:", editItem.sprite);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        if (GUILayout.Button("Edit Item"))
        {
            ResourcesLoader.SaveObject("Assets/Resources/Entities/Items/", editItem.name, editItem);
            ItemEntities.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel = 1;

        if (GUI.changed)
        {
            string nName = values[currentIndex];
            if (nName != editItem.Name)
            {
                editItem = ItemEntities.items[nName];
            }
            else
            {
                editItem.icon   = icon;
                editItem.sprite = sprite;
            }
        }
    }
Example #3
0
 public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Update Item Entities"))
     {
         ItemEntities.Update();
     }
     AddItemGUI();
     EditItemGUI();
 }