LoginMgr.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Newtonsoft.Json;
  5. /* 登录管理者,用户数据定义和存储 */
  6. public class LoginMgr : MonoBehaviour
  7. {
  8. [SerializeField] GameObject loginView;
  9. [SerializeField] GameObject registerView;
  10. [SerializeField] GameObject forgetPWD_View;
  11. public static UserInfo myUserInfo = new UserInfo();
  12. public void showRegisterView() {
  13. loginView.SetActive(false);
  14. registerView.SetActive(true);
  15. forgetPWD_View.SetActive(false);
  16. }
  17. public void showLoginView() {
  18. loginView.SetActive(true);
  19. registerView.SetActive(false);
  20. forgetPWD_View.SetActive(false);
  21. }
  22. public void showForgetPWD_View() {
  23. loginView.SetActive(false);
  24. registerView.SetActive(false);
  25. forgetPWD_View.SetActive(true);
  26. }
  27. public static bool HasToken() {
  28. string IdAndToken = PlayerPrefs.GetString("IdAndToken", "");
  29. return string.IsNullOrEmpty(IdAndToken) ? false : true;
  30. }
  31. void Awake() {
  32. transform.Find("AgreementPopup").gameObject.SetActive(true);
  33. }
  34. }
  35. public class UserInfo {
  36. public int id;
  37. public int avatarID = 0;
  38. public string nickname = "超级射手";
  39. public int gender = 1;
  40. public string phone = "";
  41. public string birthday = "";
  42. public string country = "";
  43. public string state = "";
  44. public string city = "";
  45. public int integral = 0;
  46. public int coin = 0;
  47. public int diamond = 1000;
  48. public List<PropInfo> bagList = new List<PropInfo>();
  49. public List<DeviceInfo> deviceList = new List<DeviceInfo>();
  50. //显示游戏最高分(不同距离分数独立)
  51. public Dictionary<string, float> timeLimitGameScores = new Dictionary<string, float>();
  52. //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数)
  53. public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
  54. public void Save()
  55. {
  56. try { UserComp.ins.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); }
  57. }
  58. public void SetChallengeLevelPass(int gameType, int level) {
  59. if (gameType != 3 && gameType != 4 && gameType != 5) return;
  60. if (challengeLevels.ContainsKey(gameType)) {
  61. if (level <= challengeLevels[gameType]) {
  62. return;
  63. }
  64. }
  65. challengeLevels.Remove(gameType);
  66. challengeLevels.Add(gameType, level);
  67. }
  68. public int GetChallengeLevelPass(int gameType) {
  69. if (challengeLevels.ContainsKey(gameType)) {
  70. return challengeLevels[gameType];
  71. }
  72. return 0;
  73. }
  74. }
  75. public class UserSettings {
  76. //打开BGM
  77. public bool openBGM = true;
  78. //打开音效
  79. public bool openEffect = true;
  80. //是否打开准心
  81. public bool openCrossHair = true;
  82. //射击难度
  83. public int shootLevel = 0;
  84. //游戏里的箭重,单位克
  85. public float actualArrowWeight = 20;
  86. //设备校准引导-是否已经完成
  87. public bool deviceCalibrateGuideFinish = false;
  88. //游戏规则引导-是否已经完成(完成则保存对应的GameType)
  89. public HashSet<int> gameRuleGuideFinish = new HashSet<int>();
  90. private static UserSettings _ins;
  91. public static UserSettings ins {
  92. get {
  93. if (_ins == null) {
  94. string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
  95. try {
  96. _ins = JsonConvert.DeserializeObject<UserSettings>(dataStr);
  97. }
  98. catch (System.Exception) {}
  99. if (_ins == null) {
  100. _ins = new UserSettings();
  101. }
  102. }
  103. return _ins;
  104. }
  105. }
  106. public void Save() {
  107. PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
  108. }
  109. }