Jan 6, 2016

Posted by in Game Development | 0 Comments

Breaking News: Scriptable Objects and Editors

CommodityEditorSo this happened.

After my previous post went live, I looked up my current data structure for Commodity Items in my “good” version of Project Universe and created an analogue and a Scriptable Object database to hold them in a new test project. I then crawled through the EditorGUI documentation, ingested the examples on how to use the Scriptable Object database paradigm, and crafted this not-so-sexy looking editor panel you see on the left.

Funny thing: it works! You can pop up the panel by selecting the Data Tools > Commodity Items from the Unity menu. Clicking the New Commodity Item button at the top defaults some values in the editor form at the bottom of the panel. The developer can edit those values, and the click Save to have the new item added to the database (and immediately listed in the grid). If the dev needs to modify an existing record, he can click Edit and the data is transferred to the edit form. If the entry is no longer needed, clicking the Del button will remove the item from the database (leaving an ID “hole” in the sequence, but I digress). The “database” is stored as “commodityItemBaseDB.asset” in the project folder. Even the ENUM selection works!

I’m kind of shocked at how easy this was. I mean, the panel looks like utter ass, but everything is functional. Clicking on the .asset file, I can see the item entries in the inspector on the sidebar (which I could also edit, but why?!)

So…dayum. Now I just need to make the panel look better, and then set up a framework for loading the database for actual use. One thing I noticed that I have to look into: once the asset has been loaded, using EditorUtility.SetDirty() marks the Scriptable Object for auto-updating on disk. There doesn’t seem to a specific “Save” function aside from when I use SaveAssets() when creating the original file, and more importantly, it looks like the asset is memory-resident for good. I don’t see a Close() or Unload() function of AssetDatabase. I’m always concerned when loading materials from disk, so that I don’t keep them lying around open any longer than necessary.

 

Leave a Reply

What do you think?