| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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<PropInfo> bagList = new List<PropInfo>();
- public List<DeviceInfo> deviceList = new List<DeviceInfo>();
- //显示游戏最高分(不同距离分数独立)
- public Dictionary<string, float> timeLimitGameScores = new Dictionary<string, float>();
- //闯关记录(gameType:通关数)(野兔、野鸡、野狼的通关数)
- public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
- 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<int> gameRuleGuideFinish = new HashSet<int>();
- private static UserSettings _ins;
- public static UserSettings ins {
- get {
- if (_ins == null) {
- string dataStr = PlayerPrefs.GetString("UserSettings", "{}");
- try {
- _ins = JsonConvert.DeserializeObject<UserSettings>(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;
- }
- }
|