| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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;
- }
- }
- 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<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 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();
- }
- }
- return _ins;
- }
- }
- public void Save() {
- PlayerPrefs.SetString("UserSettings", JsonConvert.SerializeObject(this));
- }
- }
|