I’m trying to create a custom editor window which will allow us to add and remove weapons. It would effectively be just a fixed length array consisting of weapon value objects.
It seems that when I subclass EditorWindow, I can’t access any of my other scripts (for example, my Scripts/WeaponVO.cs class.) Is there no way to reference classes defined in the Scripts folder of a project? Is what I am trying to do even possible or will I need to create a MonoBehaviour manager class instead?
1 Answer
1
I believe that if you create an editor window, it needs a GameObject, whether it is a scene object or a prefab, for you to modify it or make changes. The problem with accessing/changing a script is that a script is just a template for some functionality and data - there is no actual “instance” of an object for you to edit.
The only way an editor window could modify a script is if it were changing the text in the script (not likely) or if you wanted to change some property of the MonoScript asset (see the docs for more info on MonoScript - it is basically just the code text asset).
You may have a unique situation, but usually when you create an editor window, it is because you want to create a “clean” interface for modifying a prefab with a lot of complex data. What I usually do is create a prefab with the script attached, then have my EditorWindow modify the prefab by grabbing it with AssetDatabase.LoadAssetAtPath(“Assets/Managers/…”).
Then, during gameplay, I can either instantiate that prefab, or load it from Resources and make use of whatever data I’ve put in there using the EditorWindow.
In your case, I’d probably create a WeaponsManager prefab or and have the EditorWindow modify that. If it really is just an array that you are modifying values for, you may find it more time efficient to just change the code file?