diff --git a/Assets/KJM/KJM.unity b/Assets/KJM/KJM.unity index 0d91b2f4..09606b0d 100644 --- a/Assets/KJM/KJM.unity +++ b/Assets/KJM/KJM.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7f13f719e71b8e944fc097d5a437f5e135e094a1cf536cc80881327f9a5dbe59 -size 48687 +oid sha256:72074771a04b1e569bf2994ccbbf0fa4598b680121664c502cf750c8f77fd2f7 +size 49861 diff --git a/Assets/KJM/KJM_Test/ISaveable.cs b/Assets/KJM/KJM_Test/ISaveable.cs index 5c98ca97..a7d44c8e 100644 --- a/Assets/KJM/KJM_Test/ISaveable.cs +++ b/Assets/KJM/KJM_Test/ISaveable.cs @@ -6,26 +6,3 @@ public interface ISaveable void ApplySaveData(Save save); Save ExtractSaveData(); } - - -// 인터페이스 사용예시 -// -// public void ApplySaveData(Save save) -// { -// if (save?.homeSave != null) -// { -// mealCount = save.homeSave.mealCount; -// } -// } -// -// public Save ExtractSaveData() -// { -// // 자신이 책임지는 부분만 채움, 나머지는 null로 둠 -// return new Save -// { -// homeSave = new HomeSave -// { -// mealCount = mealCount -// } -// }; -// } diff --git a/Assets/KJM/KJM_Test/SaveDataController.cs b/Assets/KJM/KJM_Test/SaveDataController.cs index f380d64b..58cb82e8 100644 --- a/Assets/KJM/KJM_Test/SaveDataController.cs +++ b/Assets/KJM/KJM_Test/SaveDataController.cs @@ -6,13 +6,16 @@ using UnityEngine; public class SaveDataController : MonoBehaviour { - [SerializeField] private ISaveable[] saveables; + [SerializeField] private MonoBehaviour[] saveableBehaviours; + private ISaveable[] saveables; private Save tmpSave; void Awake() { tmpSave = new Save(); + saveables = saveableBehaviours.OfType().ToArray(); + if (saveables == null || saveables.Length == 0) saveables = FindObjectsOfType().OfType().ToArray(); } diff --git a/Assets/KJM/KJM_Test/SaveManager.cs b/Assets/KJM/KJM_Test/SaveManager.cs index 0b9c8df1..773cff46 100644 --- a/Assets/KJM/KJM_Test/SaveManager.cs +++ b/Assets/KJM/KJM_Test/SaveManager.cs @@ -12,7 +12,8 @@ public class SaveManager : Singleton private const string SaveFolder = "QuickSave"; private string MainSaveFilePath => GetSavePath("Save_Main"); private string BackupSaveFilePath => GetSavePath("Save_Backup"); - + + [SerializeField] private SaveDataController saveDataController; private Save mainSave; private Save backupSave; @@ -25,7 +26,7 @@ public class SaveManager : Singleton public void Save() { - if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(StatManager.instance.ToSaveData())) //같은 상태는 저장되지 않음. 백업 덮어쓰기 방지. + if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(saveDataController.GetSaveData())) //같은 상태는 저장되지 않음. 백업 덮어쓰기 방지. return; EnsureSaveExists(); @@ -45,7 +46,7 @@ public class SaveManager : Singleton mainSave = LoadMain(); backupSave = LoadBackup(); - StatManager.instance.loadSaveData2StataManager(mainSave); + saveDataController.ApplySaveData(mainSave); Debug.Log("메인 로드" + mainSave.homeSave.reputation); //임시 코드 Debug.Log("백업 로드" + backupSave.homeSave.reputation); //임시 코드 @@ -53,7 +54,7 @@ public class SaveManager : Singleton private void UpdateSaveInfo() { - mainSave = StatManager.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출 + mainSave = saveDataController.GetSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출 } private void SaveMain() @@ -119,7 +120,7 @@ public class SaveManager : Singleton //더미 세이브 파일 생성 private Save CreateNewSave() { - var fresh = StatManager.instance.ToSaveData(); + var fresh = saveDataController.GetSaveData(); SaveMain(); SaveBackup(); return fresh; diff --git a/Assets/KJM/KJM_Test/StatManager.cs b/Assets/KJM/KJM_Test/StatManager.cs deleted file mode 100644 index d00d5e68..00000000 --- a/Assets/KJM/KJM_Test/StatManager.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; -using Random = UnityEngine.Random; - -/// -/// 테스트용 임시 클래스 -/// -public class StatManager : MonoBehaviour -{ - public static StatManager instance; - - public int attackLevel; - public int attackSpeedLevel; - public int heartLevel; - public int moveSpeedLevel; - public int evasionTimeLevel; - public int stageLevel; - - public float time; - public int currentDay; - public float health; - public float reputation; - - public bool isEvent; //Todo 이벤트 여부 및 관련 조건들 추가 - public int mealCount; - public int houseworkCount; - - - private void Awake() - { - instance = this; - } - - /// - /// 스탯값 변화 - /// - public void ChangeValue() - { - float floatValue = Random.Range(0f, 2f); - Debug.Log(floatValue); - int intValue = Random.Range(0, 10); - Debug.Log(intValue); - - attackLevel = intValue; - attackSpeedLevel = intValue; - heartLevel = intValue; - moveSpeedLevel = intValue; - evasionTimeLevel = intValue; - stageLevel = intValue; - - - time = floatValue; - currentDay = intValue; - health = floatValue; - reputation = floatValue; - - isEvent = false; - mealCount = intValue; - houseworkCount = intValue; - - Debug.Log("ChangeValue"); - - } - - /// - /// 스탯값 반환 - /// - /// - public Save ToSaveData() - { - return new Save - { - dungeonSave = new DungeonSave - { - attackLevel = this.attackLevel, - attackSpeedLevel = this.attackSpeedLevel, - heartLevel = this.heartLevel, - moveSpeedLevel = this.moveSpeedLevel, - evasionTimeLevel = this.evasionTimeLevel, - stageLevel = this.stageLevel - }, - homeSave = new HomeSave - { - time = this.time, - currentDay = this.currentDay, - health = this.health, - reputation = this.reputation, - mealCount = this.mealCount, - houseworkCount = this.houseworkCount, - } - }; - } - - public void loadSaveData2StataManager(Save saveData) - { - attackLevel = saveData.dungeonSave.attackLevel; - attackSpeedLevel = saveData.dungeonSave.attackSpeedLevel; - heartLevel = saveData.dungeonSave.heartLevel; - moveSpeedLevel = saveData.dungeonSave.moveSpeedLevel; - evasionTimeLevel = saveData.dungeonSave.evasionTimeLevel; - stageLevel = saveData.dungeonSave.stageLevel; - - time = saveData.homeSave.time; - currentDay = saveData.homeSave.currentDay; - health = saveData.homeSave.health; - reputation = saveData.homeSave.reputation; - mealCount = saveData.homeSave.mealCount; - houseworkCount = saveData.homeSave.houseworkCount; - } - - public void SceneChange() - { - SceneManager.LoadScene("Main"); - } -} diff --git a/Assets/KJM/KJM_Test/TestScript.cs b/Assets/KJM/KJM_Test/TestScript.cs new file mode 100644 index 00000000..107b18ab --- /dev/null +++ b/Assets/KJM/KJM_Test/TestScript.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; +using Random = UnityEngine.Random; + +/// +/// 테스트용 임시 클래스 +/// +public class TestScript : MonoBehaviour,ISaveable +{ + //던전 + private int attackLevel; + private int attackSpeedLevel; + private int heartLevel; + private int moveSpeedLevel; + private int evasionTimeLevel; + private int stageLevel; + + //일상 + private float time; + private int currentDay; + private float health; + private float reputation; + private int mealCount; + private int houseworkCount; + + /// + /// 스탯값 랜덤 변화 + /// + public void ChangeValue() + { + float floatValue = Random.Range(0f, 2f); + int intValue = Random.Range(0, 10); + + attackLevel = intValue; + attackSpeedLevel = intValue; + heartLevel = intValue; + moveSpeedLevel = intValue; + stageLevel = intValue; + + + time = floatValue; + currentDay = intValue; + health = floatValue; + reputation = floatValue; + mealCount = intValue; + houseworkCount = intValue; + + Debug.Log("ChangeValue : " + floatValue); + } + + /// + /// 인터페이스 함수1, 데이터 불러오기 + /// + /// + public void ApplySaveData(Save save) + { + if (save?.dungeonSave != null) + { + attackLevel = save.dungeonSave.attackLevel; + attackSpeedLevel = save.dungeonSave.attackSpeedLevel; + heartLevel = save.dungeonSave.heartLevel; + moveSpeedLevel = save.dungeonSave.moveSpeedLevel; + evasionTimeLevel = save.dungeonSave.evasionTimeLevel; + stageLevel = save.dungeonSave.stageLevel; + } + + if (save?.homeSave != null) + { + time = save.homeSave.time; + currentDay = save.homeSave.currentDay; + health = save.homeSave.health; + reputation = save.homeSave.reputation; + mealCount = save.homeSave.mealCount; + houseworkCount = save.homeSave.houseworkCount; + + Debug.Log("ApplySaveData : " + reputation); + } + } + + /// + /// 인터페이스 함수2, 데이터 전달 + /// + /// + public Save ExtractSaveData() + { + return new Save + { + dungeonSave = new DungeonSave() + { + attackLevel = this.attackLevel, + attackSpeedLevel = this.attackSpeedLevel, + heartLevel = this.heartLevel, + moveSpeedLevel = this.moveSpeedLevel, + evasionTimeLevel = this.evasionTimeLevel, + stageLevel = this.stageLevel, + + }, + + homeSave = new HomeSave + { + time = this.time, + currentDay = this.currentDay, + health = this.health, + reputation = this.reputation, + mealCount = this.mealCount, + houseworkCount = this.houseworkCount + } + }; + } + + /// + /// 씬 전환 테스트용 함수 + /// + public void SceneChange() + { + SceneManager.LoadScene("Main"); + } + +} diff --git a/Assets/KJM/KJM_Test/StatManager.cs.meta b/Assets/KJM/KJM_Test/TestScript.cs.meta similarity index 100% rename from Assets/KJM/KJM_Test/StatManager.cs.meta rename to Assets/KJM/KJM_Test/TestScript.cs.meta