DEG-24 [Test] 인터페이스 사용 테스트 코드 추가
This commit is contained in:
parent
a3328c7724
commit
67410c0860
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
Binary file not shown.
@ -6,26 +6,3 @@ public interface ISaveable
|
|||||||
void ApplySaveData(Save save);
|
void ApplySaveData(Save save);
|
||||||
Save ExtractSaveData();
|
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
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
@ -6,13 +6,16 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class SaveDataController : MonoBehaviour
|
public class SaveDataController : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private ISaveable[] saveables;
|
[SerializeField] private MonoBehaviour[] saveableBehaviours;
|
||||||
|
private ISaveable[] saveables;
|
||||||
private Save tmpSave;
|
private Save tmpSave;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
tmpSave = new Save();
|
tmpSave = new Save();
|
||||||
|
|
||||||
|
saveables = saveableBehaviours.OfType<ISaveable>().ToArray();
|
||||||
|
|
||||||
if (saveables == null || saveables.Length == 0)
|
if (saveables == null || saveables.Length == 0)
|
||||||
saveables = FindObjectsOfType<MonoBehaviour>().OfType<ISaveable>().ToArray();
|
saveables = FindObjectsOfType<MonoBehaviour>().OfType<ISaveable>().ToArray();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ public class SaveManager : Singleton<SaveManager>
|
|||||||
private string MainSaveFilePath => GetSavePath("Save_Main");
|
private string MainSaveFilePath => GetSavePath("Save_Main");
|
||||||
private string BackupSaveFilePath => GetSavePath("Save_Backup");
|
private string BackupSaveFilePath => GetSavePath("Save_Backup");
|
||||||
|
|
||||||
|
[SerializeField] private SaveDataController saveDataController;
|
||||||
|
|
||||||
private Save mainSave;
|
private Save mainSave;
|
||||||
private Save backupSave;
|
private Save backupSave;
|
||||||
@ -25,7 +26,7 @@ public class SaveManager : Singleton<SaveManager>
|
|||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(StatManager.instance.ToSaveData())) //같은 상태는 저장되지 않음. 백업 덮어쓰기 방지.
|
if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(saveDataController.GetSaveData())) //같은 상태는 저장되지 않음. 백업 덮어쓰기 방지.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EnsureSaveExists();
|
EnsureSaveExists();
|
||||||
@ -45,7 +46,7 @@ public class SaveManager : Singleton<SaveManager>
|
|||||||
mainSave = LoadMain();
|
mainSave = LoadMain();
|
||||||
backupSave = LoadBackup();
|
backupSave = LoadBackup();
|
||||||
|
|
||||||
StatManager.instance.loadSaveData2StataManager(mainSave);
|
saveDataController.ApplySaveData(mainSave);
|
||||||
|
|
||||||
Debug.Log("메인 로드" + mainSave.homeSave.reputation); //임시 코드
|
Debug.Log("메인 로드" + mainSave.homeSave.reputation); //임시 코드
|
||||||
Debug.Log("백업 로드" + backupSave.homeSave.reputation); //임시 코드
|
Debug.Log("백업 로드" + backupSave.homeSave.reputation); //임시 코드
|
||||||
@ -53,7 +54,7 @@ public class SaveManager : Singleton<SaveManager>
|
|||||||
|
|
||||||
private void UpdateSaveInfo()
|
private void UpdateSaveInfo()
|
||||||
{
|
{
|
||||||
mainSave = StatManager.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
mainSave = saveDataController.GetSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveMain()
|
private void SaveMain()
|
||||||
@ -119,7 +120,7 @@ public class SaveManager : Singleton<SaveManager>
|
|||||||
//더미 세이브 파일 생성
|
//더미 세이브 파일 생성
|
||||||
private Save CreateNewSave()
|
private Save CreateNewSave()
|
||||||
{
|
{
|
||||||
var fresh = StatManager.instance.ToSaveData();
|
var fresh = saveDataController.GetSaveData();
|
||||||
SaveMain();
|
SaveMain();
|
||||||
SaveBackup();
|
SaveBackup();
|
||||||
return fresh;
|
return fresh;
|
||||||
|
@ -1,118 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
using Random = UnityEngine.Random;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 테스트용 임시 클래스
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 스탯값 변화
|
|
||||||
/// </summary>
|
|
||||||
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");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 스탯값 반환
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
122
Assets/KJM/KJM_Test/TestScript.cs
Normal file
122
Assets/KJM/KJM_Test/TestScript.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 테스트용 임시 클래스
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 스탯값 랜덤 변화
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 인터페이스 함수1, 데이터 불러오기
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="save"></param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 인터페이스 함수2, 데이터 전달
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 씬 전환 테스트용 함수
|
||||||
|
/// </summary>
|
||||||
|
public void SceneChange()
|
||||||
|
{
|
||||||
|
SceneManager.LoadScene("Main");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user