Game Development Reference
In-Depth Information
Saving and managing asset data
To achieve this, we simply need to create a script (named ScriptingObjects ) with
some properties we want to serialize; then, we change its class inheritance from
MonoBehaviour to ScriptableObject as follows:
using UnityEngine;
public class ScriptingObjects : ScriptableObject {
public Vector2[] MyPositions;
}
Great! So we have some serializable data. However, to use it in the editor, we need to cre-
ate an option in the editor to create and save these assets for us. Create a new script named
PositionManager in the Editor under Assets\Scripts and replace its contents
with the following code:
using UnityEngine;
using UnityEditor;
public class PositionManager : MonoBehaviour
{
//Define a menu option in the editor to create the new
asset
[MenuItem("Assets/Create/PositionManager")]
public static void CreateAsset()
{
//Create a new instance of our scriptable object
ScriptingObjects positionManager =
ScriptableObject.CreateInstance<ScriptingObjects>();
//Create a .asset file for our new object and save it
AssetDatabase.CreateAsset(positionManager, "Assets/
newPositionManager.asset");
AssetDatabase.SaveAssets();
//Now switch the inspector to our new object
Search WWH ::




Custom Search