LoginMgr.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. AgreenmentOption.ins.gameObject.SetActive(true);
  17. }
  18. public void showLoginView() {
  19. loginView.SetActive(true);
  20. registerView.SetActive(false);
  21. forgetPWD_View.SetActive(false);
  22. AgreenmentOption.ins.gameObject.SetActive(true);
  23. }
  24. public void showForgetPWD_View() {
  25. loginView.SetActive(false);
  26. registerView.SetActive(false);
  27. forgetPWD_View.SetActive(true);
  28. AgreenmentOption.ins.gameObject.SetActive(false);
  29. }
  30. public const string LoginTokenKey = "LoginToken";
  31. public static bool HasToken() {
  32. string loginToken = PlayerPrefs.GetString(LoginMgr.LoginTokenKey, "");
  33. return string.IsNullOrEmpty(loginToken) ? false : true;
  34. }
  35. void Awake() {
  36. transform.Find("AgreementPopup").gameObject.SetActive(true);
  37. }
  38. }
  39. public class UserInfo {
  40. public int id;
  41. public int avatarID = 0;
  42. public string nickname = "超级射手";
  43. public int gender = 1;
  44. public string phone = "";
  45. public string birthday = "";
  46. public string country = "";
  47. public string state = "";
  48. public string city = "";
  49. public int integral = 0;
  50. public int coin = 0;
  51. public int diamond = 1000;
  52. public string mac = "";
  53. public List<PropInfo> bagList = new List<PropInfo>();
  54. public List<DeviceInfo> deviceList = new List<DeviceInfo>();
  55. //显示游戏最高分(不同距离分数独立)
  56. public Dictionary<string, float> timeLimitGameScores = new Dictionary<string, float>();
  57. //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数)
  58. public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
  59. public string guideRecord = "";
  60. public void Save()
  61. {
  62. try { UserComp.Instance.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); }
  63. }
  64. public void SetChallengeLevelPass(int gameType, int level) {
  65. if (gameType != 3 && gameType != 4 && gameType != 5) return;
  66. if (challengeLevels.ContainsKey(gameType)) {
  67. if (level <= challengeLevels[gameType]) {
  68. return;
  69. }
  70. }
  71. challengeLevels.Remove(gameType);
  72. challengeLevels.Add(gameType, level);
  73. }
  74. public int GetChallengeLevelPass(int gameType) {
  75. if (challengeLevels.ContainsKey(gameType)) {
  76. return challengeLevels[gameType];
  77. }
  78. return 0;
  79. }
  80. //判断引导是否完成(服务端保存)
  81. //index0: 新手引导NewUserGuide
  82. public bool IsGuideFinish(int index) {
  83. if (index == 0) {
  84. return PlayerPrefs.GetInt("NewUserGuideFinish_" + LoginMgr.myUserInfo.id, 0) == 1;
  85. }
  86. char[] chars = guideRecord.ToCharArray();
  87. if (index < chars.Length) {
  88. return chars[index] == '1';
  89. }
  90. return false;
  91. }
  92. public void SaveGuideFinish(int index) {
  93. if (index == 0) {
  94. PlayerPrefs.SetInt("NewUserGuideFinish_" + LoginMgr.myUserInfo.id, 1);
  95. return;
  96. }
  97. char[] chars = guideRecord.ToCharArray();
  98. if (index < chars.Length) {
  99. if (chars[index] == '1') return;
  100. chars[index] = '1';
  101. } else {
  102. int newLen = index + 1;
  103. char[] newChars = new char[newLen];
  104. for (int i = 0; i < newLen; i++) {
  105. newChars[i] = i < chars.Length ? chars[i] : '0';
  106. }
  107. newChars[index] = '1';
  108. chars = newChars;
  109. }
  110. this.guideRecord = string.Join("", chars);
  111. UserPlayer.ins?.call("userComp.saveGuideRecord", this.guideRecord);
  112. }
  113. }
  114. public class UserSettings {
  115. //打开BGM
  116. public bool openBGM = true;
  117. //打开音效
  118. public bool openEffect = true;
  119. //是否打开准心
  120. public bool openCrossHair = true;
  121. //射击难度
  122. public int shootLevel = 0;
  123. //游戏里的箭重,单位克
  124. public float actualArrowWeight = 20;
  125. //弓箭旋转转化
  126. public BowRotateConvert bowRotateConvert = new BowRotateConvert();
  127. //游戏中是否固定镜头
  128. public bool bowCameraFixed = true;
  129. //训练模式
  130. public bool trainMode = false;
  131. //设备校准引导-是否已经完成
  132. public bool deviceCalibrateGuideFinish = false;
  133. //游戏规则引导-是否已经完成(完成则保存对应的GameType)
  134. public HashSet<int> gameRuleGuideFinish = new HashSet<int>();
  135. private static UserSettings _ins;
  136. public static UserSettings ins {
  137. get {
  138. if (_ins == null) {
  139. string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
  140. try {
  141. _ins = JsonConvert.DeserializeObject<UserSettings>(dataStr);
  142. }
  143. catch (System.Exception) {}
  144. if (_ins == null) {
  145. _ins = new UserSettings();
  146. }
  147. if (CommonConfig.SpecialVersion1) {
  148. if (PlayerPrefs.GetInt("sv1_UserSettings_2", 0) == 0) {
  149. PlayerPrefs.SetInt("sv1_UserSettings_2", 1);
  150. UserSettings us = _ins;
  151. us.bowRotateConvert.screenSize = 60;
  152. us.bowRotateConvert.screenDistance = 1.5f;
  153. us.Save();
  154. }
  155. }
  156. }
  157. return _ins;
  158. }
  159. }
  160. public void Save() {
  161. PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
  162. }
  163. }
  164. /*
  165. 描述1
  166. 已知:
  167. 屏幕宽高比例w:h=16:9,屏幕尺寸s=60.11英寸,屏幕距离d=2.50米,实际指向右边树的角度为e=5.56°。
  168. 可知:
  169. 屏幕尺寸s1 = (s * 0.0254)米
  170. 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
  171. 结果:
  172. 向量(玩家->右边树)在屏幕上投影的长度比例q = tan(e) * d / unit
  173. */
  174. /*
  175. 描述2(适配各种尺寸的屏幕)
  176. 已知:
  177. 屏幕宽高比例w:h=16:9,屏幕尺寸s=(任意)英寸,屏幕距离d=(任意)米,游戏指向右边树的角度为r=27.30°。
  178. 借用描述1的结果q
  179. 可知:
  180. 屏幕尺寸s1 = (s * 0.0254)米
  181. 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2
  182. 实际指向右边树的角度为e = atan(q * unit / d)
  183. 结果:
  184. 游戏转动角度:实际转动角度 = r / e
  185. */
  186. public class BowRotateConvert {
  187. public float screenSize = 60; //屏幕尺寸(英寸)
  188. public float screenDistance = 2.5f; //玩家距离屏幕多远(米)
  189. [NonSerialized] public float fieldOfView = 25;
  190. //获取建议的屏幕距离
  191. public float GetAdviseScreenDistance() {
  192. float w = 16;
  193. float h = 9;
  194. float s1 = screenSize * 0.0254f;
  195. float unit = s1 / Mathf.Sqrt(w * w + h * h);
  196. float screenHeight = 9 * unit;
  197. return screenHeight * 0.5f / Mathf.Tan(fieldOfView / 2 / 180 * Mathf.PI);
  198. }
  199. // 游戏旋转角度 : 实际旋转角度 (这个版本丢弃掉这个功能-所以直接返回1)
  200. public float GetRate() {
  201. return 1;
  202. }
  203. // 游戏旋转角度 : 实际旋转角度
  204. // public float GetRate() {
  205. // double w = 16;
  206. // double h = 9;
  207. // double s = Convert.ToDouble(screenSize);
  208. // double d = Convert.ToDouble(screenDistance);
  209. // double r = 27.3 / 180 * Math.PI;
  210. // double q = get_q();
  211. // double s1 = s * 0.0254;
  212. // double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
  213. // double e = Math.Atan(q * unit / d);
  214. // return (float) (r / e);
  215. // }
  216. // private double get_q() {
  217. // double w = 16;
  218. // double h = 9;
  219. // double s = 60.11;
  220. // double d = 2.5;
  221. // double e = 5.56 / 180 * Math.PI;
  222. // double s1 = s * 0.0254;
  223. // double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
  224. // double q = Math.Tan(e) * d / unit;
  225. // return q;
  226. // }
  227. }