void OnEnable() { if (EditorPrefs.HasKey("ObjectPath")) { string objectPath = EditorPrefs.GetString("ObjectPath"); spellSOList = AssetDatabase.LoadAssetAtPath(objectPath, typeof(SpellSOList)) as SpellSOList; } }
void CreateNewItemList() { // There is no overwrite protection here! // There is No "Are you sure you want to overwrite your existing object?" if it exists. // This should probably get a string from the user to create a new name and pass it ... viewIndex = 1; spellSOList = CreateSOList.Create(); if (spellSOList) { spellSOList.spellCheckmarks = new List <SpellSO>(); string relPath = AssetDatabase.GetAssetPath(spellSOList); EditorPrefs.SetString("ObjectPath", relPath); } }
void OpenItemList() { string absPath = EditorUtility.OpenFilePanel("Select Spell SO List", "", ""); if (absPath.StartsWith(Application.dataPath)) { string relPath = absPath.Substring(Application.dataPath.Length - "Assets".Length); spellSOList = AssetDatabase.LoadAssetAtPath(relPath, typeof(SpellSOList)) as SpellSOList; if (spellSOList.spellCheckmarks == null) { spellSOList.spellCheckmarks = new List <SpellSO>(); } if (spellSOList) { EditorPrefs.SetString("ObjectPath", relPath); } } }
public static SpellSOList Create() { SpellSOList asset = ScriptableObject.CreateInstance <SpellSOList>(); Object[] allDictionary = Resources.LoadAll("ScriptObjects/Dictionary", typeof(SpellSOList)); counter = allDictionary.Length + 1; if (counter == 1) { AssetDatabase.CreateAsset(asset, "Assets/Resources/ScriptObjects/Dictionary/SpellSOList.asset"); } else { AssetDatabase.CreateAsset(asset, "Assets/Resources/ScriptObjects/Dictionary/SpellSOList" + counter + ".asset"); } counter++; AssetDatabase.SaveAssets(); return(asset); }