Is it possible to create an editor window that has some persistent settings that can then be used to create a new asset or modify an existing one?
My use case is that I am autogenerating some items in my RPG and previously I was doing this externally in a little c# console app that created a csv file and then I was using an editor menu script to read the csv and create and modify a List<> of item definitions on the selected unity object (containing the appropriate script). I’d rather make the items within unity as part of of an editor window and have some settings that I can modify that change the way in which the items are created. I then want that item setting data to persist between sessions.
I’m also toying with the EditorWindow creating a custom asset - maybe some XML - that I could then load at runtime.
I’ve been trying to use ScriptableObjects for my item generated data but I can’t get the UI to autogenerate for these scripts, I also don’t know whether they will persist (but I could probably write some XML out and read it back in). The added complexity here is that I need an array of objects, each object containing parameters for a set of objects I want to generate at the push of a button!
Presumably this kind of scenario can easily be solved and has to be solved for many extensions to the editor?
Create a class subclassing SciptableObject for the editor data
Create an EditorWindow subclassing EditorWindow
In the static Init() method to Get/Create the window I checked for the existence of my EditorData and load if present or create if not
Used EditorGUI.Popups to display the elements I could edit from the various Lists<> within my EditorData
Displayed GUI below each Popup for the content of the selected item in the popup
Continued with more EditorGUI.Popups and GUI below for detail (master/detail really)
Buttons to add/edit/rename bits of EditorData
A button to create the in-game asset, also a subclassed ScriptableObject
The above took me the best part of a day and I ended up with the image posted at the end.
However, I found this very painful to make, taking a day, and having worked with ScriptableObject subclasses I then elected to do the following:
For the same EditorData subclass of ScriptableObject, I created an Editor subclass
In OnInspectorGUI() I called the base method…
…I then added GUI for a button to generate the in-game data
I Added a menu item to create the EditorData
I deleted the original editor
This gives me List<> editing just as I would get for any serialisable object as a public member of a script attached to a GameObject within Unity. It is perhaps not as elegant as the master detail scenario, but it took me about an hour or so to get it working and I wasn’t somewhat confused about how to style things.
I think for more advanced editing, that the EditorWindow might have some benefit, but the Editor solution is quicker to code and provides a very usable view of the data.
I hope this information helps someone else who wishes to have EditorData and generate real game data from that.