diff --git a/Assets/Scenes/Level01.unity b/Assets/Scenes/Level01.unity index b703d679e0b0d0c93192d48d1bd863ef8a0d00e9..15701439ee99817607fd26dd638bd02b36b81b8d 100644 --- a/Assets/Scenes/Level01.unity +++ b/Assets/Scenes/Level01.unity @@ -11831,7 +11831,6 @@ Transform: - {fileID: 636207316} - {fileID: 1656483646} - {fileID: 756133771} - - {fileID: 1994384353} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1212966710 @@ -16176,11 +16175,6 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1978917666} m_Mesh: {fileID: 4300002, guid: 9f185e9167e4f99489912e1b6d9899bf, type: 3} ---- !u!4 &1994384353 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 5034770101523303488, guid: 607ac10d4a28a814ea8aea94b0d7c524, type: 3} - m_PrefabInstance: {fileID: 8089176424800807016} - m_PrefabAsset: {fileID: 0} --- !u!1 &2025801928 stripped GameObject: m_CorrespondingSourceObject: {fileID: 2179698135647974157, guid: a6cf23af3ca4087408302fb3311a1fd3, type: 3} @@ -16566,63 +16560,6 @@ 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/Scripts/MainMenu/MainMenu.cs b/Assets/Scripts/MainMenu/MainMenu.cs index 74757dff8fb904d0e22f380aab353278bacc52e1..867bbd00dc3bc8fd1157960f9027d441df3e68d4 100644 --- a/Assets/Scripts/MainMenu/MainMenu.cs +++ b/Assets/Scripts/MainMenu/MainMenu.cs @@ -51,7 +51,7 @@ public class MainMenu : MonoBehaviour public void QuitGame() { - DataPersistenceManager.instance.DeleteFile(); + DataPersistenceManager.instance.FileMechanism(); Application.Quit(); } @@ -59,6 +59,7 @@ public class MainMenu : MonoBehaviour { Debug.Log("OnLoadGame clicked"); DataPersistenceManager.instance.LoadGame(); + DataPersistenceManager.instance.LoadGameClicked(); LevelManager.Instance.LoadScene(); } } diff --git a/Assets/Scripts/Managers/DataPersistenceManager.cs b/Assets/Scripts/Managers/DataPersistenceManager.cs index 8f2e1978712cfff8c8fff44155bc6d6ff4acc050..4dd381323091b837722deb114f62e4949a910b33 100644 --- a/Assets/Scripts/Managers/DataPersistenceManager.cs +++ b/Assets/Scripts/Managers/DataPersistenceManager.cs @@ -11,7 +11,9 @@ public class DataPersistenceManager : MonoBehaviour public static DataPersistenceManager instance { get; private set; } private GameData gameData; private List<IDataPersistence> dataPersistenceList; + private GameData loadedGameData; private bool newGame = false; + private bool loadGame = false; private bool saveSafeHouse = false; private void Awake() @@ -41,13 +43,20 @@ public class DataPersistenceManager : MonoBehaviour this.dataHandler.Delete(); } - public void DeleteFile() + public void FileMechanism() { - if (!saveSafeHouse) + if (!saveSafeHouse && !loadGame) { this.dataHandler.Delete(); this.gameData = null; } + else if (loadGame) + { + if (!saveSafeHouse) + { + this.dataHandler.Save(this.loadedGameData); + } + } } private void OnEnable() @@ -96,8 +105,8 @@ public class DataPersistenceManager : MonoBehaviour // TODO - load saved data if (!newGame) { - Debug.Log("Masuk ga"); this.gameData = dataHandler.Load(); + this.loadedGameData = this.gameData; } // if no data can be loaded, dont continue @@ -150,4 +159,10 @@ public class DataPersistenceManager : MonoBehaviour { this.saveSafeHouse = true; } + + public void LoadGameClicked() + { + this.loadGame = true; + this.loadedGameData = gameData; + } } diff --git a/Assets/Scripts/Managers/GameOverManager.cs b/Assets/Scripts/Managers/GameOverManager.cs index c5f2ff0457e76e79cc7c0fb438b0826d153128be..9a1ab4bdf4ee2dd1025753db2de809765ee2962c 100644 --- a/Assets/Scripts/Managers/GameOverManager.cs +++ b/Assets/Scripts/Managers/GameOverManager.cs @@ -44,7 +44,7 @@ namespace Nightmare public void ExitGame() { - DataPersistenceManager.instance.DeleteFile(); + DataPersistenceManager.instance.FileMechanism(); LevelManager.Instance.Exit(); } diff --git a/Assets/Scripts/Managers/LevelManager.cs b/Assets/Scripts/Managers/LevelManager.cs index eba761444e3e78d00222ee039a8402adf0a90b1b..3613cdba3c21ab2bea754b44e21c61afea75ceac 100644 --- a/Assets/Scripts/Managers/LevelManager.cs +++ b/Assets/Scripts/Managers/LevelManager.cs @@ -22,7 +22,7 @@ namespace Nightmare "Cutscene08" }; - private static LevelManager instance; + //private static LevelManager instance; private int currentIndex = 0; private int currentQuest = 0; private float announcementDuration = 5f; @@ -39,34 +39,34 @@ namespace Nightmare public bool winQuest = false; public bool fail = false; - public static LevelManager Instance - { - get - { - if (instance == null) - { - instance = FindObjectOfType<LevelManager>(); - if (instance == null) - { - GameObject managerObject = new GameObject("LevelManager"); - instance = managerObject.AddComponent<LevelManager>(); - } - } - return instance; - } - } + public static LevelManager Instance; + //{ + // get + // { + // if (instance == null) + // { + // instance = FindObjectOfType<LevelManager>(); + // if (instance == null) + // { + // GameObject managerObject = new GameObject("LevelManager"); + // instance = managerObject.AddComponent<LevelManager>(); + // } + // } + // return instance; + // } + //} private void Awake() { - if (instance == null) - { - instance = this; - DontDestroyOnLoad(gameObject); - } - else + if (Instance != null) { - Destroy(gameObject); + Debug.LogError("Found more than one LevelManager in the scene. Destroying the newest one."); + Destroy(this.gameObject); + return; } + + Instance = this; + DontDestroyOnLoad(this.gameObject); } public void LoadData(GameData data) @@ -295,7 +295,7 @@ namespace Nightmare } } - timeRemaining = 60f + announcementDuration; + timeRemaining = 5f + announcementDuration; } else if (currentQuest == 2) {