소스 검색

登录功能

lvjincheng 4 년 전
부모
커밋
3cbc2b3bec

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 727 - 112
Assets/BowArrow/Scenes/Login.unity


+ 2 - 281
Assets/BowArrow/Scripts/Manager/LoginMgr.cs

@@ -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;

+ 1 - 1
Assets/BowArrow/Scripts/Network/SocketPlayer.cs

@@ -36,8 +36,8 @@ public class SocketPlayer : JC.SocketIO.SocketIOClient
     public bool openInGameScene;
     //测试阶段,用这个
     public void onLoadForTest(int id, string nickname, int avatarID) {
-        LoginMgr.myUserInfo.id = id;
         if (openInGameScene) {
+            LoginMgr.myUserInfo.id = id;
             LoginMgr.myUserInfo.nickname = nickname;
             LoginMgr.myUserInfo.avatarID = avatarID;
         }

+ 1 - 1
Assets/JC/Singleton.cs

@@ -3,7 +3,7 @@
 // </summary>
 public class Singleton<T> where T : class, new()
 {
-    public static T _ins;
+    private static T _ins;
     public static T ins
     {
         get

+ 1 - 1
Assets/JC/Untiy/Picker/DatePicker/DatePickerCanvas.prefab

@@ -1241,7 +1241,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 0.6509804, g: 0.6509804, b: 0.6509804, a: 0.39215687}
+  m_Color: {r: 0, g: 0, b: 0, a: 0.60784316}
   m_RaycastTarget: 1
   m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1

+ 1 - 1
Assets/JC/Untiy/Picker/LocationPicker/LocationPickerCanvas.prefab

@@ -968,7 +968,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 0.6509804, g: 0.6509804, b: 0.6509804, a: 0.39215687}
+  m_Color: {r: 0, g: 0, b: 0, a: 0.60784316}
   m_RaycastTarget: 1
   m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1

+ 49 - 0
Assets/JC/Untiy/Picker/LocationPicker/LocationPickerGroup.cs

@@ -81,6 +81,55 @@ namespace JC.Unity.Picker {
         //         locationInfo.CountryRegionIndex++;
         //     }
         // }
+        public Tuple<string, string, string> ParseNameByCode(string countryCode, string stateCode, string cityCode) {
+            string countryName = "";
+            string stateName = "";
+            string cityName = "";
+            XmlNodeList stateNodeList = null;
+            XmlNodeList cityNodeList = null;
+            foreach (var countryNode in locationParser.CountryRegionList) {
+                if (countryNode.Attributes["Code"].Value == countryCode) {
+                    countryName = countryNode.Attributes["Name"].Value;
+                    stateNodeList = countryNode.SelectNodes("State");
+                    break;
+                }
+            }
+            if (stateNodeList != null) {
+                for (int i = 0; i < stateNodeList.Count; i++) {
+                    XmlNode stateNode = stateNodeList[i];
+                    XmlAttribute CodeAtb = stateNode.Attributes["Code"];
+                    if (CodeAtb != null) {
+                        if (stateCode == CodeAtb.Value) {
+                            XmlAttribute NameAtb = stateNode.Attributes["Name"];
+                            if (NameAtb != null) {
+                                stateName = NameAtb.Value;
+                                cityNodeList = stateNode.SelectNodes("City");
+                                break;
+                            }
+                        }
+                    } else if (CodeAtb == null && string.IsNullOrEmpty(stateCode)) {
+                        cityNodeList = stateNode.SelectNodes("City");
+                        break;
+                    }
+                }
+            }
+            if (cityNodeList != null) {
+                for (int i = 0; i < cityNodeList.Count; i++) {
+                    XmlNode cityNode = cityNodeList[i];
+                    XmlAttribute CodeAtb = cityNode.Attributes["Code"];
+                    if (CodeAtb != null) {
+                        if (cityCode == CodeAtb.Value) {
+                            XmlAttribute NameAtb = cityNode.Attributes["Name"];
+                            if (NameAtb != null) {
+                                cityName = NameAtb.Value;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+            return new Tuple<string, string, string>(countryName, stateName, cityName);
+        }
     }
     public class LocationParser {
         public List<XmlNode> CountryRegionList = new List<XmlNode>();

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.