예제 #1
0
    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);
        }
    }
예제 #2
0
    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.");
            }
        }
    }
예제 #3
0
    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($"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
                }
            }
        }
    }
예제 #4
0
 public void SetSaveablePrefabInstanceManager(SaveablePrefabInstanceManager reference, Saveable saveable, SaveablePrefab saveablePrefab)
 {
     prefabInstanceManager = reference;
     this.saveable         = saveable;
     this.saveablePrefab   = saveablePrefab;
 }