|
|
@@ -1,12 +1,6 @@
|
|
|
using System;
|
|
|
-using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
-using UnityEngine.UI;
|
|
|
-using UnityEngine.SceneManagement;
|
|
|
-using UnityEngine.Networking;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
-using DG.Tweening;
|
|
|
using Newtonsoft.Json;
|
|
|
/* 登录管理者,用户数据定义和存储 */
|
|
|
public class LoginMgr : MonoBehaviour
|
|
|
@@ -14,141 +8,20 @@ public class LoginMgr : MonoBehaviour
|
|
|
[SerializeField] GameObject loginView;
|
|
|
[SerializeField] GameObject registerView;
|
|
|
[SerializeField] GameObject forgetPWD_View;
|
|
|
- [SerializeField] GameObject loginMode1;
|
|
|
- [SerializeField] GameObject loginMode2;
|
|
|
- [SerializeField] Sprite[] loginModeSprites;
|
|
|
- [SerializeField] GameObject loginInUser;
|
|
|
- [SerializeField] GameObject loginInPWD;
|
|
|
- [SerializeField] GameObject loginInCaptcha1;
|
|
|
- [SerializeField] GameObject loginInPhone;
|
|
|
- [SerializeField] GameObject loginInCode;
|
|
|
- [SerializeField] GameObject loginValidTime;
|
|
|
- [SerializeField] GameObject loginInCaptcha2;
|
|
|
- [SerializeField] GameObject registerInUser;
|
|
|
- [SerializeField] GameObject registerInPWD1;
|
|
|
- [SerializeField] GameObject registerInPWD2;
|
|
|
- [SerializeField] GameObject registerInNickname;
|
|
|
- [SerializeField] GameObject registerInGender;
|
|
|
- [SerializeField] Text loginTip;
|
|
|
- [SerializeField] Text registerTip;
|
|
|
- [SerializeField] Transform agreementTF;
|
|
|
|
|
|
public static UserInfo myUserInfo = new UserInfo();
|
|
|
static int userInfo_version = 1000;
|
|
|
|
|
|
- int loginMode = 1;
|
|
|
-
|
|
|
- void Awake()
|
|
|
- {
|
|
|
- TextAutoLanguage.Init();
|
|
|
-
|
|
|
- agreementTF.Find("TextA").GetComponent<Button>().onClick.AddListener(delegate() {
|
|
|
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
|
|
|
- o.GetComponent<AgreementView>().EnterUserAgreement();
|
|
|
- });
|
|
|
- agreementTF.Find("TextB").GetComponent<Button>().onClick.AddListener(delegate() {
|
|
|
- GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
|
|
|
- o.GetComponent<AgreementView>().EnterPrivacyAgreement();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- void Start()
|
|
|
- {
|
|
|
- SelectLoginMode(1);
|
|
|
- GameObject[] inputNodes = {loginInUser, loginInPWD, registerInUser, registerInPWD1, registerInPWD2};
|
|
|
- foreach (var inputNode in inputNodes)
|
|
|
- {
|
|
|
- InputField inputField = GetInputField(inputNode);
|
|
|
- inputField.onValueChanged.AddListener(delegate(string text) {
|
|
|
- Match match = new Regex("[^A-Za-z0-9]").Match(text);
|
|
|
- if (match.Success) {
|
|
|
- inputField.text = text.Replace(match.Value, "");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- IEnumerator GetCaptcha(CaptchaType type)
|
|
|
- {
|
|
|
- int code = UnityEngine.Random.Range(1000, 10000);
|
|
|
- UnityWebRequest uwr = new UnityWebRequest(CommonConfig.businessServerURI + "/api/createCaptcha?code=" + code, UnityWebRequest.kHttpVerbGET);
|
|
|
- uwr.downloadHandler = new DownloadHandlerTexture();
|
|
|
- yield return uwr.SendWebRequest();
|
|
|
- Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
|
|
|
- Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
|
|
- switch (type) {
|
|
|
- case CaptchaType.Login:
|
|
|
- loginInCaptcha1.transform.Find("CodeImage").GetComponent<Image>().sprite = sprite;
|
|
|
- captcha_Login = code;
|
|
|
- break;
|
|
|
- case CaptchaType.LoginPhone:
|
|
|
- loginInCaptcha2.transform.Find("CodeImage").GetComponent<Image>().sprite = sprite;
|
|
|
- captcha_LoginPhone = code;
|
|
|
- break;
|
|
|
- case CaptchaType.Register:
|
|
|
- captcha_Register = code;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- enum CaptchaType {
|
|
|
- Login, LoginPhone, Register
|
|
|
- }
|
|
|
- int captcha_Login = -222222222;
|
|
|
- int captcha_LoginPhone = -222222222;
|
|
|
- int captcha_Register = -222222222;
|
|
|
-
|
|
|
- InputField GetInputField(GameObject inputNode)
|
|
|
- {
|
|
|
- return inputNode.transform.Find("InputField").GetComponent<InputField>();
|
|
|
- }
|
|
|
-
|
|
|
- public void SelectLoginMode(int mode) {
|
|
|
- loginMode = mode;
|
|
|
- if (loginMode == 1)
|
|
|
- {
|
|
|
- loginMode1.GetComponent<Image>().sprite = loginModeSprites[1];
|
|
|
- loginMode2.GetComponent<Image>().sprite = loginModeSprites[0];
|
|
|
- loginInUser.SetActive(true);
|
|
|
- loginInPWD.SetActive(true);
|
|
|
- loginInCaptcha1.SetActive(true);
|
|
|
- loginInPhone.SetActive(false);
|
|
|
- loginInCode.SetActive(false);
|
|
|
- loginValidTime.SetActive(false);
|
|
|
- loginInCaptcha2.SetActive(false);
|
|
|
- if (captcha_Login < 0) {
|
|
|
- StartCoroutine(GetCaptcha(CaptchaType.Login));
|
|
|
- }
|
|
|
- }
|
|
|
- else if (loginMode == 2)
|
|
|
- {
|
|
|
- loginMode1.GetComponent<Image>().sprite = loginModeSprites[0];
|
|
|
- loginMode2.GetComponent<Image>().sprite = loginModeSprites[1];
|
|
|
- loginInUser.SetActive(false);
|
|
|
- loginInPWD.SetActive(false);
|
|
|
- loginInCaptcha1.SetActive(false);
|
|
|
- loginInPhone.SetActive(true);
|
|
|
- loginInCode.SetActive(true);
|
|
|
- loginValidTime.SetActive(true);
|
|
|
- loginInCaptcha2.SetActive(true);
|
|
|
- if (captcha_LoginPhone < 0) {
|
|
|
- StartCoroutine(GetCaptcha(CaptchaType.LoginPhone));
|
|
|
- }
|
|
|
- }
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(0);
|
|
|
- }
|
|
|
-
|
|
|
public void showRegisterView() {
|
|
|
loginView.SetActive(false);
|
|
|
registerView.SetActive(true);
|
|
|
forgetPWD_View.SetActive(false);
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(0);
|
|
|
}
|
|
|
|
|
|
public void showLoginView() {
|
|
|
loginView.SetActive(true);
|
|
|
registerView.SetActive(false);
|
|
|
forgetPWD_View.SetActive(false);
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(0);
|
|
|
}
|
|
|
|
|
|
public void showForgetPWD_View() {
|
|
|
@@ -157,165 +30,13 @@ public class LoginMgr : MonoBehaviour
|
|
|
forgetPWD_View.SetActive(true);
|
|
|
}
|
|
|
|
|
|
- public void login() {
|
|
|
- if (loginMode == 1) {
|
|
|
- LoginNormal();
|
|
|
- } else if (loginMode == 2) {
|
|
|
- LoginByPhone();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void LoginNormal() {
|
|
|
- InputField user = GetInputField(loginInUser);
|
|
|
- if (user.text.Trim().Length == 0) {
|
|
|
- loginTip.color = Color.yellow;
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(41);
|
|
|
- return;
|
|
|
- }
|
|
|
- InputField pwd = GetInputField(loginInPWD);
|
|
|
- if (pwd.text.Trim().Length == 0) {
|
|
|
- loginTip.color = Color.yellow;
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(42);
|
|
|
- return;
|
|
|
- }
|
|
|
- // InputField captcha = GetInputField(loginInCaptcha1);
|
|
|
- // if (captcha.text.Trim().Length == 0) {
|
|
|
- // loginTip.color = Color.yellow;
|
|
|
- // loginTip.GetComponent<TextAutoLanguage>().SetText(42);
|
|
|
- // return;
|
|
|
- // }
|
|
|
- UserInfos userInfos = GetUserInfos();
|
|
|
- foreach (var userInfo in userInfos.list)
|
|
|
- {
|
|
|
- if (userInfo.user == user.text) {
|
|
|
- if (userInfo.pwd == pwd.text) {
|
|
|
- loginTip.color = Color.green;
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(43);
|
|
|
- myUserInfo = userInfo;
|
|
|
- PlayerPrefs.SetString("LoginRecord_User_" + userInfo_version, userInfo.user);
|
|
|
- PlayerPrefs.SetString("LoginRecord_PWD_" + userInfo_version, userInfo.pwd);
|
|
|
- SceneManager.LoadScene("Home", LoadSceneMode.Single);
|
|
|
- } else {
|
|
|
- loginTip.color = Color.red;
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(44);
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- loginTip.color = Color.yellow;
|
|
|
- loginTip.GetComponent<TextAutoLanguage>().SetText(45);
|
|
|
- }
|
|
|
-
|
|
|
- void LoginByPhone() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void Register()
|
|
|
- {
|
|
|
- InputField user = GetInputField(registerInUser);
|
|
|
- if (user.text.Length < 6) {
|
|
|
- registerTip.color = Color.red;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(46);
|
|
|
- return;
|
|
|
- }
|
|
|
- InputField pwd1 = GetInputField(registerInPWD1);
|
|
|
- if (pwd1.text.Length < 6) {
|
|
|
- registerTip.color = Color.red;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(47);
|
|
|
- return;
|
|
|
- }
|
|
|
- InputField pwd2 = GetInputField(registerInPWD2);
|
|
|
- if (pwd1.text != pwd2.text) {
|
|
|
- registerTip.color = Color.red;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(48);
|
|
|
- return;
|
|
|
- }
|
|
|
- InputField nickname = GetInputField(registerInNickname);
|
|
|
- if (nickname.text.Trim().Length == 0) {
|
|
|
- registerTip.color = Color.yellow;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(49);
|
|
|
- return;
|
|
|
- }
|
|
|
- UserInfos userInfos = GetUserInfos();
|
|
|
- foreach (var userInfo in userInfos.list)
|
|
|
- {
|
|
|
- if (userInfo.user == user.text) {
|
|
|
- registerTip.color = Color.yellow;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(50);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- UserInfo userInfo1 = new UserInfo();
|
|
|
- userInfo1.user = user.text;
|
|
|
- userInfo1.pwd = pwd1.text;
|
|
|
- userInfo1.nickname = nickname.text;
|
|
|
- Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
|
|
|
- for (int i = 0; i < toggleGroup.childCount; i++) {
|
|
|
- if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
|
|
|
- userInfo1.gender = i == 0 ? 1 : 2;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- userInfos.list.Add(userInfo1);
|
|
|
- SetUserInfos(userInfos);
|
|
|
- registerTip.color = Color.green;
|
|
|
- registerTip.GetComponent<TextAutoLanguage>().SetText(51);
|
|
|
- //自动跳转到登录并填写登录信息
|
|
|
- GetInputField(loginInUser).text = userInfo1.user;
|
|
|
- GetInputField(loginInPWD).text = userInfo1.pwd;
|
|
|
- SelectLoginMode(1);
|
|
|
- Invoke("showLoginView", 0.5f);
|
|
|
- }
|
|
|
-
|
|
|
- public static UserInfos GetUserInfos() {
|
|
|
- string userInfosStr = PlayerPrefs.GetString("UserInfos_" + userInfo_version, "");
|
|
|
- return userInfosStr.Length == 0 ? new UserInfos(): JsonConvert.DeserializeObject<UserInfos>(userInfosStr);
|
|
|
- }
|
|
|
-
|
|
|
- public static void SetUserInfos(UserInfos userInfos) {
|
|
|
- PlayerPrefs.SetString("UserInfos_" + userInfo_version, JsonConvert.SerializeObject(userInfos));
|
|
|
- }
|
|
|
-
|
|
|
- public static void SaveUserInfo(UserInfo userInfo) {
|
|
|
- UserInfos userInfos = GetUserInfos();
|
|
|
- for(int i = 0; i < userInfos.list.Count; i++) {
|
|
|
- UserInfo u = userInfos.list[i];
|
|
|
- if (u.user == userInfo.user) {
|
|
|
- userInfos.list[i] = userInfo;
|
|
|
- }
|
|
|
- }
|
|
|
- SetUserInfos(userInfos);
|
|
|
- myUserInfo = userInfo;
|
|
|
- }
|
|
|
-
|
|
|
- public static bool CheckAutoLogin()
|
|
|
- {
|
|
|
- string username = PlayerPrefs.GetString("LoginRecord_User_" + userInfo_version, "");
|
|
|
- string password = PlayerPrefs.GetString("LoginRecord_PWD_" + userInfo_version, "");
|
|
|
- UserInfos userInfos = GetUserInfos();
|
|
|
- foreach (var userInfo in userInfos.list)
|
|
|
- {
|
|
|
- if (userInfo.user == username) {
|
|
|
- if (userInfo.pwd == password) {
|
|
|
- myUserInfo = userInfo;
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ public static bool CheckAutoLogin() {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-public class UserInfos {
|
|
|
- public List<UserInfo> list = new List<UserInfo>();
|
|
|
-}
|
|
|
-
|
|
|
-[Serializable]
|
|
|
public class UserInfo {
|
|
|
public int id;
|
|
|
public string user = "";
|
|
|
- public string pwd = "";
|
|
|
public int avatarID = 0;
|
|
|
public string nickname = "超级射手";
|
|
|
public int gender = 0;
|
|
|
@@ -334,7 +55,7 @@ public class UserInfo {
|
|
|
public Dictionary<int, int> challengeLevels = new Dictionary<int, int>();
|
|
|
public void Save()
|
|
|
{
|
|
|
- LoginMgr.SaveUserInfo(this);
|
|
|
+
|
|
|
}
|
|
|
public void SetChallengeLevelPass(int gameType, int level) {
|
|
|
if (gameType != 3 && gameType != 4 && gameType != 5) return;
|