Create a. asset file from Class X that inherits from Scriptableobject.
Suppose class X is defined as:
[System.serializable]
public class X:scriptableobject {
public float m_a;
}
Method One: Write code creation.
#if Unity_editor
String path = "Assets/resources/x.asset";
X scriptableobj = scriptableobject.createinstance<x> ();
UnityEditor.AssetDatabase.CreateAsset (scriptableobj, path);
UnityEditor.AssetDatabase.SaveAssets ();
UnityEditor.AssetDatabase.Refresh ();
#endif
(add: For X.asset created above, the loading notation is:
If loading with assetdatabase:
#if Unity_editor
UnityEditor.AssetDatabase.LoadAssetAtPath ("Assets/resources/x.asset");
#endif
If loading with resource.load:
Resources.load ("X");
)
Method Two: Created through the menu.
Adding the Createassetmenu property before class X automatically adds the corresponding menu item to the System create menu.
[Createassetmenu (filename= "x", Menuname= "(custom) x")]
[System.serializable]
public class X:scriptableobject {
public float m_a;
}
Reference:
http://baba-s.hatenablog.com/entry/2015/06/13/000000
Http://answers.unity3d.com/questions/1079664/how-do-i-use-the-createassetmenu-attribute.html
Unity, created by Scriptableobject. Asset