123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- using LitJson;
- using Newtonsoft.Json.Linq;
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Text.RegularExpressions;
- using UnityEngine;
- using UnityEngine.UI;
- public class LoginPanel : SingletonMono<LoginPanel>
- {
- public SCInputField m_Account;
- public Button m_EmptyAccountBtn;
- public Text m_AccountErrorStr;
- public Transform m_AccountError;
- public string m_AccountStr;
-
- public SCInputField m_Password;
- public Button m_EmptyPwdBtn;
- public Button m_LockPwdBtn;
- public Text m_PwdErrorStr;
- public Transform m_PwdError;
- public string m_PasswordStr;
- public Button m_Logn;
- public Toggle m_RemenberPwd;
- public bool m_IsRemberPwd;
- public Text error;
- public GameObject loaginError;
- public string message;
- public Text sn;
- public Text version;
- private string token;
- private void Awake()
- {
- m_Account = transform.Find("Account/SCInputField").GetComponent<SCInputField>();
- m_EmptyAccountBtn = transform.Find("Account/EmptyAccount").GetComponent<Button>();
- m_AccountErrorStr = transform.Find("Error/AccountError/Text").GetComponent<Text>();
- m_AccountError = transform.Find("Error/AccountError");
- error = transform.Find("Error/CaptchaError/Text").GetComponent<Text>();
- loaginError = transform.Find("Error/CaptchaError").gameObject;
- m_Password = transform.Find("Password/SCInputField").GetComponent<SCInputField>();
- m_EmptyPwdBtn = transform.Find("Password/EmptyPassword").GetComponent<Button>();
- m_LockPwdBtn = transform.Find("Password/Icon").GetComponent<Button>();
- m_PwdErrorStr = transform.Find("Error/PasswordError/Text").GetComponent<Text>();
- m_PwdError = transform.Find("Error/PasswordError");
- sn = transform.Find("SN").GetComponent<Text>();
- version = transform.Find("Version").GetComponent<Text>();
- m_Logn = transform.Find("LoginBtn").GetComponent<Button>();
- m_RemenberPwd = transform.Find("RememberPwd").GetComponent<Toggle>();
- m_RemenberPwd.isOn = false;
- m_IsRemberPwd = false;
- AddUIListenEvent();
- LitJson.JsonMapper.RegisterImporter<int, string>((int input) => { return input.ToString(); });
- LitJson.JsonMapper.RegisterImporter<string, int>((string input) => { return Int32.Parse(input); });
- LitJson.JsonMapper.RegisterImporter<float, Double>((float input) => { return (double)(input); });
- OnShow();
- }
- private void Start()
- {
- // WriteLog.ConsoleLog.LogStart();
- sn.text = DeviceSN.Instance.SendSerialBy16();
- version.text = "V"+Application.version;
- // PlayerPrefs.DeleteAll();
- #if UNITY_EDITOR
- OnClickLogin();
- # endif
- //SendInit send = new SendInit();
- //send.sn = "ABD123456";
- //send.projectId = 10;
- //string jsonString = JsonMapper.ToJson(send);
- //HttpTool.Instance.PostTest("/sn/init", jsonString, InitSceneValueCallBack);
- //InitSceneValueCallBack(message);
- // //登录
- //SendLogin sendLogin = new SendLogin();
- // sendLogin.email = "test_basic@ghz-tech.com";
- // sendLogin.password = "123456789";
- // string jsonLogin = JsonMapper.ToJson(sendLogin);
- // HttpTool.Instance.PostLogin("/user/login", jsonLogin, LoginCallBack);
- // GameManager.Instance.text2.text = " 选择场景";
- //// 模拟下载
- //SendMaterials sendMaterials = new SendMaterials();
- //sendMaterials.url = "/file/user3/material/5_scaled.jpg";
- //string jsonMaterials = JsonMapper.ToJson(sendMaterials);
- //MaterialObjValue mObj = new MaterialObjValue();
- //mObj.name = "Test";
- //mObj.DownloadPath = "/file/user3/material/5_scaled.jpg";
- //mObj.localSavePath = Application.persistentDataPath + "/Image/" + Path.GetFileName(mObj.DownloadPath);
- //DownLoadMaterial value = new DownLoadMaterial(mObj, 1646126688);
- //HttpTool.Instance.PostImage(value, "/file/download", jsonMaterials, DownLoadCallBack);
- }
- public float timernext = 1;
- float timer = 0;
- private void Update()
- {
- timer += Time.deltaTime;
- if (timer > timernext)
- {
- timer = 0;
- timernext = UnityEngine.Random.Range(13, 33) * 60;
-
- }
-
- }
-
-
- /// <summary>
- /// 添加UI的监听事件
- /// </summary>
- private void AddUIListenEvent()
- {
- m_Account.onEndEdit.AddListener(OnAccountEndEdit);
- m_EmptyAccountBtn.onClick.AddListener(OnclickEmptyAccount);
- m_Password.onEndEdit.AddListener(OnPasswordEndEdit);
- m_EmptyPwdBtn.onClick.AddListener(OnClickEmptyPwd);
- m_LockPwdBtn.onClick.AddListener(OnclickLockPwd);
- m_Password.contentType = SCInputField.ContentType.Password;
- m_Logn.onClick.AddListener(OnClickLogin);
- m_RemenberPwd.onValueChanged.AddListener(OnRemPwdValueChange);
-
- }
- #region UI监听事件
- /// <summary>
- /// 账号输入完成
- /// </summary>
- /// <param name="str"></param>
- private void OnAccountEndEdit(string str)
- {
- m_AccountStr = "";
- if (string.IsNullOrWhiteSpace(str))
- {
- m_AccountError.gameObject.SetActive(true);
- m_AccountErrorStr.text = "请输入邮箱账号";
- }
- else
- {
- //邮箱名以数字或字母开头;邮箱名可由字母、数字、点号、减号、下划线组成;邮箱名(@前的字符)长度为3~18个字符;邮箱名不能以点号、减号或下划线结尾;不能出现连续两个或两个以上的点号、减号。
- //string pattern = @"^[a-zA-Z0-9]((?<!(\.\.|--))[a-zA-Z0-9\._-]){1,16}[a-zA-Z0-9]@([0-9a-zA-Z][0-9a-zA-Z-]{0,62}\.)+([0-9a-zA-Z][0-9a-zA-Z-]{0,62})\.?|((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$";
- string pattern = @"^([\w-\.]+)@([\w-\.]+)(\.[a-zA-Z0-9]+)$";
- if (Regex.IsMatch(str, pattern))
- {
- m_AccountStr = str;
- m_AccountErrorStr.text = "";
- m_AccountError.gameObject.SetActive(false);
- }
- else
- {
- m_AccountError.gameObject.SetActive(true);
- m_AccountErrorStr.text = "账号不合法";
- }
- }
- if (!string.IsNullOrWhiteSpace(m_AccountStr) && !string.IsNullOrWhiteSpace(m_PasswordStr))
- {
- m_Logn.interactable = true;
- }
- }
- /// <summary>
- /// 清理账号输入
- /// </summary>
- private void OnclickEmptyAccount()
- {
- m_AccountErrorStr.text = "";
- m_AccountError.gameObject.SetActive(false);
- m_AccountStr = "";
- m_Account.text = "";
- }
- /// <summary>
- /// 密码输入完成
- /// </summary>
- /// <param name="str"></param>
- private void OnPasswordEndEdit(string str)
- {
- m_PasswordStr = "";
- if (string.IsNullOrWhiteSpace(str))
- {
- m_PwdError.gameObject.SetActive(true);
- m_PwdErrorStr.text = "请输入密码";
-
- }
- else
- {
- //Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");
- //if (RegCHZN.IsMatch(str))
- //{
- // m_PwdError.gameObject.SetActive(true);
- // m_PwdErrorStr.text = "密码不合法";
- // return;
- //}
- //int n = 0;
- ////必须包含小写字母
- //string pattern1 = @"(?=.*[a-z])";
- ////必须包含大写字母
- //string pattern2 = @"(?=.*[A-Z])";
- ////必须包含数字
- //string pattern3 = @"(?=.*\d)";
- ////string pattern3 = @"(?=.*[0 - 9])";
- ////必须包含特殊符号
- //string pattern4 = @"(?=.*[ !""#$%&'()*+,-./:;<=>?@\[\]\^_`{|}~])";
- //string pattern4 = @"(?=([\x21-\x7e]+)[^a-zA-Z0-9])";
- //至少8个字符,最多32个字符
- string pattern5 = @"^.{8,32}$";
- if (!Regex.IsMatch(str, pattern5))
- {
- m_PwdError.gameObject.SetActive(true);
- m_PwdErrorStr.text = "密码小于8位数或大于32位";
- return;
- }
- m_PasswordStr = str;
- m_PwdErrorStr.text = "";
- m_PwdError.gameObject.SetActive(false);
- //if (Regex.IsMatch(str, pattern1))
- //{
- // n++;
- //}
- //if (Regex.IsMatch(str, pattern2))
- //{
- // n++;
- //}
- //if (Regex.IsMatch(str, pattern3))
- //{
- // n++;
- //}
- //if (Regex.IsMatch(str, pattern4))
- //{
- // n++;
- //}
- //if (n >= 3)
- //{
- // m_PasswordStr = str;
- // m_PwdErrorStr.text = "";
- // m_PwdError.gameObject.SetActive(false);
- //}
- //else
- //{
- // m_PwdError.gameObject.SetActive(true);
- // m_PasswordStr = "";
- // m_PwdErrorStr.text = "密码不正确,请重新输入";
- //}
- }
- if (!string.IsNullOrWhiteSpace(m_AccountStr) && !string.IsNullOrWhiteSpace(m_PasswordStr))
- {
- m_Logn.interactable = true;
- }
- }
- /// <summary>
- /// 清理密码输入
- /// </summary>
- private void OnClickEmptyPwd()
- {
- m_PwdErrorStr.text = "";
- m_PwdError.gameObject.SetActive(false);
- m_PasswordStr = "";
- m_Password.text = "";
- }
- /// <summary>
- /// 是否可以显示密码
- /// </summary>
- private void OnclickLockPwd()
- {
- if (m_LockPwdBtn.image.sprite.name == "Lock_Close")
- {
- m_LockPwdBtn.image.sprite = Resources.Load<Sprite>("Texture/Lock_Open");
- m_Password.contentType = SCInputField.ContentType.Standard;
- }
- else if (m_LockPwdBtn.image.name == "Lock_Open")
- {
- m_LockPwdBtn.image.sprite = Resources.Load<Sprite>("Texture/Lock_Close");
- m_Password.contentType = SCInputField.ContentType.Password;
- }
- }
- /// <summary>
- /// 登录
- /// </summary>
- private void OnClickLogin()
- {
- #if UNITY_EDITOR
- m_AccountStr = "mandan.chao@ghz-tech.com";
- m_PasswordStr = "123456Aa";
- #endif
- loaginError.SetActive(false);
- //m_AccountStr = "yifei.yang@ivglass.com";
- //m_AccountStr = "1400672881@qq.com";
- ////m_AccountStr = "test_basic@ghz-tech.com";
- ////m_PasswordStr = "123456789";
-
- if (string.IsNullOrWhiteSpace(m_AccountStr))
- {
- m_AccountErrorStr.text = "账号不能为空";
- return;
- }
- Debug.Log(m_PasswordStr);
- if (string.IsNullOrWhiteSpace(m_PasswordStr))
- {
- m_PwdErrorStr.text = "密码不能为空";
- return;
- }
- if (m_IsRemberPwd)
- {
- PlayerPrefs.SetString("Account", m_AccountStr);
- PlayerPrefs.SetString("Password", m_PasswordStr);
- PlayerPrefs.SetString("IsremPwd", "1");
- }
- else
- {
- PlayerPrefs.SetString("Account", "");
- PlayerPrefs.SetString("Password", "");
- PlayerPrefs.SetString("IsremPwd", "0");
- }
- //向服务器发送账号和密码进行验证
- Debug.Log("向服务器发送账号和密码进行登录");
- m_Logn.interactable = false;
- GameManager.Instance.text.text = " 登录";
- // 登录
- SendLogin sendLogin = new SendLogin();
- sendLogin.email = m_AccountStr;
- sendLogin.password = m_PasswordStr;
- string jsonLogin = JsonMapper.ToJson(sendLogin);
- GameManager.Instance.text.text = jsonLogin;
- HttpTool.Instance.PostLogin("/user/login", jsonLogin, LoginCallBack);
- GameManager.Instance.text2.text = " 选择场景";
-
-
- }
- /// <summary>
- /// 是否记住密码
- /// </summary>
- /// <param name="b"></param>
- private void OnRemPwdValueChange(bool b)
- {
- m_IsRemberPwd = b;
- }
- #endregion
- public void OnShow()
- {
- // gameObject.transform.localScale = new Vector3(1, 1, 1);
- m_Logn.interactable = false;
- m_AccountStr = PlayerPrefs.GetString("Account");
- m_PasswordStr = PlayerPrefs.GetString("Password");
- int n = int.Parse(PlayerPrefs.GetString("IsremPwd", "0"));
- m_RemenberPwd.isOn = n > 0 ? true : false;
- m_IsRemberPwd = n > 0 ? true : false;
- if (!string.IsNullOrWhiteSpace(m_AccountStr) && !string.IsNullOrWhiteSpace(m_PasswordStr))
- {
- m_Account.text = m_AccountStr;
- m_Password.text = m_PasswordStr;
- m_Logn.interactable = true;
- }
- else
- {
- m_Account.text = "";
- m_Password.text = "";
- m_AccountStr = "";
- m_PasswordStr = "";
- m_Logn.interactable = false;
- }
- }
- public void LoginCallBack(string message)
- {
- Debug.Log( message);
- GameManager.Instance.text.text = message;
- if (message.Contains("密码不正确,请重新输入") || message.Contains("用户未注册"))
- {
- JObject obj = JObject.Parse(message);
- message = obj["message"].ToString();
- loaginError.SetActive(true);
- error.text = message;
- m_Logn.interactable = true;
- return;
- }
- // 获取素材库列表
- //JObject obj = JObject.Parse(message);
- //Debug.Log(obj["data"]["token"].ToString());
- HttpTool.Instance.GetAllMaterials("/material/init", message, AllMaterialsCallBack);
- HttpTool.Instance.Get("/project/index", GetAllSceneDataCallBack);
-
-
- }
- public void DownLoadCallBack(DownLoadMaterial mObj, object obj)
- {
- Debug.Log(mObj.mObj.name + " " + mObj.mObj.DownloadPath);
- Sprite sprite = (Sprite)obj;
- m_LockPwdBtn.GetComponent<Image>().sprite = sprite;
- }
- private void AllMaterialsCallBack(string message)
- {
- GameManager.Instance.text.text = " 获取素材列表";
- GameManager.Instance.text4.text = message;
- Debug.Log(message);
- JObject jObject = JObject.Parse(message);
- string data = jObject["data"].ToString();
- JObject dataObject = JObject.Parse(data);
- string single = dataObject["single"].ToString();
- string library = dataObject["library"].ToString();
- string combination = dataObject["combination"].ToString();
- //string test = dataObject["combination"][0].ToString();
- //Debug.Log(test);
- //CompositeMaterialValueTest test111 = JsonMapper.ToObject<CompositeMaterialValueTest>(test);
- List<CompositeMaterialValue> singleMaterials = JsonMapper.ToObject<List<CompositeMaterialValue>>(single);
- List<CompositeMaterialValue> libraryMaterials = JsonMapper.ToObject<List<CompositeMaterialValue>>(library);
- Debug.Log(combination);
- List<CompositeMaterialValue> combinationMaterials = JsonMapper.ToObject<List<CompositeMaterialValue>>(combination);
- List<CompositeMaterialValue> upLoadMaterials = new List<CompositeMaterialValue>();
- //for (int i = 0; i < libraryMaterials.Count; i++)
- //{
- // upLoadMaterials.Add(libraryMaterials[i]);
- //}
- for (int i = 0; i < combinationMaterials.Count; i++)
- {
- upLoadMaterials.Add(combinationMaterials[i]);
- }
- for (int i = 0; i < singleMaterials.Count; i++)
- {
- upLoadMaterials.Add(singleMaterials[i]);
- }
- Debug.Log(upLoadMaterials.Count);
- //for (int i = 0; i < upLoadMaterials.Count; i++)
- //{
- // Debug.Log(upLoadMaterials[i].name);
- // for (int j = 0; j < upLoadMaterials[i].materialList.Count; j++)
- // {
- // Debug.Log(upLoadMaterials[i].materialList[j].name);
- // }
- //}
- GameManager.Instance.listCMValue = GameManager.Instance.ProcessCMVJsonData(upLoadMaterials, true);
- GameManager.Instance.text.text = " 素材列表获取结束";
- try
- {
-
- }
- catch (Exception e)
- {
- ErrorLogPanel.Instance.Show(" 处理素材列表数据出现错误 " + e.Message);
- }
-
- }
- private void GetAllSceneDataCallBack(string message)
- {
- Debug.Log("@@@@ "+message);
- JObject jobject = JObject.Parse(message);
- message = jobject["data"].ToString();
- List<ScenesPage> listScenesPage = JsonMapper.ToObject<List<ScenesPage>>(message);
- if (listScenesPage == null || listScenesPage.Count == 0)
- {
- error.text = "当前账号下未创建场景";
- return;
- }
- SelectScene.Instance.Show(listScenesPage);
-
- }
- private void InitSceneValueCallBack(string message)
- {
- try
- {
- GameManager.Instance.text2.text = " 获取场景信息";
- JObject jObject = JObject.Parse(message);
- message = jObject["data"].ToString();
- Debug.Log("@@@ " + message);
- SceneValue scene = JsonMapper.ToObject<SceneValue>(message);
- GameManager.Instance.scene = GameManager.Instance.ProcesSceneValueJsonData(scene);
- GameManager.Instance.text2.text = " 场景信息获取结束";
- }
- catch (Exception e)
- {
-
- throw;
- }
-
-
- }
- }
|