So i used a tutorial on how to create a custom inspector because i’m making a farm game and i wanted to make an easier way to create orders for an order board so i have it to where when i press a button on the inspector it adds a Element to a list and under the Elements are multiple variables
public class OrderAction : MonoBehaviour {
//MyClass myclass;
materialss material;
public List<materialss> materials = new List<materialss>();
[System.Serializable]
public class materialss
{
public string MaterialName = string.Empty;
public int amountNeeded;
public Image materialImage;
public Text amountNeededT;
public void Update()
{
Debug.Log("Done");
materialImage.sprite = Resources.Load(MaterialName) as Sprite;
}
}
}
This is the script for controlling the orders
[CustomEditor(typeof(OrderAction))]
public class OrderEditor : Editor
{
OrderAction t;
SerializedObject GetTarget;
SerializedProperty thisList;
void OnEnable()
{
t = (OrderAction)target;
GetTarget = new SerializedObject(t);
thisList = GetTarget.FindProperty("materials");
}
public override void OnInspectorGUI()
{
OrderAction myOrderAction = (OrderAction)target;
GetTarget.Update();
//myOrderAction.experience = EditorGUILayout.IntField("Experience", myOrderAction.experience);
GUILayout.Label("List of materials");
GUILayout.Space(20);
if (GUILayout.Button("Add Material"))
{
t.materials.Add(new OrderAction.materialss());
Debug.Log("Added");
}
base.OnInspectorGUI();
}
public void addMaterial()
{
OrderAction myOrderAction = (OrderAction)target;
myOrderAction.materials.Add(new OrderAction.materialss());
Debug.Log("Added");
}
}
This is the script that edits the inspector
Now the problem is in the OrderAction script i have a subclass called materialss. When the button is pressed it creates a new element using the variables in the subclass and it creates the new elements fine but i cant seem to be able to edit them. for example I have the Update function and im trying to get the image for the material to change to a sprite according to the name and it doesn’t work. i put a Debug.Log in and it doesn’t even call that. So how would i be able to edit the variables or can i?