123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- using LitJson;
- using SC.XR.Unity;
- using ShadowStudio.Mgr;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using XRTool.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- using static SC.XR.Unity.SCInputField;
- using static ScenesManager;
- using static ShowLogin;
- namespace ShadowStudio.UI
- {
- [RequireComponent(typeof(WorldDlg))]
-
-
-
- public class LoginDlg : MonoBehaviour
- {
- private SCInputField userInputField;
- private SCInputField passwordInputField;
- private Button loginBtn;
- private Toggle remberToggle;
- private GameObject verifyObj;
- private SCInputField verifyInputField;
- private RawImage verifyTexture;
- private Button verifyTextureBtn;
- private bool isRemberUserAndPass;
- public bool isLock;
- private Text userRemind;
- private Text passwordRemind;
- private Text vcodeRemind;
- private Button phoneNumLoginBtn;
- public GameObject user;
- public GameObject PassBt;
- WorldDlg dlg;
- public GameObject AccountLoginObj;
- public GameObject PhoneLoginObj;
- private void Awake()
- {
- dlg = GetComponent<WorldDlg>();
- userInputField = dlg.GetChild<SCInputField>("AccountLoginObj/UIRoot/UserInputField");
- passwordInputField = dlg.GetChild<SCInputField>("AccountLoginObj/UIRoot/PasswordInputField");
- loginBtn = dlg.GetChild<Button>("AccountLoginObj/FullUIRoot/LoginBtn");
- remberToggle = dlg.GetChild<Toggle>("AccountLoginObj/UIRoot/RemberToggle_CheckBox");
- remberToggle.onValueChanged.AddListener(ClickOnToggle);
- verifyObj = dlg.GetChild<Transform>("AccountLoginObj/UIRoot/VerifyObj").gameObject;
- verifyInputField = dlg.GetChild<SCInputField>("AccountLoginObj/UIRoot/VerifyObj/VerifyInputField");
- verifyTexture = dlg.GetChild<RawImage>("AccountLoginObj/UIRoot/VerifyObj/VerifyTexture");
- verifyTextureBtn = dlg.GetBreadthChild<Button>("VerifyTextureBtn");
- verifyTextureBtn.onClick.AddListener(OnClickChangeTex);
- loginBtn.onClick.AddListener(OnClickLogin);
- userInputField.onEndEdit.AddListener(InputUserEnd);
- userInputField.onValueChanged.AddListener(UserValueChanged);
- passwordInputField.onEndEdit.AddListener(InputPassEnd);
- passwordInputField.onValueChanged.AddListener(PassValueChanged);
- verifyInputField.onEndEdit.AddListener(InputVerifyEnd);
- verifyInputField.onValueChanged.AddListener(VerifyValueChanged);
- userRemind = dlg.GetChild<Text>("AccountLoginObj/UIRoot/ErrorRemind/UserRemind");
- passwordRemind = dlg.GetChild<Text>("AccountLoginObj/UIRoot/ErrorRemind/PasswordRemind");
- vcodeRemind = dlg.GetChild<Text>("AccountLoginObj/UIRoot/VerifyObj/VcodeRemind");
- phoneNumLoginBtn = dlg.GetChild<Button>("AccountLoginObj/UIRoot/PhoneNumLoginBtn");
- phoneNumLoginBtn.onClick.AddListener(ClickOnphoneNumLogin);
-
- }
- private void OnEnable()
- {
- #if UNITY_EDITOR
- Invoke("OnClickLogin", 1f);
- #endif
- }
- private void ClickOnphoneNumLogin()
- {
- LoginInit.LoginMethod = "PhoneLogin";
- show();
- }
- public void hide()
- {
- this.gameObject.SetActive(false);
- }
- public void show()
- {
- switch (LoginInit.LoginMethod)
- {
- case "AccountLogin":
- this.gameObject.SetActive(true);
- AccountLoginObj.SetActive(true);
- PhoneLoginObj.SetActive(false);
- isRemberUserAndPass = PlayerPrefs.GetInt("isRemberUserAndPass") == 1 ? true : false;
- Debug.Log(PlayerPrefs.GetInt("isRemberUserAndPass"));
- remberToggle.isOn = isRemberUserAndPass;
- verifyObj.SetActive(false);
- verifyInputField.text = "";
- if (LoginMgr.Instance.userInfo != null && isRemberUserAndPass)
- {
- userInputField.text = LoginMgr.Instance.userInfo.UserID;
- passwordInputField.text = LoginMgr.Instance.userInfo.Password;
- if (userInputField.text != "")
- {
- user.SetActive(true);
- }
- if (passwordInputField.text != "")
- {
- PassBt.SetActive(true);
- }
- }
- else
- {
- userInputField.text = "";
- passwordInputField.text = "";
-
- user.SetActive(false);
- PassBt.SetActive(false);
- }
- userRemind.gameObject.SetActive(false);
- passwordRemind.gameObject.SetActive(false);
- break;
- case "PhoneLogin":
- this.gameObject.SetActive(true);
- AccountLoginObj.SetActive(false);
- PhoneLoginObj.SetActive(true);
- if (PhoneLogin.Instance)
- {
- PhoneLogin.Instance.Init();
- }
- break;
- }
- }
-
- public void cleanUser()
- {
- userInputField.text = "";
- user.SetActive(false);
- }
- public void cleanPassWord()
- {
- passwordInputField.text = "";
- PassBt.SetActive(false);
- }
- public void openEye()
- {
- passwordInputField.contentType = ContentType.Standard;
-
- }
- public void closeEye()
- {
- passwordInputField.contentType = ContentType.Password;
-
- }
- private void OnClickChangeTex()
- {
- NetWorkHeaders.GetTextureCode(GetSucess);
- }
- private void UserValueChanged(string user)
- {
- userRemind.gameObject.SetActive(false);
- if (user != "")
- {
- this.user.SetActive(true);
- }
- }
- private void InputUserEnd(string user)
- {
- if (user == "")
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = RtcStrConfig.qAccount;
- this.user.SetActive(false);
- }
- else
- {
-
-
-
-
-
-
-
- this.user.SetActive(true);
- }
- }
- private void PassValueChanged(string password)
- {
- passwordRemind.gameObject.SetActive(false);
- if (password != "")
- {
- PassBt.SetActive(true);
- }
- }
- private void InputPassEnd(string password)
- {
- if (password == "")
- {
- passwordRemind.gameObject.SetActive(true);
- passwordRemind.text = RtcStrConfig.qPassWord;
- PassBt.SetActive(false);
- }
- else
- {
- PassBt.SetActive(true);
- }
- }
- private void VerifyValueChanged(string verifyNum)
- {
- vcodeRemind.gameObject.SetActive(false);
- }
- private void InputVerifyEnd(string verifyNum)
- {
- if (verifyNum == "")
- {
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text = RtcStrConfig.qRemind;
- }
- }
- private void ClickOnToggle(bool ison)
- {
- Debug.Log("ClickOnToggle");
- isRemberUserAndPass = ison;
- }
- private void OnClickLogin()
- {
-
-
-
-
-
-
- #if UNITY_EDITOR
- userInputField.text = "test01";
- passwordInputField.text = "123456Aa";
- #endif
- if (userInputField.text == "" || passwordInputField.text == "")
- {
- if (userInputField.text == "")
- {
- userRemind.gameObject.SetActive(true);
- userRemind.text = RtcStrConfig.qAccount;
- }
- else if (passwordInputField.text == "")
- {
- passwordRemind.gameObject.SetActive(true);
- passwordRemind.text = RtcStrConfig.qPassWord;
- }
- }
-
-
-
-
- else
- {
- if (!isLock)
- {
- if (!verifyObj.activeSelf)
- {
- isLock = true;
- NetWorkHeaders.YuLogin(userInputField.text, passwordInputField.text, YuLoginOk, LoginFail);
- }
- else
- {
- if (verifyInputField.text != "")
- {
- isLock = true;
- NetWorkHeaders.YuLogin(userInputField.text, passwordInputField.text, verifyInputField.text,capID, YuLoginOk, LoginFail);
- verifyInputField.text = "";
- }
- else
- {
- vcodeRemind.gameObject.SetActive(true);
- vcodeRemind.text = RtcStrConfig.qRemind;
- }
- }
- }
- }
- }
- public void ClickBreakLoginBtn()
- {
- if (!isLock)
- {
- NetWorkHeaders.BreakNumLogin(LoginOk, LoginFail);
- isLock = true;
- }
- }
- private void YuLoginOk(JsonData js)
- {
- if (js["code"].ToString() == "200")
- {
- NetWorkHeaders.Login(userInputField.text, passwordInputField.text, LoginOk, LoginFail);
- }
- }
- private void YuLoginOk()
- {
- NetWorkHeaders.Login(userInputField.text, passwordInputField.text, LoginOk, LoginFail);
- }
- public void LoginOk(JsonData js)
- {
- LoginInitRTC.Instance.InitRTC();
-
- string user = userInputField.text;
- string password = passwordInputField.text;
- UserInfo.isSN = false;
- UserInfo.UnionId = js["data"]["unionId"].ToString();
- UserInfo.User_Token = js["data"]["token"].ToString();
- UserInfo.Account = user;
- UserInfo.PassWord = password;
- NetWorkHeaders.GetUserInfo((JsonData sData) => {
- UserInfo.phone =sData["data"]["phone"].ToString();
- UserInfo.userName = sData["data"]["nickName"].ToString();
- if(UserInfo.userName=="")
- {
- UserInfo.userName = user;
-
- }
- UserInfo.activateType = int.Parse(sData["data"]["activateType"].ToString());
- UserInfo.indate = double.Parse(sData["data"]["indate"].ToString());
- CustomInfo.isSendAudio = bool.Parse(sData["data"]["settings"]["mic"].ToString());
- CustomInfo.isSendVideo = bool.Parse(sData["data"]["settings"]["camera"].ToString());
- CustomInfo.camIndex = int.Parse(sData["data"]["settings"]["resolution"].ToString());
- NetWorkHeaders.GetUserAvater((JsonData aData) =>
- {
- NetWorkHeaders.Instance.getNetTexture(aData["data"]["user"][0].ToString(), null, (Texture tex) => {
- UserInfo.defaulttextIcon = tex;
- });
- UserInfo.defaultavatar = aData["data"]["user"][0].ToString();
- });
- if (sData["data"]["avatar"].ToString()=="")
- {
- UserInfo.textIcon = UserInfo.defaulttextIcon;
- UserInfo.avatar = UserInfo.defaultavatar;
- NetWorkHeaders.SetUserInfo();
- }
- else
- {
- UserInfo.avatar = sData["data"]["avatar"].ToString();
- NetWorkHeaders.Instance.getNetTexture(sData["data"]["avatar"].ToString(),null, (Texture tex) => {
- UserInfo.textIcon = tex;
- });
- }
- isLock = false;
-
-
- bool isSuccess = LoginMgr.Instance.Login(user, password);
-
-
-
- if (isSuccess)
- {
- if (!isRemberUserAndPass)
- {
- user = "";
- password = "";
- userInputField.text = "";
- passwordInputField.text = "";
- LoginMgr.Instance.DeleteLoginInfo();
- }
- else
- {
- LoginMgr.Instance.SaveLoginInfo(user, password);
- }
- }
- WSHandler.Office.OnInit -= Init;
- WSHandler.Office.OnInit += Init;
- WSHandler.init();
-
-
-
- if (verifyObj.activeSelf == true)
- {
- verifyObj.SetActive(false);
- }
- }, (string failStr) => {
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.serverFail);
- });
-
-
- }
- private void Init(JsonData data)
- {
- if (isRemberUserAndPass)
- {
- PlayerPrefs.SetInt("isRemberUserAndPass", 1);
- }
- else
- {
- PlayerPrefs.SetInt("isRemberUserAndPass", -1);
- }
- ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowOffice);
- verifyObj.SetActive(false);
- WSHandler.Office.OnInit -= Init;
- }
- void LoginFail(string str)
- {
- isLock = false;
-
-
- JsonData data = null;
- string code = "";
- try
- {
- data = JsonMapper.ToObject(str);
- code = data["code"].ToString();
- }
- catch (Exception e)
- {
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.serverError);
- return;
-
- }
- string codeStr = data["message"].ToString();
- codeStr = data["message"].ToString();
- switch (code)
- {
- case "5010":
- passwordRemind.text = RtcStrConfig.ePassWord;
- passwordRemind.gameObject.SetActive(true);
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.ePassWord);
- if (this.verifyObj.activeSelf)
- {
- NetWorkHeaders.GetTextureCode(GetSucess);
- }
- break;
- case "6004":
- this.verifyObj.SetActive(true);
- NetWorkHeaders.GetTextureCode(GetSucess);
- passwordRemind.gameObject.SetActive(true);
- passwordRemind.text = RtcStrConfig.eFPassWord;
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.eFPassWord);
- break;
- case "6005":
- this.verifyObj.SetActive(true);
- NetWorkHeaders.GetTextureCode(GetSucess);
- vcodeRemind.text = RtcStrConfig.eRemind;
- vcodeRemind.gameObject.SetActive(true);
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Tip, RtcStrConfig.eRemind);
- break;
- case "6006":
- PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.breakotherLogin, "确定登录",()=> { YuLoginOk(); },"返回",
- () => {
- ShowLogin.Instance.loginType = LoginType.INIT;
- ScenesManager.Instance.showWindow(SceneType.ShowLogin);
- });
- break;
- default:
- passwordRemind.text = RtcStrConfig.ePassWord;
- passwordRemind.gameObject.SetActive(true);
- break;
- }
- }
- string capID;
- private void GetSucess(JsonData data)
- {
- Debug.Log(" 收到验证码图片====> ");
- capID = data["data"]["captchaId"].ToString();
- string[] strs = data["data"]["captcha"].ToString().Split(',');
- byte[] bytes = Convert.FromBase64String(strs[strs.Length - 1]);
- Debug.Log(bytes.Length);
- Texture2D tex2D = new Texture2D(512, 512);
- tex2D.LoadImage(bytes);
-
- verifyTexture.texture = tex2D;
- }
- private void OnClickSet()
- {
- }
- private void OnClickPhoneLogin()
- {
- }
- public void gotoBack()
- {
- ShowLogin.Instance.loginType = LoginType.INIT;
- ScenesManager.Instance.showWindow(SceneType.ShowLogin);
- }
-
- }
- }
|