LoginMgr.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 BowRotateConvert bowRotateConvert = new BowRotateConvert();
  88. //游戏中是否固定镜头
  89. public bool bowCameraFixed = true;
  90. //设备校准引导-是否已经完成
  91. public bool deviceCalibrateGuideFinish = false;
  92. //游戏规则引导-是否已经完成(完成则保存对应的GameType)
  93. public HashSet<int> gameRuleGuideFinish = new HashSet<int>();
  94. private static UserSettings _ins;
  95. public static UserSettings ins {
  96. get {
  97. if (_ins == null) {
  98. string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
  99. try {
  100. _ins = JsonConvert.DeserializeObject<UserSettings>(dataStr);
  101. }
  102. catch (System.Exception) {}
  103. if (_ins == null) {
  104. _ins = new UserSettings();
  105. }
  106. }
  107. return _ins;
  108. }
  109. }
  110. public void Save() {
  111. PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
  112. }
  113. }
  114. /*
  115. 描述1
  116. 已知:
  117. 屏幕宽高比例w:h=16:9,屏幕尺寸s=60.11英寸,屏幕距离d=2.50米,实际指向右边树的角度为e=5.56°。
  118. 可知:
  119. 屏幕尺寸s1 = (s * 0.0254)米
  120. 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
  121. 结果:
  122. 向量(玩家->右边树)在屏幕上投影的长度比例q = tan(e) * d / unit
  123. */
  124. /*
  125. 描述2(适配各种尺寸的屏幕)
  126. 已知:
  127. 屏幕宽高比例w:h=16:9,屏幕尺寸s=(任意)英寸,屏幕距离d=(任意)米,游戏指向右边树的角度为r=27.30°。
  128. 借用描述1的结果q
  129. 可知:
  130. 屏幕尺寸s1 = (s * 0.0254)米
  131. 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
  132. 实际指向右边树的角度为e = atan(q * unit / d)
  133. 结果:
  134. 游戏转动角度:实际转动角度 = r / e
  135. */
  136. public class BowRotateConvert {
  137. public float screenSize = 60; //屏幕尺寸(英寸)
  138. public float screenDistance = 2.5f; //玩家距离屏幕多远(米)
  139. // 游戏旋转角度 : 实际旋转角度
  140. public float GetRate() {
  141. double w = 16;
  142. double h = 9;
  143. double s = Convert.ToDouble(screenSize);
  144. double d = Convert.ToDouble(screenDistance);
  145. double r = 27.3 / 180 * Math.PI;
  146. double q = get_q();
  147. double s1 = s * 0.0254;
  148. double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
  149. double e = Math.Atan(q * unit / d);
  150. return (float) (r / e);
  151. }
  152. private double get_q() {
  153. double w = 16;
  154. double h = 9;
  155. double s = 60.11;
  156. double d = 2.5;
  157. double e = 5.56 / 180 * Math.PI;
  158. double s1 = s * 0.0254;
  159. double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
  160. double q = Math.Tan(e) * d / unit;
  161. return q;
  162. }
  163. }