DEG-23 [Feat] 예외 처리 및 테스트 스탯매니저

세이브 첫 생성 및 중복 요청 시 예외처리.
임시 스탯 매니저 생성.
This commit is contained in:
99jamin 2025-04-18 23:58:55 +09:00
parent 84c718101c
commit f28f659e68
7 changed files with 185 additions and 144 deletions

BIN
Assets/KJM/KJM.unity (Stored with Git LFS)

Binary file not shown.

View File

@ -2,7 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Random = System.Random; using Random = UnityEngine.Random;
public class GMTest : MonoBehaviour public class GMTest : MonoBehaviour
{ {
@ -13,14 +13,11 @@ public class GMTest : MonoBehaviour
public int heartLevel; public int heartLevel;
public int moveSpeedLevel; public int moveSpeedLevel;
public int evasionTimeLevel; public int evasionTimeLevel;
//스테이지 진행도
public int stageLevel; public int stageLevel;
public float time; public float time;
public float health; public float health;
public float reputation; public float reputation;
public bool isEvent; //Todo 이벤트 여부 및 관련 조건들 추가 public bool isEvent; //Todo 이벤트 여부 및 관련 조건들 추가
private void Start() private void Start()
@ -30,6 +27,48 @@ public class GMTest : MonoBehaviour
public void ChangeValue() public void ChangeValue()
{ {
//float rand = Random.Range(0f, 1f); 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;
health = floatValue;
reputation = floatValue;
isEvent = false;
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,
health = this.health,
reputation = this.reputation,
isEvent = false
}
};
} }
} }

View File

@ -0,0 +1,40 @@
using System;
using UnityEngine;
// 던전 관련 저장 데이터
[Serializable]
public class DungeonSave
{
// 강화 수치
public int attackLevel;
public int attackSpeedLevel;
public int heartLevel;
public int moveSpeedLevel;
public int evasionTimeLevel;
// 현재 진행 중인 스테이지
public int stageLevel;
}
// 일상(자취방) 관련 저장 데이터
[Serializable]
public class HomeSave
{
// 일상 시간
public float time;
// 체력 및 평판 수치
public float health;
public float reputation;
// 돌발 이벤트 발생 여부
public bool isEvent;
}
// 게임 전체 저장 구조
[Serializable]
public class Save
{
public HomeSave homeSave;
public DungeonSave dungeonSave;
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d33a0395e991c084eb8003ba7ffab5a8 guid: 883ac325bc606014fa78662a7b7ec954
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using CI.QuickSave;
using UnityEngine;
public class SaveManager : MonoBehaviour
{
private const string SaveFolder = "QuickSave";
private const string SaveFileName = "Save_Main.json";
private string SaveFilePath => Path.Combine(Application.persistentDataPath, SaveFolder, SaveFileName);
private Save mainSave;
private Save backupSave;
void Start()
{
mainSave = new Save();
backupSave = new Save();
if (!QuickSaveRaw.Exists(SaveFilePath)) // Save_Main 파일이 없을때
{
UpdateSaveInfo();
SaveMain(); //Save_Main 파일 생성
backupSave = LoadMain();
SaveBackup(); //Save_Backup 파일 생성
Debug.Log("세이브가 존재하지 않아 새로운 세이브 생성.");
}
Load(); //저장된 메인,백업 세이브를 로드
}
public void Save()
{
if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(GMTest.instance.ToSaveData())) //같은 상태를 저장하면 저장되지 않음. 백업 덮어쓰기 방지
return;
backupSave = LoadMain(); //메인 세이브를 백업 세이브에 로드
SaveBackup(); //백업 세이브 저장
UpdateSaveInfo(); //세이브를 현재 정보로 업데이트
SaveMain(); //메인 세이브 저장
Debug.Log("세이브");
}
public void Load()
{
mainSave = LoadMain();
backupSave = LoadBackup();
Debug.Log("메인 로드" + mainSave.homeSave.reputation);
Debug.Log("백업 로드" + backupSave.homeSave.reputation);
}
private void UpdateSaveInfo()
{
mainSave = GMTest.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
}
private void SaveMain()
{
QuickSaveWriter.Create("Save_Main")
.Write("Main", mainSave)
.Commit();
}
private void SaveBackup()
{
QuickSaveWriter.Create("Save_Backup")
.Write("Backup", backupSave)
.Commit();
}
private Save LoadMain()
{
return QuickSaveReader.Create("Save_Main")
.Read<Save>("Main");
}
private Save LoadBackup()
{
return QuickSaveReader.Create("Save_Backup")
.Read<Save>("Backup");
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9c85bf88c19d95947bc288da9dfd85bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,136 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using CI.QuickSave;
using UnityEngine;
//저장해야할 정보
//던전 : 강화 수치, 현재 스테이지
//일상 : 시간, 체력, 사회평판, 돌발 이벤트 호출 여부(), 일상 이벤트 호출 여부(회사,식사)
//던전 정보
[System.Serializable]
public class DungeonSave
{
//강화 수치
public int attackLevel;
public int attackSpeedLevel;
public int heartLevel;
public int moveSpeedLevel;
public int evasionTimeLevel;
//스테이지 진행도
public int stageLevel;
}
[System.Serializable]
public class HomeSave
{
public float time;
public float health;
public float reputation;
public bool isEvent; //Todo 이벤트 여부 및 관련 조건들 추가
}
[System.Serializable]
public class Save
{
public HomeSave homeSave;
public DungeonSave dungeonSave;
}
public class SaveTest : MonoBehaviour
{
private Save mainSave;
private Save backupSave;
void Start()
{
mainSave = new Save();
backupSave = new Save();
if (!QuickSaveRaw.Exists("Save_Main")) // Save_Main.qs파일이 없을때
{
UpdateSaveInfo();
SaveMain(); //Save_Main.qs 파일 생성
backupSave = LoadMain();
SaveBackup(); //Save_Backup.qs 파일 생성
}
Load(); //저장된 메인,백업 세이브를 로드
}
public void Save()
{
backupSave = LoadMain(); //메인 세이브를 백업 세이브에 로드
SaveBackup(); //백업 세이브 저장
UpdateSaveInfo(); //세이브를 현재 정보로 업데이트
SaveMain(); //메인 세이브 저장
Debug.Log("세이브");
}
public void Load()
{
mainSave = LoadMain();
backupSave = LoadBackup();
Debug.Log("메인 로드" + mainSave);
Debug.Log("백업 로드" + backupSave);
}
private void UpdateSaveInfo()
{
//Todo: 데이터 받기
//임시 데이터 생성
mainSave = new Save
{
dungeonSave = new DungeonSave
{
attackLevel = 2,
attackSpeedLevel = 1,
heartLevel = 3,
moveSpeedLevel = 1,
evasionTimeLevel = 2,
stageLevel = 5
},
homeSave = new HomeSave
{
time = 3.5f,
health = 80f,
reputation = 42f,
isEvent = false
}
};
}
private void SaveMain()
{
QuickSaveWriter.Create("Save_Main")
.Write("Main", mainSave)
.Commit();
}
private void SaveBackup()
{
QuickSaveWriter.Create("Save_Backup")
.Write("Backup", backupSave)
.Commit();
}
private Save LoadMain()
{
return QuickSaveReader.Create("Save_Main")
.Read<Save>("Main");
}
private Save LoadBackup()
{
return QuickSaveReader.Create("Save_Backup")
.Read<Save>("Backup");
}
}