I’m completely lost at how to make a custom inspector for a completely custom object type. What I’m trying to do is create an array of Stacks of Items; the Item class is a regular class with attributes like price, name, and description. I want them in a stack because the player will have several of the same Item and I want them to be group together. The array is simply the list of all the different items a player could find - it’s intended to be a set number in the game. In code, this would be
Stack<Item>[] item = new Stack<Item>[number of items]
I want to configure this list of items in the inspector, and since Stack isn’t a normal type, my next course of action is to make a custom inspector.
I’m really struggling with this custom inspector because I can’t get the inspector to show up or recognize Stack objects. Judging from the lack of extensive documentation on the site, forums and UnityAnswers, it seems that everyone “gets it” but me.
How do I make the Editor-extended class I have work with Stack objects? Stack inherits from IEnumerable, ICollection, and IEnumerable (read: not Object), so if Unity can’t reference it, should I use a wrapper class?
What exactly is the procedure for getting a custom Inspector to show up in the Inspector area?
You can only implement a custom inspector for specific MonoBehaviours. When creating an Editor class you specify which particular behaviour the editor is linked to using the CustomEditor attribute:
[CustomEditor(typeof(MyScript))]
public class MyScriptInspector : Editor
{...}
From that point on, the MyScriptInspector takes over the work from default inspector for MyScript objects. In other words, for you Stack to show up, you will need to write an inspector for the MonoBehaviour containing the stack.
I realize that you probably want to achieve something different, namely having your Stack recognized by the inspector for any script that happens to contain such a stack. As far as I know, that cannot be done through editor scripting.
Dang, that is what I wanted. See, the point of all this was to create new Stacks in an Inspector, and then save it in a prefab or GameObject. Essentially, I want want a handy way to store special data without getting it changed (meaning no XML).