private static void OnLoad() { if (!data) { data = CreateInstance <CustomMenuData>(); AssetDatabase.CreateAsset(data, "Assets/CustomMenuData.asset"); AssetDatabase.Refresh(); } }
private static void OnLoad() { // if no data exists yet create and reference a new instance if (!data) { data = CreateInstance <CustomMenuData>(); AssetDatabase.CreateAsset(data, "Assets/CustomMenuData.asset"); AssetDatabase.Refresh(); } }
private static void OnLoad() { // if data is null create and reference a new ScriptableObject instance if (!data) { // create new instance data = ScriptableObject.CreateInstance <CustomMenuData>(); // store it as an asset AssetDatabase.CreateAsset(data, FilePath); AssetDatabase.Refresh(); } }
private static void OnLoad() { // if no data exists yet create and reference a new instance if (!data) { // as first option check if maybe there is an instance already // and only the reference got lost // won't work ofcourse if you moved it elsewhere ... data = AssetDatabase.LoadAssetAtPath <CustomMenuData>("Assets/CustomMenuData.asset"); // if that was successful we are done if (data) { return; } // otherwise create and reference a new instance data = CreateInstance <CustomMenuData>(); AssetDatabase.CreateAsset(data, "Assets/CustomMenuData.asset"); AssetDatabase.Refresh(); } }