HRB_UserInfo.cs 2.4 KB

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