diff --git a/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab b/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab new file mode 100644 index 0000000000000000000000000000000000000000..adc28f8a7d7d4ce7eb5655070ba33df02b43b5ea --- /dev/null +++ b/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2379307448264636869 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5034770101523303488} + - component: {fileID: 7310441132621849856} + m_Layer: 0 + m_Name: DataPersistenceManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5034770101523303488 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2379307448264636869} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.5124696, y: 1.9276284, z: 0.27401495} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &7310441132621849856 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2379307448264636869} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ff080c65d846fce40916179a81d1a151, type: 3} + m_Name: + m_EditorClassIdentifier: + fileName: data.game diff --git a/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab.meta b/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..9e75afa9c3d19949d40a521ada121f6f79ca4042 --- /dev/null +++ b/Assets/Prefabs/SaveLoad/DataPersistenceManager.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 607ac10d4a28a814ea8aea94b0d7c524 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Level01.unity b/Assets/Scenes/Level01.unity index 5dfa2ce81dbe3904a782adf6e23be11e11245230..d5d075b0a76bff444d0f3dd5c6f6fa0dce4159bd 100644 --- a/Assets/Scenes/Level01.unity +++ b/Assets/Scenes/Level01.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 8900000, guid: a7bed68887a07e34394d4191b3081359, type: 3} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.13346848, g: 0.18373615, b: 0.26000363, a: 1} + m_IndirectSpecularColor: {r: 0.13346876, g: 0.18373644, b: 0.2600042, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &4 LightmapSettings: @@ -1764,8 +1764,6 @@ Transform: - {fileID: 264136413} - {fileID: 614175243} - {fileID: 1123739724} - - {fileID: 756133771} - - {fileID: 1994384353} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!82 &183304859 @@ -9662,7 +9660,7 @@ PrefabInstance: serializedVersion: 2 m_Modification: serializedVersion: 3 - m_TransformParent: {fileID: 183304858} + m_TransformParent: {fileID: 1165414997} m_Modifications: - target: {fileID: 1992393469529829993, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_Name @@ -9670,15 +9668,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: -1.5124696 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalPosition.y - value: 0 + value: 1.9276284 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalPosition.z - value: 0 + value: 0.27401495 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalRotation.w @@ -9686,15 +9684,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalRotation.x - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalRotation.y - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalRotation.z - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 4229777418789777714, guid: 9a6d921c651709348999fd7b203033c9, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -11832,6 +11830,8 @@ Transform: - {fileID: 14871712} - {fileID: 636207316} - {fileID: 1656483646} + - {fileID: 756133771} + - {fileID: 1994384353} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1212966710 @@ -13712,6 +13712,8 @@ MonoBehaviour: kepalaKerocoKilled: 0 jendralKilled: 0 rajaKilled: 0 + winQuest: 0 + fail: 0 --- !u!1 &1695883712 GameObject: m_ObjectHideFlags: 0 @@ -16161,51 +16163,11 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1978917666} m_Mesh: {fileID: 4300002, guid: 9f185e9167e4f99489912e1b6d9899bf, type: 3} ---- !u!1 &1994384352 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1994384353} - - component: {fileID: 1994384354} - m_Layer: 0 - m_Name: DataPersistenceManager - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1994384353 +--- !u!4 &1994384353 stripped Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994384352} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 183304858} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1994384354 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} + m_CorrespondingSourceObject: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + m_PrefabInstance: {fileID: 8089176424800807016} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1994384352} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ff080c65d846fce40916179a81d1a151, type: 3} - m_Name: - m_EditorClassIdentifier: - fileName: data.game --- !u!1 &2025801928 stripped GameObject: m_CorrespondingSourceObject: {fileID: 2179698135647974157, guid: a6cf23af3ca4087408302fb3311a1fd3, type: 3} @@ -16591,6 +16553,63 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2138422230} m_CullTransparentMesh: 1 +--- !u!1001 &8089176424800807016 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 1165414997} + m_Modifications: + - target: {fileID: 2379307448264636869, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_Name + value: DataPersistenceManager + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.x + value: -1.5124696 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.y + value: 1.9276284 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.z + value: 0.27401495 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/MainMenu.unity b/Assets/Scenes/MainMenu.unity index 3086566e823d5eea5df94c24ecb13b7855084f3e..09a7bb0cb2672ad5efd4df3ae877522a282946b0 100644 --- a/Assets/Scenes/MainMenu.unity +++ b/Assets/Scenes/MainMenu.unity @@ -2064,6 +2064,63 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 528860947} m_CullTransparentMesh: 1 +--- !u!1001 &573993210 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 2379307448264636869, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_Name + value: DataPersistenceManager + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.x + value: -1.5124696 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.y + value: 1.9276284 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalPosition.z + value: 0.27401495 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} --- !u!1 &579857812 GameObject: m_ObjectHideFlags: 0 @@ -4597,7 +4654,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1184545941 RectTransform: m_ObjectHideFlags: 0 @@ -5362,7 +5419,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1495964239} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2052799349} + m_TargetAssemblyTypeName: MainMenu, Assembly-CSharp + m_MethodName: OnLoadGameClicked + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &1495964239 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7191,7 +7260,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &2052799348 RectTransform: m_ObjectHideFlags: 0 @@ -7234,6 +7303,7 @@ MonoBehaviour: m_EditorClassIdentifier: settings: {fileID: 95415617} stats: {fileID: 1261534167} + loadButton: {fileID: 1495964238} --- !u!114 &2052799350 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7983,3 +8053,4 @@ SceneRoots: - {fileID: 1460444564} - {fileID: 309830954} - {fileID: 716746504} + - {fileID: 573993210} diff --git a/Assets/Scripts/DataUtils/FileDataHandler.cs b/Assets/Scripts/DataUtils/FileDataHandler.cs index 121d11637a1fb8bdc047f9306cb7870cc0f0f432..e4f323934edb75983eb43a3122c5e1162b631439 100644 --- a/Assets/Scripts/DataUtils/FileDataHandler.cs +++ b/Assets/Scripts/DataUtils/FileDataHandler.cs @@ -21,6 +21,8 @@ public class FileDataHandler GameData loadedData = null; + Debug.Log(fullPath); + if (File.Exists(fullPath)) { try diff --git a/Assets/Scripts/DataUtils/GameData.cs b/Assets/Scripts/DataUtils/GameData.cs index 935212a35826462387f4d86f2b6459bbbcda76e5..791d648a0edb9e286bd6da3543bb1fc4e1857844 100644 --- a/Assets/Scripts/DataUtils/GameData.cs +++ b/Assets/Scripts/DataUtils/GameData.cs @@ -16,6 +16,9 @@ public class GameData public double baseDamage; public Vector3 currentPosition; public int currentWeapon; + public int currentScene; + public int currentQuest; + public float shopKeeperTime; // Constructor buat default values kalau new game public GameData() @@ -30,6 +33,9 @@ public class GameData this.baseDamage = 40; this.currentPosition = new Vector3(0f, 0f, 0f); this.currentWeapon = 0; + this.currentScene = 4; + this.currentQuest = 1; + this.shopKeeperTime = 120f; } } diff --git a/Assets/Scripts/MainMenu.meta b/Assets/Scripts/MainMenu.meta new file mode 100644 index 0000000000000000000000000000000000000000..2acfe9287da27713af9a3ad363703722e8ca110b --- /dev/null +++ b/Assets/Scripts/MainMenu.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3dcc3c23223c6bf47a2fee8f908e125f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Global/MainMenu.cs b/Assets/Scripts/MainMenu/MainMenu.cs similarity index 60% rename from Assets/Scripts/Global/MainMenu.cs rename to Assets/Scripts/MainMenu/MainMenu.cs index 33e8ad6fd56b5cc1d95298efe67fa29a04177834..5e7f08515ffb64d1d46a771d8acb50b27cef3c97 100644 --- a/Assets/Scripts/Global/MainMenu.cs +++ b/Assets/Scripts/MainMenu/MainMenu.cs @@ -8,6 +8,15 @@ public class MainMenu : MonoBehaviour { public GameObject settings; public GameObject stats; + [SerializeField] private Button loadButton; + + private void Start() + { + if (!DataPersistenceManager.instance.HasGameData()) + { + loadButton.interactable = false; + } + } public void OpenSettings(bool open) { @@ -34,11 +43,20 @@ public class MainMenu : MonoBehaviour public void PlayGame() { + Debug.Log("On New Game Clicked"); LevelManager.Instance.Next(); + DataPersistenceManager.instance.NewGame(); } public void QuitGame() { Application.Quit(); } + + public void OnLoadGameClicked() + { + Debug.Log("OnLoadGame clicked"); + DataPersistenceManager.instance.LoadGame(); + LevelManager.Instance.LoadScene(); + } } diff --git a/Assets/Scripts/Global/MainMenu.cs.meta b/Assets/Scripts/MainMenu/MainMenu.cs.meta similarity index 100% rename from Assets/Scripts/Global/MainMenu.cs.meta rename to Assets/Scripts/MainMenu/MainMenu.cs.meta diff --git a/Assets/Scripts/Managers/DataPersistenceManager.cs b/Assets/Scripts/Managers/DataPersistenceManager.cs index 17432a11a69237280e729f47ab597feea8bf0abd..0aca1a40b9d416e303e40158fb052b898868ddfb 100644 --- a/Assets/Scripts/Managers/DataPersistenceManager.cs +++ b/Assets/Scripts/Managers/DataPersistenceManager.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; +using UnityEngine.SceneManagement; public class DataPersistenceManager : MonoBehaviour { [Header("File Storage Config")] @@ -15,16 +16,15 @@ public class DataPersistenceManager : MonoBehaviour { if (instance != null) { - Debug.LogError("Found more than one DataPersistence Manager in the scene"); + Debug.LogError("Found more than one DataPersistence Manager in the scene. Destroying the newest one."); + Destroy(this.gameObject); + return; } instance = this; - } - private void Start() - { + DontDestroyOnLoad(this.gameObject); + this.dataHandler = new FileDataHandler(Application.persistentDataPath, fileName); - this.dataPersistenceList = FindAllDataPersistence(); - LoadGame(); } private List<IDataPersistence> FindAllDataPersistence() @@ -41,7 +41,29 @@ public class DataPersistenceManager : MonoBehaviour SaveGame(); return; } - NewGame(); + } + + private void OnEnable() + { + SceneManager.sceneLoaded += OnSceneLoaded; + SceneManager.sceneUnloaded += OnSceneUnloaded; + } + + private void OnDisable() + { + SceneManager.sceneLoaded -= OnSceneLoaded; + SceneManager.sceneUnloaded -= OnSceneUnloaded; + } + + public void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + this.dataPersistenceList = FindAllDataPersistence(); + LoadGame(); + } + + public void OnSceneUnloaded(Scene scene) + { + SaveGame(); } public void NewGame() @@ -54,11 +76,11 @@ public class DataPersistenceManager : MonoBehaviour // TODO - load saved data this.gameData = dataHandler.Load(); - // if no data can be loaded, initialize new game data + // if no data can be loaded, dont continue if (this.gameData == null || this.gameData.playerHealth <= 0) { - Debug.Log("No data was found. Initializing data to defaults"); - NewGame(); + Debug.Log("No data was found. A New Game needs to be started before data can be loaded."); + return; } // TODO - push loaded data to all other scripts that need it @@ -67,11 +89,7 @@ public class DataPersistenceManager : MonoBehaviour dataPersistence.LoadData(gameData); } - GameObject player = GameObject.FindGameObjectWithTag("Player"); - - player.transform.position = this.gameData.currentPosition; - - Debug.Log("Data Loaded."); + Debug.Log("Load Game called"); } public void SaveGame() @@ -80,15 +98,16 @@ public class DataPersistenceManager : MonoBehaviour foreach (IDataPersistence dataPersistence in dataPersistenceList) { dataPersistence.SaveData(ref gameData); - - Debug.Log("Data Saved."); } - GameObject player = GameObject.FindGameObjectWithTag("Player"); - - gameData.currentPosition = player.transform.position; - // TODO - save data to a file dataHandler.Save(gameData); + + Debug.Log("Save Game called"); + } + + public bool HasGameData() + { + return gameData != null; } } diff --git a/Assets/Scripts/Managers/LevelManager.cs b/Assets/Scripts/Managers/LevelManager.cs index 22dae70f2697e1bd3074321affc41768eba690d5..3c61c8e3bd297046247f3698541ac58d746dfacf 100644 --- a/Assets/Scripts/Managers/LevelManager.cs +++ b/Assets/Scripts/Managers/LevelManager.cs @@ -4,7 +4,7 @@ using UnityEngine.SceneManagement; namespace Nightmare { - public class LevelManager : MonoBehaviour + public class LevelManager : MonoBehaviour, IDataPersistence { public string[] levels = { "MainMenu", @@ -69,6 +69,18 @@ namespace Nightmare } } + public void LoadData(GameData data) + { + this.currentIndex = data.currentScene; + this.currentQuest = data.currentQuest; + } + + public void SaveData(ref GameData data) + { + data.currentScene = this.currentIndex; + data.currentQuest = this.currentQuest; + } + private void Update() { // Update only for levels not cutscenes diff --git a/Assets/Scripts/Managers/PetManager.cs b/Assets/Scripts/Managers/PetManager.cs index 0c57db3749c2772f5c91e6125143d1e0e3d8f1a4..a01631375f57631fb4a809d7ba6233d8fefb4743 100644 --- a/Assets/Scripts/Managers/PetManager.cs +++ b/Assets/Scripts/Managers/PetManager.cs @@ -12,7 +12,7 @@ public class PetManager : MonoBehaviour, IDataPersistence { player = GameObject.FindGameObjectWithTag("Player"); } - + public void SpawnPet(string petTag, double petHealth) { GameObject pet = null; @@ -47,27 +47,22 @@ public class PetManager : MonoBehaviour, IDataPersistence public void SaveData(ref GameData data) { - Transform playerTransform = player.transform; + GameObject[] petHealers = GameObject.FindGameObjectsWithTag("PetHealer"); + GameObject[] petFighters = GameObject.FindGameObjectsWithTag("PetFighter"); - foreach (Transform child in playerTransform) + foreach (GameObject petHealer in petHealers) { - if (child.CompareTag("PetHealer")) - { - GameObject pet = child.gameObject; - PetHealth petHealth = pet.GetComponent<PetHealth>(); - - data.pets.Add("PetHealer"); - data.petsHealth.Add(petHealth.currentHealth); - } - else if (child.CompareTag("PetFighter")) - { - GameObject pet = child.gameObject; - PetHealth petHealth = pet.GetComponent<PetHealth>(); + PetHealth goodPetHealth = petHealer.GetComponent<PetHealth>(); + data.pets.Add("PetHealer"); + data.petsHealth.Add(goodPetHealth.currentHealth); + } - data.pets.Add("PetFighter"); - data.petsHealth.Add(petHealth.currentHealth); - } + foreach (GameObject petFighter in petFighters) + { + PetHealth goodPetHealth = petFighter.GetComponent<PetHealth>(); + data.pets.Add("PetFighter"); + data.petsHealth.Add(goodPetHealth.currentHealth); } - } + } } diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index bed4a8986f6f40aa25b31dd620fbd3ac57d664d5..e7499959113415bdaf9b7ad3b436c9cacb8a885a 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -1,6 +1,7 @@ using UnityEngine; using UnitySampleAssets.CrossPlatformInput; using UnityEngine.UI; +using UnityEngine.Playables; namespace Nightmare { @@ -47,11 +48,19 @@ namespace Nightmare public void LoadData(GameData data) { this.speed = data.playerSpeed; + + GameObject player = GameObject.FindGameObjectWithTag("Player"); + + player.transform.position = data.currentPosition; } public void SaveData(ref GameData data) { data.playerSpeed = this.speed; + + GameObject player = GameObject.FindGameObjectWithTag("Player"); + + data.currentPosition = player.transform.position; } void FixedUpdate () diff --git a/Assets/Scripts/ShopKeeper/TimerScript.cs b/Assets/Scripts/ShopKeeper/TimerScript.cs index d4b67c59f1b09809e2036d04b763ff214586edd6..f3eb1b8eb8bd21489867b1d917116953f3d27846 100644 --- a/Assets/Scripts/ShopKeeper/TimerScript.cs +++ b/Assets/Scripts/ShopKeeper/TimerScript.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using UnityEngine; using TMPro; -public class TimerScript : MonoBehaviour +public class TimerScript : MonoBehaviour, IDataPersistence { public TMP_Text timerUI; private Coroutine timeCoroutine; @@ -17,6 +17,16 @@ public class TimerScript : MonoBehaviour timeCoroutine = StartCoroutine(TimerCountDown()); } + public void LoadData(GameData data) + { + this.timer = data.shopKeeperTime; + } + + public void SaveData(ref GameData data) + { + data.shopKeeperTime = this.timer; + } + IEnumerator TimerCountDown() { while (timer > 0)