LoginMgr.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. }
  32. public class UserInfo {
  33. public int id;
  34. public int avatarID = 0;
  35. public string nickname = "超级射手";
  36. public int gender = 1;
  37. public string phone = "";
  38. public string birthday = "";
  39. public string country = "";
  40. public string state = "";
  41. public string city = "";
  42. public int integral = 0;
  43. public int coin = 0;
  44. public int diamond = 1000;
  45. public List<PropInfo> bagList = new List<PropInfo>();
  46. public List<DeviceInfo> deviceList = new List<DeviceInfo>();
  47. //显示游戏最高分(不同距离分数独立)
  48. public Dictionary<string, float> timeLimitGameScores = new Dictionary<string, float>();
  49. //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数)
  50. public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
  51. public void Save()
  52. {
  53. try { UserComp.ins.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); }
  54. }
  55. public void SetChallengeLevelPass(int gameType, int level) {
  56. if (gameType != 3 && gameType != 4 && gameType != 5) return;
  57. if (challengeLevels.ContainsKey(gameType)) {
  58. if (level <= challengeLevels[gameType]) {
  59. return;
  60. }
  61. }
  62. challengeLevels.Remove(gameType);
  63. challengeLevels.Add(gameType, level);
  64. }
  65. public int GetChallengeLevelPass(int gameType) {
  66. if (challengeLevels.ContainsKey(gameType)) {
  67. return challengeLevels[gameType];
  68. }
  69. return 0;
  70. }
  71. }
  72. public class UserSettings {
  73. //打开BGM
  74. public bool openBGM = true;
  75. //打开音效
  76. public bool openEffect = true;
  77. //是否打开准心
  78. public bool openCrossHair = true;
  79. //射击难度
  80. public int shootLevel = 0;
  81. //游戏里的箭重,单位克
  82. public float actualArrowWeight = 20;
  83. //设备校准引导-是否已经完成
  84. public bool deviceCalibrateGuideFinish = false;
  85. //游戏规则引导-是否已经完成(完成则保存对应的GameType)
  86. public HashSet<int> gameRuleGuideFinish = new HashSet<int>();
  87. private static UserSettings _ins;
  88. public static UserSettings ins {
  89. get {
  90. if (_ins == null) {
  91. string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
  92. try {
  93. _ins = JsonConvert.DeserializeObject<UserSettings>(dataStr);
  94. }
  95. catch (System.Exception) {}
  96. if (_ins == null) {
  97. _ins = new UserSettings();
  98. }
  99. }
  100. return _ins;
  101. }
  102. }
  103. public void Save() {
  104. PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
  105. }
  106. }