HRB_UserInfo.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using JCUnityLib;
  6. public class HRB_UserInfo
  7. {
  8. public int id;
  9. public int avatarID = 0;
  10. public string nickname = "Player";
  11. public int gender = 1;
  12. public string birthday = "";
  13. public string country = "";
  14. public string state = "";
  15. public string city = "";
  16. public int weight = 80;
  17. public int waistLine = 100;
  18. public float lanWeightLoss = 0;
  19. public string planDateStart = DateTime.Now.ToString("yyyy-MM-dd");
  20. public string planDateEnd = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd");
  21. public int bmpMin = 120;
  22. private static HRB_UserInfo _current = new HRB_UserInfo();
  23. public static HRB_UserInfo current
  24. {
  25. get => _current;
  26. set
  27. {
  28. _current = value;
  29. if (_current != null) _current.LoadLocalData();
  30. }
  31. }
  32. void LoadLocalData()
  33. {
  34. weight = PlayerPrefs.GetInt(GetLocalDataKey("weight"), 80);
  35. waistLine = PlayerPrefs.GetInt(GetLocalDataKey("waistLine"), 100);
  36. lanWeightLoss = PlayerPrefs.GetFloat(GetLocalDataKey("lanWeightLoss"), 0);
  37. planDateStart = PlayerPrefs.GetString(GetLocalDataKey("planDateStart"), DateTime.Now.ToString("yyyy-MM-dd"));
  38. planDateEnd = PlayerPrefs.GetString(GetLocalDataKey("planDateEnd"), DateTime.Now.AddDays(30).ToString("yyyy-MM-dd"));
  39. bmpMin = PlayerPrefs.GetInt(GetLocalDataKey("bmpMin"), 120);
  40. }
  41. public void SaveLocalData()
  42. {
  43. PlayerPrefs.SetInt(GetLocalDataKey("weight"), weight);
  44. PlayerPrefs.SetInt(GetLocalDataKey("waistLine"), waistLine);
  45. PlayerPrefs.SetFloat(GetLocalDataKey("lanWeightLoss"), lanWeightLoss);
  46. PlayerPrefs.SetString(GetLocalDataKey("planDateStart"), planDateStart);
  47. PlayerPrefs.SetString(GetLocalDataKey("planDateEnd"), planDateEnd);
  48. PlayerPrefs.SetInt(GetLocalDataKey("bmpMin"), bmpMin);
  49. }
  50. string GetLocalDataKey(string propName)
  51. {
  52. return $"HRB_UserInfo_{id}_{propName}";
  53. }
  54. public void Save(bool showTip = true)
  55. {
  56. CoroutineStarter.Start(HRB_Controller.Instance.saveUserInfo(this, (RequestResult res) => {
  57. Debug.Log(this.GetType().Name + "保存" + (res.code == 0 ? "成功" : "失败"));
  58. if (res.code == 0 && showTip) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("保存成功"));
  59. }));
  60. }
  61. }