Deg-23 [Feat] 세이브 매니저 싱글톤 구현
This commit is contained in:
parent
f28f659e68
commit
3cf799e039
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
BIN
Assets/KJM/KJM.unity
(Stored with Git LFS)
Binary file not shown.
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using CI.QuickSave;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SaveManager : MonoBehaviour
|
||||
public class SaveManager : Singleton<SaveManager>
|
||||
{
|
||||
private const string SaveFolder = "QuickSave";
|
||||
private const string SaveFileName = "Save_Main.json";
|
||||
@ -13,6 +14,7 @@ public class SaveManager : MonoBehaviour
|
||||
private Save mainSave;
|
||||
private Save backupSave;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
mainSave = new Save();
|
||||
@ -33,7 +35,7 @@ public class SaveManager : MonoBehaviour
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(GMTest.instance.ToSaveData())) //같은 상태를 저장하면 저장되지 않음. 백업 덮어쓰기 방지
|
||||
if(JsonUtility.ToJson(mainSave) == JsonUtility.ToJson(StatManager.instance.ToSaveData())) //같은 상태는 저장되지 않음. 백업 덮어쓰기 방지.
|
||||
return;
|
||||
|
||||
backupSave = LoadMain(); //메인 세이브를 백업 세이브에 로드
|
||||
@ -55,7 +57,7 @@ public class SaveManager : MonoBehaviour
|
||||
|
||||
private void UpdateSaveInfo()
|
||||
{
|
||||
mainSave = GMTest.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
||||
mainSave = StatManager.instance.ToSaveData(); //스탯을 관리하는 클래스에 선언된 스탯 업데이트 함수를 호출
|
||||
}
|
||||
|
||||
private void SaveMain()
|
||||
@ -84,4 +86,9 @@ public class SaveManager : MonoBehaviour
|
||||
.Read<Save>("Backup");
|
||||
}
|
||||
|
||||
protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
Save();
|
||||
Debug.Log("자동저장");
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,15 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class GMTest : MonoBehaviour
|
||||
/// <summary>
|
||||
/// 테스트용 임시 클래스
|
||||
/// </summary>
|
||||
public class StatManager : MonoBehaviour
|
||||
{
|
||||
public static GMTest instance;
|
||||
public static StatManager instance;
|
||||
|
||||
public int attackLevel;
|
||||
public int attackSpeedLevel;
|
||||
@ -25,6 +29,9 @@ public class GMTest : MonoBehaviour
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 스탯값 변화
|
||||
/// </summary>
|
||||
public void ChangeValue()
|
||||
{
|
||||
float floatValue = Random.Range(0f, 2f);
|
||||
@ -49,6 +56,10 @@ public class GMTest : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 스탯값 반환
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Save ToSaveData()
|
||||
{
|
||||
return new Save
|
||||
@ -71,4 +82,9 @@ public class GMTest : MonoBehaviour
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void SceneChange()
|
||||
{
|
||||
SceneManager.LoadScene("Main");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user