commit
414691a982
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
Binary file not shown.
8
Assets/KJM/KJM_Test/ISaveable.cs
Normal file
8
Assets/KJM/KJM_Test/ISaveable.cs
Normal file
@ -0,0 +1,8 @@
|
||||
/// <summary>
|
||||
/// 세이브 데이터를 주고 받는 함수 인터페이스
|
||||
/// </summary>
|
||||
public interface ISaveable
|
||||
{
|
||||
void ApplySaveData(Save save);
|
||||
Save ExtractSaveData();
|
||||
}
|
11
Assets/KJM/KJM_Test/ISaveable.cs.meta
Normal file
11
Assets/KJM/KJM_Test/ISaveable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8b6bcb2e37dea949b70a8a96f96e44b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -6,14 +6,27 @@ using UnityEngine;
|
||||
public class DungeonSave
|
||||
{
|
||||
// 강화 수치
|
||||
public int attackLevel;
|
||||
public int attackSpeedLevel;
|
||||
public int heartLevel;
|
||||
public int moveSpeedLevel;
|
||||
public int evasionTimeLevel;
|
||||
public int attackLevel = 0;
|
||||
public int attackSpeedLevel = 0;
|
||||
public int heartLevel = 0;
|
||||
public int moveSpeedLevel = 0;
|
||||
public int evasionTimeLevel = 0;
|
||||
|
||||
// 현재 진행 중인 스테이지
|
||||
public int stageLevel;
|
||||
public int stageLevel = 0;
|
||||
|
||||
//병합을 위한 메서드
|
||||
public void MergeWith(DungeonSave other)
|
||||
{
|
||||
if (other == null) return;
|
||||
|
||||
if (other.attackLevel != 0) attackLevel = other.attackLevel;
|
||||
if (other.attackSpeedLevel != 0) attackSpeedLevel = other.attackSpeedLevel;
|
||||
if (other.heartLevel != 0) heartLevel = other.heartLevel;
|
||||
if (other.moveSpeedLevel != 0) moveSpeedLevel = other.moveSpeedLevel;
|
||||
if (other.evasionTimeLevel != 0) evasionTimeLevel = other.evasionTimeLevel;
|
||||
if (other.stageLevel != 0) stageLevel = other.stageLevel;
|
||||
}
|
||||
}
|
||||
|
||||
// 일상(자취방) 관련 저장 데이터
|
||||
@ -21,17 +34,30 @@ public class DungeonSave
|
||||
public class HomeSave
|
||||
{
|
||||
// 일상 시간
|
||||
public float time;
|
||||
public int day;
|
||||
public int currentDay = 0;
|
||||
public float time = 999;
|
||||
|
||||
|
||||
// 체력 및 평판 수치
|
||||
public float health;
|
||||
public float reputation;
|
||||
public float health = 999;
|
||||
public float reputation = 999;
|
||||
|
||||
//이벤트
|
||||
public bool isEvent;
|
||||
public int mealCount;
|
||||
public int houseworkCount;
|
||||
public int mealCount = 999;
|
||||
public int houseworkCount = 999;
|
||||
|
||||
//병합을 위한 메서드
|
||||
public void MergeWith(HomeSave other)
|
||||
{
|
||||
if (other == null) return;
|
||||
|
||||
if (other.currentDay != 0) currentDay = other.currentDay;
|
||||
if (other.time < 999) time = other.time;
|
||||
if (other.health < 999) health = other.health;
|
||||
if (other.reputation < 999) reputation = other.reputation;
|
||||
if (other.mealCount < 999) mealCount = other.mealCount;
|
||||
if (other.houseworkCount < 999) houseworkCount = other.houseworkCount;
|
||||
}
|
||||
}
|
||||
|
||||
// 게임 전체 저장 구조
|
||||
|
82
Assets/KJM/KJM_Test/SaveDataController.cs
Normal file
82
Assets/KJM/KJM_Test/SaveDataController.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class SaveDataController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private MonoBehaviour[] saveableBehaviours;
|
||||
private ISaveable[] saveables;
|
||||
private Save tmpSave;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
tmpSave = new Save();
|
||||
|
||||
saveables = saveableBehaviours.OfType<ISaveable>().ToArray();
|
||||
|
||||
if (saveables == null || saveables.Length == 0)
|
||||
saveables = FindObjectsOfType<MonoBehaviour>().OfType<ISaveable>().ToArray();
|
||||
}
|
||||
|
||||
//세이브를 현재 상태에 적용
|
||||
public void ApplySaveData(Save saveData)
|
||||
{
|
||||
GetSaveDataFromManager(saveData);
|
||||
SendSaveDataToClass();
|
||||
}
|
||||
|
||||
//현재 상태를 세이브에 적용
|
||||
public Save GetSaveData()
|
||||
{
|
||||
UpdateSaveData();
|
||||
return tmpSave;
|
||||
}
|
||||
|
||||
//로컬에서 로드한 세이브 데이터를 받아오는 함수.
|
||||
private void GetSaveDataFromManager(Save saveData)
|
||||
{
|
||||
tmpSave = saveData;
|
||||
}
|
||||
|
||||
//세이브 데이터를 각클래스에게 적용하는 함수.
|
||||
private void SendSaveDataToClass()
|
||||
{
|
||||
foreach (var s in saveables)
|
||||
{
|
||||
s.ApplySaveData(tmpSave);
|
||||
}
|
||||
}
|
||||
|
||||
//각 클래스에게서 현재 정보를 받아오는 함수.
|
||||
private void UpdateSaveData()
|
||||
{
|
||||
foreach (var s in saveables)
|
||||
{
|
||||
Save partial = s.ExtractSaveData();
|
||||
MergeSave(ref tmpSave, partial);
|
||||
}
|
||||
}
|
||||
|
||||
private void MergeSave(ref Save baseSave, Save newSave)
|
||||
{
|
||||
if (newSave == null) return;
|
||||
|
||||
if (newSave.dungeonSave != null)
|
||||
{
|
||||
if (baseSave.dungeonSave == null)
|
||||
baseSave.dungeonSave = new DungeonSave();
|
||||
|
||||
baseSave.dungeonSave.MergeWith(newSave.dungeonSave);
|
||||
}
|
||||
|
||||
if (newSave.homeSave != null)
|
||||
{
|
||||
if (baseSave.homeSave == null)
|
||||
baseSave.homeSave = new HomeSave();
|
||||
|
||||
baseSave.homeSave.MergeWith(newSave.homeSave);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/KJM/KJM_Test/SaveDataController.cs.meta
Normal file
11
Assets/KJM/KJM_Test/SaveDataController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e5de90e465e1ed4f91e2e6f11e17273
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -12,7 +12,8 @@ public class SaveManager : Singleton<SaveManager>
|
||||
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<SaveManager>
|
||||
|
||||
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<SaveManager>
|
||||
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<SaveManager>
|
||||
|
||||
private void UpdateSaveInfo()
|
||||
{
|
||||
mainSave = StatManager.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
||||
mainSave = saveDataController.GetSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
||||
}
|
||||
|
||||
private void SaveMain()
|
||||
@ -119,7 +120,7 @@ public class SaveManager : Singleton<SaveManager>
|
||||
//더미 세이브 파일 생성
|
||||
private Save CreateNewSave()
|
||||
{
|
||||
var fresh = StatManager.instance.ToSaveData();
|
||||
var fresh = saveDataController.GetSaveData();
|
||||
SaveMain();
|
||||
SaveBackup();
|
||||
return fresh;
|
||||
|
@ -1,120 +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 day;
|
||||
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;
|
||||
day = 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,
|
||||
day = this.day,
|
||||
health = this.health,
|
||||
reputation = this.reputation,
|
||||
isEvent = false,
|
||||
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;
|
||||
day = saveData.homeSave.day;
|
||||
health = saveData.homeSave.health;
|
||||
reputation = saveData.homeSave.reputation;
|
||||
isEvent = saveData.homeSave.isEvent;
|
||||
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