public static void InitializeFromDefault(ShonkyInventory shonkyInventory) { if (_instance) { DestroyImmediate(_instance); } _instance = Instantiate(shonkyInventory); _instance.hideFlags = HideFlags.HideAndDontSave; }
public static void LoadFromJSON(string path) { if (!_instance) { DestroyImmediate(_instance); } _instance = ScriptableObject.CreateInstance <ShonkyInventory>(); JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText(path), _instance); _instance.hideFlags = HideFlags.HideAndDontSave; }
public static void LoadOrInitializeShonkyInventory(ShonkyInventory shonkyInventoryTemplate) { // Saving and loading. if (File.Exists(Path.Combine(Application.persistentDataPath, "shonkyinventory.json"))) { Debug.Log("Found file shonkyinventory.json, loading shonky inventory."); ShonkyInventory.LoadFromJSON(Path.Combine(Application.persistentDataPath, "shonkyinventory.json")); } else { Debug.Log("Couldn't find shonkyinventory.json, loading from template."); ShonkyInventory.InitializeFromDefault(shonkyInventoryTemplate); } }
// Load from default. public static void LoadFromShonkyTemplate(ShonkyInventory template) { ShonkyInventory.InitializeFromDefault(template); }