I seem to come across various answers about not been able to do this without some serious work-arounds but all the posts I came across weren’t exactly for the same reasons I’m looking for.
I have a class to hold info on a slot in a container.
[System.Serializable]
public class ContainerSlot
{
public ItemObject item; //SO item
public int amount; //Says it all
public ContainerBase parent; //Parent container
public int inventoryIndex; //Current inventory Index
public ContainerStorage container; //Optional container contents class
public ContainerSlot(ItemObject _item, int _amount, int _index)
{
item = _item;
amount = _amount;
inventoryIndex = _index;
}
public void AddAmount(int _value)
{
amount += _value;
}
public void RemoveAmount(int _value)
{
amount -= _value;
}
}
I’m trying to figure out a way to get the inspector window to only show the “container” field if the “item” field fits a certain rule (the SO item can fit into a certain catagory. I.E item.type == itemType.Storage)
Now from here you have 2 approaches. There is the legacy approach of using the ‘OnGUI’ or the newer approach of ‘CreatePropertyGUI’. Check out the documentation for both:
But effectively in your approach you pick you’ll only draw the elements that meet your conditions. You’re going to read the item field and if it meets your conditions draw the container field.
Note you should probably be checking the SerializedProperty’s SerializedObject field to see if it is drawing multiple objects or not. Since if it is, then there are technically multiple 'item’s. And you may want to behave differently (as in, don’t draw at all).
Now I just have to get rid of my stacking serielized fields past 10 since I seem to be self referencing slot in container over and over. Ah the love of creating problems for ourselves