Esempio n. 1
0
        private void WriteSaveToFile()
        {
            TimeSpan currentTimePlayed = DateTime.Now - cachedSaveData.saveDate;
            TimeSpan allTimePlayed     = cachedSaveData.timePlayed;

            cachedSaveData.timePlayed = allTimePlayed + currentTimePlayed;

            SaveUtility.WriteSave(cachedSaveData, saveSlot.Value);
        }
Esempio n. 2
0
        private void Start()
        {
            cachedSaveData = SaveUtility.LoadSave(saveSlot.Value);
            if (cachedSaveData == null)
            {
                Debug.Log("cachedSaveData == null");
                CreateNewSave();
            }

            onGameLoad?.Invoke(cachedSaveData);
        }
Esempio n. 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(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
                    }
                }
            }
        }
Esempio n. 4
0
        public static SaveGame LoadSave(int slot)
        {
#if UNITY_WEBGL && !UNITY_EDITOR
            SyncFiles();
#endif

            Log($"Attempting to load game at slot: {slot}");

            SaveGame getSave;

            if (SaveUtility.ObtainAllSaveGames().TryGetValue(slot, out getSave))
            {
                Log($"Succesful load at slot: {slot}");
                return(getSave);
            }
            else
            {
                Log($"Could not load game at slot {slot}");
                return(null);
            }
        }
Esempio n. 5
0
 public void Initialize()
 {
     cachedSaveData = SaveUtility.LoadSave(saveSlot.Value);
 }
Esempio n. 6
0
 public void OnLoadSystem()
 {
     cachedSaveData = SaveUtility.LoadSave(saveSlot.Value);
 }