파일 입출력과 JSON변환 예외처리
This commit is contained in:
parent
70eb7d3268
commit
1925579508
@ -64,6 +64,8 @@ public class ReplayManager : Singleton<ReplayManager>
|
|||||||
/// 게임 종료 후 호출하여 리플레이 데이터를 저장합니다.
|
/// 게임 종료 후 호출하여 리플레이 데이터를 저장합니다.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SaveReplayData(PlayerType winnerPlayerType)
|
public void SaveReplayData(PlayerType winnerPlayerType)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
string time = DateTime.Now.ToString(("yyyy-MM-dd HH_mm_ss"));
|
string time = DateTime.Now.ToString(("yyyy-MM-dd HH_mm_ss"));
|
||||||
_recordingReplayData.gameDate = time;
|
_recordingReplayData.gameDate = time;
|
||||||
@ -79,6 +81,11 @@ public class ReplayManager : Singleton<ReplayManager>
|
|||||||
//최신 데이터 10개만 유지되도록 저장
|
//최신 데이터 10개만 유지되도록 저장
|
||||||
RecordCountChecker();
|
RecordCountChecker();
|
||||||
}
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"An error occurred while saving replay data:{e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//폴더내 기보 파일을 전부 읽어옵니다.
|
//폴더내 기보 파일을 전부 읽어옵니다.
|
||||||
@ -86,16 +93,34 @@ public class ReplayManager : Singleton<ReplayManager>
|
|||||||
{
|
{
|
||||||
List<ReplayRecord> records = new List<ReplayRecord>();
|
List<ReplayRecord> records = new List<ReplayRecord>();
|
||||||
string path = Application.persistentDataPath;
|
string path = Application.persistentDataPath;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var files = Directory.GetFiles(path, "*.json");
|
var files = Directory.GetFiles(path, "*.json");
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
records.Add(JsonUtility.FromJson<ReplayRecord>(File.ReadAllText(file)));
|
try
|
||||||
|
{
|
||||||
|
ReplayRecord record = JsonUtility.FromJson<ReplayRecord>(File.ReadAllText(file));
|
||||||
|
records.Add(record);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Replaydata cannot be converted to JSON: {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Replay Directory Error: {e.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecordCountChecker()
|
private void RecordCountChecker()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
string path = Application.persistentDataPath;
|
string path = Application.persistentDataPath;
|
||||||
var files = Directory.GetFiles(path, "*.json");
|
var files = Directory.GetFiles(path, "*.json");
|
||||||
@ -104,6 +129,11 @@ public class ReplayManager : Singleton<ReplayManager>
|
|||||||
File.Delete(files[0]);
|
File.Delete(files[0]);
|
||||||
RecordCountChecker();
|
RecordCountChecker();
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Replay Directory Error: {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user