?
_Afra 的博客_会思考的猴子_CSDN博客-unity,Arduino,Processing领域博主
using UniRx;
using UnityEngine;
namespace QFramework.ZFP
{
// 控制层
public class ZFPGameManager : MonoSingleton<ZFPGameManager>
{
PlayerList Model;
private void Start()
{
// PlayerPrefs.DeleteAll();
StartGame();
}
// 结束游戏
public void EndGame()
{
UIKit.ClosePanel<ZFPUIPreparePanel>();
Model.Save();
StartGame();
}
// 开始游戏
public void StartGame()
{
Model = PlayerList.Load();
Model.m_ArrayPlayers.ForEach(_ => { Debug.Log(_.Name.ToString() + _.Score.ToString() + _.GameType); });
this.Delay(0.2f, () =>
{
UIKit.OpenPanel<ZFPUIPreparePanel>(new ZFPUIPreparePanelData()
{
Model = this.Model
});
});
}
}
}
?
using QFramework;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
public enum GAMETYPE
{
ZFP,
PXP
}
/// <summary>
/// Model数据层
/// </summary>
[System.Serializable]
public class PlayerList
{
public List<Player> m_ArrayPlayers = new List<Player>() {
new Player("张三",GAMETYPE.ZFP,0),
new Player("李四", GAMETYPE.ZFP,0),
new Player("王五", GAMETYPE.ZFP, 0)
};
// Json 反序列化(读取)
public static PlayerList Load()
{
var jsonContent = PlayerPrefs.GetString("PlayerListData");
//Debug.Log(jsonContent);
return jsonContent.IsNullOrEmpty() ? new PlayerList() : JsonUtility.FromJson<PlayerList>(jsonContent);
}
//Json 序列化(写入)
public void Save()
{
PlayerPrefs.SetString("PlayerListData", JsonUtility.ToJson(this));
}
}
[System.Serializable]
// 玩家类
public class Player
{
public StringReactiveProperty Name = new StringReactiveProperty(string.Empty);
public IntReactiveProperty Score = new IntReactiveProperty(0);
public ReactiveProperty<GAMETYPE> GameType = new ReactiveProperty<GAMETYPE>(GAMETYPE.ZFP);
// 初始化结构
public Player(string name, GAMETYPE gameType, int score)
{
this.Name.Value = name;
this.GameType.Value = gameType;
this.Score.Value = score;
}
}
?
|