using System; using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; /* 登录管理者,用户数据定义和存储 */ public class LoginMgr : MonoBehaviour { [SerializeField] GameObject loginView; [SerializeField] GameObject registerView; [SerializeField] GameObject forgetPWD_View; public static UserInfo myUserInfo = new UserInfo(); public void showRegisterView() { loginView.SetActive(false); registerView.SetActive(true); forgetPWD_View.SetActive(false); AgreenmentOption.ins.gameObject.SetActive(true); } public void showLoginView() { loginView.SetActive(true); registerView.SetActive(false); forgetPWD_View.SetActive(false); AgreenmentOption.ins.gameObject.SetActive(true); } public void showForgetPWD_View() { loginView.SetActive(false); registerView.SetActive(false); forgetPWD_View.SetActive(true); AgreenmentOption.ins.gameObject.SetActive(false); } public static bool HasToken() { string IdAndToken = PlayerPrefs.GetString("IdAndToken", ""); return string.IsNullOrEmpty(IdAndToken) ? false : true; } void Awake() { transform.Find("AgreementPopup").gameObject.SetActive(true); } } public class UserInfo { public int id; public int avatarID = 0; public string nickname = "超级射手"; public int gender = 1; public string phone = ""; public string birthday = ""; public string country = ""; public string state = ""; public string city = ""; public int integral = 0; public int coin = 0; public int diamond = 1000; public string mac = ""; public List bagList = new List(); public List deviceList = new List(); //显示游戏最高分(不同距离分数独立) public Dictionary timeLimitGameScores = new Dictionary(); //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数) public Dictionary challengeLevels = new Dictionary(); public void Save() { try { UserComp.ins.saveUserInfo(this); } catch (System.Exception e) { Debug.LogError(e.Message); } } public void SetChallengeLevelPass(int gameType, int level) { if (gameType != 3 && gameType != 4 && gameType != 5) return; if (challengeLevels.ContainsKey(gameType)) { if (level <= challengeLevels[gameType]) { return; } } challengeLevels.Remove(gameType); challengeLevels.Add(gameType, level); } public int GetChallengeLevelPass(int gameType) { if (challengeLevels.ContainsKey(gameType)) { return challengeLevels[gameType]; } return 0; } } public class UserSettings { //打开BGM public bool openBGM = true; //打开音效 public bool openEffect = true; //是否打开准心 public bool openCrossHair = true; //射击难度 public int shootLevel = 0; //游戏里的箭重,单位克 public float actualArrowWeight = 20; //弓箭旋转转化 public BowRotateConvert bowRotateConvert = new BowRotateConvert(); //游戏中是否固定镜头 public bool bowCameraFixed = true; //训练模式 public bool trainMode = false; //设备校准引导-是否已经完成 public bool deviceCalibrateGuideFinish = false; //游戏规则引导-是否已经完成(完成则保存对应的GameType) public HashSet gameRuleGuideFinish = new HashSet(); private static UserSettings _ins; public static UserSettings ins { get { if (_ins == null) { string dataStr = PlayerPrefs.GetString("UserSettings", "{}"); try { _ins = JsonConvert.DeserializeObject(dataStr); } catch (System.Exception) {} if (_ins == null) { _ins = new UserSettings(); } if (CommonConfig.SpecialVersion1) { if (PlayerPrefs.GetInt("sv1_UserSettings_1", 0) == 0) { PlayerPrefs.SetInt("sv1_UserSettings_1", 1); UserSettings us = _ins; us.bowRotateConvert.screenSize = 60; us.bowRotateConvert.screenDistance = 0.5f; us.Save(); } } } return _ins; } } public void Save() { PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this)); } } /* 描述1 已知: 屏幕宽高比例w:h=16:9,屏幕尺寸s=60.11英寸,屏幕距离d=2.50米,实际指向右边树的角度为e=5.56°。 可知: 屏幕尺寸s1 = (s * 0.0254)米 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2 结果: 向量(玩家->右边树)在屏幕上投影的长度比例q = tan(e) * d / unit */ /* 描述2(适配各种尺寸的屏幕) 已知: 屏幕宽高比例w:h=16:9,屏幕尺寸s=(任意)英寸,屏幕距离d=(任意)米,游戏指向右边树的角度为r=27.30°。 借用描述1的结果q 可知: 屏幕尺寸s1 = (s * 0.0254)米 屏幕单位大小为unit,关系式(w*unit)^2 + (h*unit)^2 = s1^2 实际指向右边树的角度为e = atan(q * unit / d) 结果: 游戏转动角度:实际转动角度 = r / e */ public class BowRotateConvert { public float screenSize = 60; //屏幕尺寸(英寸) public float screenDistance = 2.5f; //玩家距离屏幕多远(米) // 游戏旋转角度 : 实际旋转角度 public float GetRate() { double w = 16; double h = 9; double s = Convert.ToDouble(screenSize); double d = Convert.ToDouble(screenDistance); double r = 27.3 / 180 * Math.PI; double q = get_q(); double s1 = s * 0.0254; double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2))); double e = Math.Atan(q * unit / d); return (float) (r / e); } private double get_q() { double w = 16; double h = 9; double s = 60.11; double d = 2.5; double e = 5.56 / 180 * Math.PI; double s1 = s * 0.0254; double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2))); double q = Math.Tan(e) * d / unit; return q; } }