public void AddListener(Saveable instance, SaveablePrefab scriptablePrefab, string identification) { SaveablePrefabData prefabData; // Is there no data yet for this scriptable prefab? Create it. if (!saveReferences.TryGetValue(scriptablePrefab, out prefabData)) { prefabData = new SaveablePrefabData(); prefabData.prefabGUID = scriptablePrefab.GetGuid(); prefabData.trimmedguid = $"{this.gameObject.scene.name}{prefabData.prefabGUID.Substring(0, 4)}"; saveReferences.Add(scriptablePrefab, prefabData); } // Add identification keys for each saveable object. if (!prefabData.saveableGUIDS.ContainsKey(instance)) { string saveableGUID = (string.IsNullOrEmpty(identification) ? $"I{prefabData.trimmedguid}{prefabData.saveableGUIDS.Count}" : identification); instance.saveIdentification.UseConstant = true; instance.saveIdentification.ConstantValue = saveableGUID; isSaveable = true; prefabData.saveableGUIDS.Add(instance, saveableGUID); } }
public void RemoveListener(Saveable instance, SaveablePrefab scriptablePrefab) { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif // We only remove the saved state of a prefab when it is destroyed by code. // Not while the scene is being destroyed or when the game is quitting. if (destroyingScene || quittingGame) { return; } SaveablePrefabData data; if (saveReferences.TryGetValue(scriptablePrefab, out data)) { instance.RemoveFromSaveData(); if (data.saveableGUIDS.Remove(instance)) { isSaveable = true; } else { Debug.Log("Tried to remove listener that was never added."); } } }
public void OnLoad(string data) { if (string.IsNullOrEmpty(data)) { return; } currentSaveGame = SaveUtility.LoadSave(currentSaveSlot.Value); if (currentSaveGame == null) { Debug.Log("Could not find current save"); return; } SaveData saveData = JsonUtility.FromJson <SaveData>(data); if (saveData.data != null && saveData.data.Count > 0) { for (int i = 0; i < saveData.data.Count; i++) { SaveablePrefab saveablePrefab = ScriptableAssetDatabase.GetAsset(saveData.data[i].prefabGUID) as SaveablePrefab; if (saveablePrefab == null) { //Debug.Log(saveData.data[i]); Debug.Log($"Could not find reference in ScriptableAssetDatabase for Saveable Prefab : {saveData.data[i].prefabGUID}"); continue; } for (int i2 = 0; i2 < saveData.data[i].saveableGUIDs.Count; i2++) { Saveable getSaveable = saveablePrefab.Retrieve <Saveable>(saveData.data[i].saveableGUIDs[i2]); getSaveable.OnLoadRequest(currentSaveGame); #if UNITY_EDITOR getSaveable.transform.SetParent(this.transform, true); #endif } } } }
public void SetSaveablePrefabInstanceManager(SaveablePrefabInstanceManager reference, Saveable saveable, SaveablePrefab saveablePrefab) { prefabInstanceManager = reference; this.saveable = saveable; this.saveablePrefab = saveablePrefab; }