public override void ApplyData(string s) { if (usePlayerSpawnpoint && SaveSystem.playerSpawnpoint != null) { SetPosition(SaveSystem.playerSpawnpoint.transform.position, SaveSystem.playerSpawnpoint.transform.rotation); } else if (!string.IsNullOrEmpty(s)) { if (multiscene) { var currentScene = SceneManager.GetActiveScene().buildIndex; for (int i = 0; i < m_multisceneData.positions.Count; i++) { if (m_multisceneData.positions[i].scene == currentScene) { SetPosition(m_multisceneData.positions[i].position, m_multisceneData.positions[i].rotation); break; } } } else { var data = SaveSystem.Deserialize <PositionData>(s, m_data); if (data == null) { return; } m_data = data; SetPosition(data.position, data.rotation); } } }
public override void ApplyData(string s) { var data = SaveSystem.Deserialize <DestructibleData>(s, m_data); if (data == null) { return; } m_data = data; if (data.destroyed) { if (destroyedVersionPrefab != null) { Instantiate(destroyedVersionPrefab, data.position, transform.rotation); } switch (destroyMode) { case DestroyMode.Destroy: Destroy(gameObject); break; case DestroyMode.Deactivate: gameObject.SetActive(false); break; } } }
public override void ApplyData(string s) { if (gameObjectToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null) { return; } m_data = data; var applyDataToOtherSavers = data.active && !gameObjectToWatch.activeSelf; gameObjectToWatch.SetActive(data.active); if (applyDataToOtherSavers) { var savers = gameObjectToWatch.GetComponentsInChildren <Saver>(); for (int i = 0; i < savers.Length; i++) { var saver = savers[i]; if (saver == this || !saver.enabled) { continue; } saver.ApplyData(SaveSystem.currentSavedGameData.GetData(saver.key)); } } }
public override void ApplyData(string data) { if (string.IsNullOrEmpty(data)) { return; } var spawnedObjectDataList = SaveSystem.Deserialize <SpawnedObjectDataList>(data); if (spawnedObjectDataList == null || spawnedObjectDataList.list == null) { return; } m_spawnedObjects.Clear(); for (int i = 0; i < spawnedObjectDataList.list.Count; i++) { var spawnedObjectData = spawnedObjectDataList.list[i]; if (spawnedObjectData == null) { continue; } var prefab = GetSpawnedObjectPrefab(spawnedObjectData.prefabName); if (prefab == null) { continue; } Instantiate(prefab, spawnedObjectData.position, Quaternion.identity); } }
public override void ApplyData(string s) { if (gameObjectToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null) { return; } m_data = data; var applyDataToOtherSavers = data.active && !gameObjectToWatch.activeSelf; if (!data.active) { gameObjectToWatch.BroadcastMessage("OnBeforeSceneChange", SendMessageOptions.DontRequireReceiver); gameObjectToWatch.BroadcastMessage("OnLevelWillBeUnloaded", SendMessageOptions.DontRequireReceiver); } gameObjectToWatch.SetActive(data.active); if (applyDataToOtherSavers) { var savers = gameObjectToWatch.GetComponentsInChildren <Saver>(); for (int i = 0; i < savers.Length; i++) { var saver = savers[i]; if (saver == this || !saver.enabled) { continue; } saver.ApplyData(SaveSystem.currentSavedGameData.GetData(saver.key)); } } }
public override SavedGameData RetrieveSavedGameData(int slotNumber) { if (debug && HasDataInSlot(slotNumber)) { Debug.Log("Save System: Retrieved from PlayerPrefs key " + GetPlayerPrefsKey(slotNumber) + ": " + PlayerPrefs.GetString(GetPlayerPrefsKey(slotNumber))); } return(HasDataInSlot(slotNumber) ? SaveSystem.Deserialize <SavedGameData>(PlayerPrefs.GetString(GetPlayerPrefsKey(slotNumber))) : new SavedGameData()); }
public override void ApplyData(string s) { if (string.IsNullOrEmpty(s) || animator == null) { return; } SaveSystem.Deserialize <Data>(s, m_data); if (m_data == null) { m_data = new Data(); } else if (m_data.layers != null) { // Apply layer states: for (int i = 0; i < animator.layerCount; i++) { if (i < m_data.layers.Length) { animator.Play(m_data.layers[i].hash, i, m_data.layers[i].time); } } // Apply parameter values: int numBools = 0; int numFloats = 0; int numInts = 0; for (int i = 0; i < animator.parameterCount; i++) { var parameter = animator.parameters[i]; switch (parameter.type) { case AnimatorControllerParameterType.Bool: if (numBools < m_data.bools.Count) { animator.SetBool(parameter.name, m_data.bools[numBools++]); } break; case AnimatorControllerParameterType.Float: if (numFloats < m_data.floats.Count) { animator.SetFloat(parameter.name, m_data.floats[numFloats++]); } break; case AnimatorControllerParameterType.Int: if (numInts < m_data.ints.Count) { animator.SetInteger(parameter.name, m_data.ints[numInts++]); } break; } } } }
// ApplyData() is called when loading. It receives a string representation of the // save data and applies it to the tilemap. public override void ApplyData(string s) { if (string.IsNullOrEmpty(s)) { return; } TilemapSerializedData data = SaveSystem.Deserialize <TilemapSerializedData>(s); if (data != null) { DeserializeTilemap(data, GetComponent <STETilemap>()); } }
public override void ApplyData(string s) { if (gameObjectsToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null || data.active == null) { return; } m_data = data; // First issue OnBeforeSceneChange/OnLevelWillBeUnloaded in case targets include nested GOs: for (int i = 0; i < Mathf.Min(data.active.Length, gameObjectsToWatch.Length); i++) { if (gameObjectsToWatch[i] == null) { continue; } if (!data.active[i]) { gameObjectsToWatch[i].BroadcastMessage("OnBeforeSceneChange", SendMessageOptions.DontRequireReceiver); gameObjectsToWatch[i].BroadcastMessage("OnLevelWillBeUnloaded", SendMessageOptions.DontRequireReceiver); } } // Then activate/deactivate: for (int i = 0; i < Mathf.Min(data.active.Length, gameObjectsToWatch.Length); i++) { if (gameObjectsToWatch[i] == null) { continue; } var applyDataToOtherSavers = data.active[i] && !gameObjectsToWatch[i].activeSelf; gameObjectsToWatch[i].SetActive(data.active[i]); if (applyDataToOtherSavers) { var savers = gameObjectsToWatch[i].GetComponentsInChildren <Saver>(); for (int j = 0; j < savers.Length; j++) { var saver = savers[j]; if (saver == this || !saver.enabled) { continue; } saver.ApplyData(SaveSystem.currentSavedGameData.GetData(saver.key)); } } } }
public override SavedGameData RetrieveSavedGameData(int slotNumber) { var s = ReadStringFromFile(GetSaveGameFilename(slotNumber)); if (encrypt) { string plainText; s = EncryptionUtility.TryDecrypt(s, encryptionPassword, out plainText) ? plainText : string.Empty; } if (debug) { Debug.Log("Save System: DiskSavedGameDataStorer - Loading " + GetSaveGameFilename(slotNumber) + ": " + s); } return(SaveSystem.Deserialize <SavedGameData>(s)); }
public override void ApplyData(string s) { if (gameObjectToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null) { return; } m_data = data; gameObjectToWatch.SetActive(data.active); }
public override void ApplyData(string data) { if (string.IsNullOrEmpty(data)) { return; } var positionData = SaveSystem.Deserialize <PositionData>(data); if (positionData == null) { return; } transform.position = positionData.position; transform.rotation = positionData.rotation; }
public override void ApplyData(string s) { if (componentToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null) { return; } m_data = data; ComponentUtility.SetComponentEnabled(componentToWatch, data.enabled); }
public override SavedGameData RetrieveSavedGameData(int slotNumber) { if (debug && HasDataInSlot(slotNumber)) { Debug.Log("Save System: Retrieved from PlayerPrefs key " + GetPlayerPrefsKey(slotNumber) + ": " + PlayerPrefs.GetString(GetPlayerPrefsKey(slotNumber))); } var s = PlayerPrefs.GetString(GetPlayerPrefsKey(slotNumber)); if (encrypt) { string plainText; s = EncryptionUtility.TryDecrypt(s, encryptionPassword, out plainText) ? plainText : string.Empty; } return(HasDataInSlot(slotNumber) ? SaveSystem.Deserialize <SavedGameData>(s) : new SavedGameData()); }
public override void ApplyData(string data) { var destructibleData = SaveSystem.Deserialize <DestructibleData>(data); if (destructibleData == null) { return; } m_data = destructibleData; if (destructibleData.destroyed) { if (destroyedVersionPrefab != null) { Instantiate(destroyedVersionPrefab, destructibleData.position, transform.rotation); } Destroy(gameObject); } }
public override void ApplyData(string s) { if (usePlayerSpawnpoint && SaveSystem.playerSpawnpoint != null) { transform.position = SaveSystem.playerSpawnpoint.transform.position; transform.rotation = SaveSystem.playerSpawnpoint.transform.rotation; } else if (!string.IsNullOrEmpty(s)) { var data = SaveSystem.Deserialize <PositionData>(s, m_data); if (data == null) { return; } m_data = data; transform.position = data.position; transform.rotation = data.rotation; } }
public override void ApplyData(string s) { if (string.IsNullOrEmpty(s) || animator == null) { return; } SaveSystem.Deserialize <Data>(s, m_data); if (m_data == null) { m_data = new Data(); } else if (m_data.layers != null) { for (int i = 0; i < animator.layerCount; i++) { if (i < m_data.layers.Length) { animator.Play(m_data.layers[i].hash, 0, m_data.layers[i].time); } } } }
public override void ApplyData(string s) { if (componentsToWatch == null || string.IsNullOrEmpty(s)) { return; } var data = SaveSystem.Deserialize <Data>(s, m_data); if (data == null || data.active == null) { return; } m_data = data; for (int i = 0; i < Mathf.Min(data.active.Length, componentsToWatch.Length); i++) { if (componentsToWatch[i] == null) { continue; } ComponentUtility.SetComponentEnabled(componentsToWatch[i], data.active[i]); } }
public override void ApplyData(string data) { if (string.IsNullOrEmpty(data)) { return; } var spawnedObjectDataList = SaveSystem.Deserialize <SpawnedObjectDataList>(data); if (spawnedObjectDataList == null || spawnedObjectDataList.list == null) { return; } m_spawnedObjects.Clear(); for (int i = 0; i < spawnedObjectDataList.list.Count; i++) { var spawnedObjectData = spawnedObjectDataList.list[i]; if (spawnedObjectData == null) { continue; } var prefab = GetSpawnedObjectPrefab(spawnedObjectData.prefabName); if (prefab == null) { continue; } Instantiate(prefab, spawnedObjectData.position, spawnedObjectData.rotation); } if (m_applySaveDataToSpawnedObjectsOnRestore) { if (SaveSystem.framesToWaitBeforeApplyData == 0) { ApplyDataToRespawnedObjects(); } else { StartCoroutine(ApplyDataToRespawnedObjectsAfterFrames(SaveSystem.framesToWaitBeforeApplyData)); } } }