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); } public void showLoginView() { loginView.SetActive(true); registerView.SetActive(false); forgetPWD_View.SetActive(false); } public void showForgetPWD_View() { loginView.SetActive(false); registerView.SetActive(false); forgetPWD_View.SetActive(true); } 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 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 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(); } } return _ins; } } public void Save() { PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this)); } }