Pretty straightforward question: is there a way to create an inspector field for either a Scene asset or an array of Scene assets?
I'm trying to create a custom editor window that allows our designers to easily modify our level packs and the levels in them. It would be ideal if, rather than having to add scenes manually to the Build Settings list, I could provide an inspector field to slot in a Scene (.unity3d) asset. This way, I could throw warnings when a level isn't assigned a scene file, and ensure that all the scenes needed for the game are included when we do a build.
So far, this seems much harder than necessary because I can't find an appropriate asset type that corresponds to the scene asset type.
asked Apr 20 '12 at 11:33 PM
Found a workable solution through experimentation, thought I would share:
There is no class exposed in Unity's API to create an inspector reference to a Scene, but it turns out that a Scene does inherit from Object, so it is possible to have an Object reference and then slot in a Scene asset:
The only problem with this solution is that you can't really enforce that the list contain only Scene objects at compile time; there is nothing stopping someone on the team from inserting a reference to some other asset entirely. Still, it is better than nothing, and you can do some runtime checks to make sure it works.
With the scene asset reference, you can use the AssetDatabase object to get path information, and manually add the scene data to the build settings list of scenes.
I'm assuming you could make a script or such and have a public variable so it can be assigned in the editor window. I am unsure ifna similar thing applies to asset packages.
answered Apr 20 '12 at 11:39 PM