using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using JCUnityLib; public class HRB_UserInfo { public int id; public int avatarID = 0; public string nickname = "Player"; public int gender = 1; public string birthday = ""; public string country = ""; public string state = ""; public string city = ""; public int weight = 80; public int waistLine = 100; public float lanWeightLoss = 0; public string planDateStart = DateTime.Now.ToString("yyyy-MM-dd"); public string planDateEnd = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd"); public int bmpMin = 120; private static HRB_UserInfo _current = new HRB_UserInfo(); public static HRB_UserInfo current { get => _current; set { _current = value; if (_current != null) _current.LoadLocalData(); } } void LoadLocalData() { weight = PlayerPrefs.GetInt(GetLocalDataKey("weight"), 80); waistLine = PlayerPrefs.GetInt(GetLocalDataKey("waistLine"), 100); lanWeightLoss = PlayerPrefs.GetFloat(GetLocalDataKey("lanWeightLoss"), 0); planDateStart = PlayerPrefs.GetString(GetLocalDataKey("planDateStart"), DateTime.Now.ToString("yyyy-MM-dd")); planDateEnd = PlayerPrefs.GetString(GetLocalDataKey("planDateEnd"), DateTime.Now.AddDays(30).ToString("yyyy-MM-dd")); bmpMin = PlayerPrefs.GetInt(GetLocalDataKey("bmpMin"), 120); } public void SaveLocalData() { PlayerPrefs.SetInt(GetLocalDataKey("weight"), weight); PlayerPrefs.SetInt(GetLocalDataKey("waistLine"), waistLine); PlayerPrefs.SetFloat(GetLocalDataKey("lanWeightLoss"), lanWeightLoss); PlayerPrefs.SetString(GetLocalDataKey("planDateStart"), planDateStart); PlayerPrefs.SetString(GetLocalDataKey("planDateEnd"), planDateEnd); PlayerPrefs.SetInt(GetLocalDataKey("bmpMin"), bmpMin); } string GetLocalDataKey(string propName) { return $"HRB_UserInfo_{id}_{propName}"; } public void Save(bool showTip = true) { CoroutineStarter.Start(HRB_Controller.Instance.saveUserInfo(this, (RequestResult res) => { Debug.Log(this.GetType().Name + "保存" + (res.code == 0 ? "成功" : "失败")); if (res.code == 0 && showTip) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("保存成功")); })); } }