feat(): 完成将Manager从Gameplay转移到Core,实现循环次数持久化,实现设置面板
This commit is contained in:
27
Assets/Script/Gameplay/Global/GameDataManager.cs
Normal file
27
Assets/Script/Gameplay/Global/GameDataManager.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Core;
|
||||
using Script.Gameplay.Input;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.Gameplay.Global
|
||||
{
|
||||
public class GameDataManager : MonoSingleton<GameDataManager>
|
||||
{
|
||||
private const string LoopCountKey = "TotalLoopCount";
|
||||
public int TotalLoopCount { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameManager.Instance.OnGameStart += AddLoop;
|
||||
// 读取已保存的循环次数
|
||||
TotalLoopCount = PlayerPrefs.GetInt(LoopCountKey, 0);
|
||||
Debug.Log("目前循环次数:" + TotalLoopCount);
|
||||
}
|
||||
|
||||
public void AddLoop()
|
||||
{
|
||||
TotalLoopCount++;
|
||||
PlayerPrefs.SetInt(LoopCountKey, TotalLoopCount);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user