- Home /
Show and Edit Attributes of my list of structs in EditorWindow.
Hello all, What I'm trying to do today is make my own editor window where i can add and remove a custom class from a list.
here is my custom ItemClass:
using UnityEngine;
using System.Collections;
using System;
[System.Serializable]
public class ItemClass{
public bool expanded;
public string ItemName = "Name Me!";
public string Description = "Write Description.";
public Texture2D Icon;
public int Duribility = 100;
public int Damage = 10;
public int Armor = 10;
public int Id = 0;
public bool equipped;
public Item itemtype;
public Value value;
// Use this for initialization
void ApplyStats () {
if(equipped == true) {
}
else {
}
}
}
public enum Item {
Weapon,
Helmet,
Shoulders,
Chest,
Pants,
Boots,
Gloves,
Item
}
public enum Value {
Junk,
Uncommon,
Common,
Rare,
Epic
}
And my Editor Code:
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
[Serializable]
public class ItemManager : EditorWindow {
[SerializeField]
private List<ItemClass> mast_items = new List<ItemClass>();
// Add menu named "My Window" to the Window menu
[MenuItem ("Window/Item Manager")]
static void Init () {
// Get existing open window or if none, make a new one:
ItemManager window = (ItemManager)EditorWindow.GetWindow (typeof (ItemManager));
}
void OnGUI () {
GUILayout.Label ("Item Master List:", EditorStyles.boldLabel);
for (int i = 0; i < mast_items.Count; i++)
{
mast_items[i].expanded = EditorGUILayout.Foldout(mast_items[i].expanded, mast_items[i].ItemName);
}
if (GUILayout.Button ("Add Base"))
mast_items.Add (new ItemClass());
}
}
Comment
You ask no question here. You need to explain what should happen if it works, and what is going wrong.
I appologize. What i want to happen is for it to show each attribute of the item in the list like it does in the inspector. Normally a name drop down with the varibles underneith.