123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- using GameFramework.Event;
- using GameFramework.WebRequest;
- using System.Collections;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using System.Text;
- using BestHTTP;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityGameFramework.Runtime;
- using System;
- using UnityEngine.SceneManagement;
- public class StudyCenterForm : UIFormLogic
- {
- bool remenberMe = false;
- public Sprite[] loginSelectionTypes;
- InputField userName;
- InputField userPassword;
- GameObject loginObj;
- GameObject entryObj;
- Toggle remenber;
- Button loginSelection1;
- Button loginSelection2;
- Button loginBtn;
- private Button quitBtn;
-
- GameObject navigationBtn1;
- GameObject navigationBtn2;
- GameObject navigationBtn3;
- GameObject nb1;
- GameObject nb2;
- GameObject nb3;
- GameObject nb4;
- GameObject nb5;
- GameObject nb6;
- Text userNameText;
- GameObject navigation2;
- protected override void OnInit(object userData)
- {
- base.OnInit(userData);
- InItUiComponent();
- }
- protected override void OnOpen(object userData)
- {
- base.OnOpen(userData);
- GameMain.Event.Subscribe(ChangeGameModeTypeEvent.EventId, OnChangeGameMode);
- if (PlayerPrefs.HasKey("LastUserName") && userName != null && userPassword != null && remenber != null)
- {
- userName.text = PlayerPrefs.GetString("LastUserName");
- userPassword.text = PlayerPrefs.GetString("LastPassword");
- remenber.isOn = true;
- remenberMe = true;
- }
- else {
- userName.text = "";
- userPassword.text = "";
- remenber.isOn = false;
- remenberMe = false;
- }
-
- }
- private void InItUiComponent()
- {
- loginObj = this.transform.Find("Login").gameObject;
- entryObj = this.transform.Find("Entry").gameObject;
- loginSelection1 = this.transform.Find("Login/Content/Section1").GetComponent<Button>();
- loginSelection2 = this.transform.Find("Login/Content/Section2").GetComponent<Button>();
- remenber = this.transform.Find("Login/Content/Remenber").GetComponent<Toggle>();
- loginBtn = this.transform.Find("Login/Content/Login").GetComponent<Button>();
- userName = this.transform.Find("Login/Content/Account/InputField").GetComponent<InputField>();
- userPassword = this.transform.Find("Login/Content/Password/InputField").GetComponent<InputField>();
- quitBtn=this.transform.Find("BtnQuit").GetComponent<Button>();
- quitBtn.onClick.AddListener(() =>
- {
- Application.Quit();
- });
- loginSelection1.onClick.AddListener(() =>
- {
- UserData.currentLogType = LoginType.Teacher;
- loginSelection1.GetComponent<Image>().sprite = loginSelectionTypes[0];
- loginSelection2.GetComponent<Image>().sprite = loginSelectionTypes[1];
- });
- loginSelection2.onClick.AddListener(() =>
- {
- UserData.currentLogType = LoginType.Student;
- loginSelection1.GetComponent<Image>().sprite = loginSelectionTypes[1];
- loginSelection2.GetComponent<Image>().sprite = loginSelectionTypes[0];
- });
- remenber.onValueChanged.AddListener((bool change) =>
- {
- remenberMe = change;
- });
- loginBtn.onClick.AddListener(() =>
- {
- //#if UNITY_EDITOR
- // loginObj.gameObject.SetActive(false);
- // entryObj.gameObject.SetActive(true);
- // userNameText.text = UserData.realName;
- // GameMain.Event.Fire(this, LoginResultEvent.Create(LoginResultEvent.LoginResult.success));
- // return;
- //#endif
- BestHTTP.HTTPRequest request = new BestHTTP.HTTPRequest(new System.Uri(HttpAddress.loginAddress), BestHTTP.HTTPMethods.Post, (HTTPRequest request1,HTTPResponse response) =>
- {
- try
- {
- Log.Debug(response.DataAsText);
- LoginInfoRet loginInfo = JsonConvert.DeserializeObject<LoginInfoRet>(response.DataAsText);
- if (loginInfo.code == 200 && loginInfo.data != null)
- {
- UserData.token = loginInfo.data.token;
- UserData.userName = loginInfo.data.userName;
- UserData.realName = loginInfo.data.realName;
- LoginType tempType = loginInfo.data.roles.Length > 1 ? LoginType.Teacher : LoginType.Student;
- if (tempType != UserData.currentLogType)
- {
- GameMain.UI.OpenUIForm("Tips", "Pop", new TipsData("", "登录信息有误,请检查登录账户类型!"));
- }
- else
- {
- if (remenberMe)
- {
- PlayerPrefs.SetString("LastUserName", userName.text.Trim());
- PlayerPrefs.SetString("LastPassword", userPassword.text.Trim());
- PlayerPrefs.Save();
- }
- else
- {
- if (PlayerPrefs.HasKey("LastUserName"))
- {
- PlayerPrefs.DeleteKey("LastUserName");
- }
- if (PlayerPrefs.HasKey("LastPassword"))
- {
- PlayerPrefs.DeleteKey("LastPassword");
- }
- PlayerPrefs.Save();
- }
- HttpGlobal.SendPingToServer();
- GameMain.beginHeart = true;
- Debug.Log("登录成功开始统计在线时长");
- loginObj.gameObject.SetActive(false);
- entryObj.gameObject.SetActive(true);
- userNameText.text = UserData.realName;
- GameMain.Event.Fire(this, LoginResultEvent.Create(LoginResultEvent.LoginResult.success));
- }
- }
- else
- {
- GameMain.UI.OpenUIForm("Tips", "Pop", new TipsData("", "登录信息有误,账户或密码错误!"));
- }
- //Log.Debug(response.DataAsText);
- //LoginInfoRet loginInfo = JsonConvert.DeserializeObject<LoginInfoRet>(response.DataAsText);
- //if (loginInfo.code == 200 && loginInfo.data != null)
- //{
- // UserData.token = loginInfo.data.token;
- // UserData.userName = loginInfo.data.userName;
- // UserData.realName = loginInfo.data.realName;
- // LoginType tempType = loginInfo.data.roles.Length > 1 ? LoginType.Teacher : LoginType.Student;
- // if (tempType != UserData.currentLogType)
- // {
- // GameMain.UI.OpenUIForm("Tips", "Pop", new TipsData("", "登录信息有误,请检查登录账户类型!"));
- // }
- // else
- // {
- // if (remenberMe)
- // {
- // PlayerPrefs.SetString("LastUserName", userName.text.Trim());
- // PlayerPrefs.SetString("LastPassword", userPassword.text.Trim());
- // PlayerPrefs.Save();
- // }
- // else
- // {
- // if (PlayerPrefs.HasKey("LastUserName"))
- // {
- // PlayerPrefs.DeleteKey("LastUserName");
- // }
- // if (PlayerPrefs.HasKey("LastPassword"))
- // {
- // PlayerPrefs.DeleteKey("LastPassword");
- // }
- // PlayerPrefs.Save();
- // }
- // loginObj.gameObject.SetActive(false);
- // entryObj.gameObject.SetActive(true);
- // userNameText.text = UserData.realName;
- // GameMain.Event.Fire(this, LoginResultEvent.Create(LoginResultEvent.LoginResult.success));
- // }
- //}
- //else
- //{
- // GameMain.UI.OpenUIForm("Tips", "Pop", new TipsData("", "登录信息有误,账户或密码错误!"));
- //}
- }
- catch (Exception e) {
- GameMain.UI.OpenUIForm("Tips", "Pop", new TipsData("", string.Format("服务器异常,请联系管理员!\n{0}",e.ToString())));
- }
- });
- string jsonContent = JsonConvert.SerializeObject(new UserLoginInfo(userName.text.Trim(), userPassword.text.Trim(),"",""));
- request.RawData = Encoding.UTF8.GetBytes(jsonContent);
- request.AddHeader("Content-Type", "application/json");
- request.Send();
- });
- userNameText = this.transform.Find("Entry/LoginUser").GetComponent<Text>();
-
- navigationBtn1 = this.transform.Find("Entry/Navigation/B1").gameObject;
- navigationBtn2 = this.transform.Find("Entry/Navigation/B2").gameObject;
- navigationBtn3 = this.transform.Find("Entry/Navigation/B3").gameObject;
- nb1 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB1").gameObject;
- nb2 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB2").gameObject;
- nb3 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB3").gameObject;
- nb4 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB4").gameObject;
- nb5 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB5").gameObject;
- nb6 = this.transform.Find("Entry/Navigation/B2/Navigation2/NB6").gameObject;
- navigation2 = this.transform.Find("Entry/Navigation/B2/Navigation2").gameObject;
- navigationBtn1.gameObject.GetComponent<Button>().onClick.AddListener(()=> {
- if (SceneManager.GetActiveScene().name == "Main")
- {
- return;
- }
- navigationBtn1.gameObject.GetComponent<Image>().color = Color.white;
- navigationBtn2.gameObject.GetComponent<Image>().color = Color.clear;
- navigationBtn3.gameObject.GetComponent<Image>().color = Color.clear;
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(navigationBtn1.gameObject.GetComponent<Button>()));
- //navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(0));
- });
- navigationBtn2.gameObject.GetComponent<Button>().onClick.AddListener(() => {
- if (SceneManager.GetActiveScene().name == "Main") {
- return;
- }
- navigationBtn1.gameObject.GetComponent<Image>().color = Color.clear;
- navigationBtn2.gameObject.GetComponent<Image>().color = Color.white;
- navigationBtn3.gameObject.GetComponent<Image>().color = Color.clear;
- navigation2.gameObject.SetActive(!navigation2.gameObject.activeSelf);
- //GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(1));
- });
- nb1.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(1));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb1.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了IT系统业务训练");
- });
- nb2.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(3));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb2.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了网络系统业务训练");
- });
- nb3.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(4));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb3.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了电力系统业务训练");
- });
- nb4.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(5));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb4.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了冷却系统业务训练");
- });
- nb5.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(7));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb5.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了监控系统业务训练");
- });
- nb6.GetComponent<Button>().onClick.AddListener(() =>
- {
- navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(6));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(nb6.GetComponent<Button>()));
- HttpGlobal.SendLogToServer("进入了应用程序系统业务训练");
- });
- navigationBtn3.gameObject.GetComponent<Button>().onClick.AddListener(() =>
- {
- if (SceneManager.GetActiveScene().name == "Main")
- {
- return;
- }
- navigationBtn1.gameObject.GetComponent<Image>().color = Color.clear;
- navigationBtn2.gameObject.GetComponent<Image>().color = Color.clear;
- navigationBtn3.gameObject.GetComponent<Image>().color = Color.white;
- //navigation2.gameObject.SetActive(false);
- GameMain.Event.Fire(this, ChangeGameModeTypeEvent.Create(2));
- GameMain.Event.Fire(this, AnyButtomClickEvent.Create(navigationBtn3.gameObject.GetComponent<Button>()));
- });
- }
- private void OnChangeGameMode(object sender, GameEventArgs e)
- {
- navigation2.gameObject.SetActive(false);
- }
- protected override void OnClose(bool isShutdown, object userData)
- {
- base.OnClose(isShutdown, userData);
- GameMain.Event.Unsubscribe(ChangeGameModeTypeEvent.EventId, OnChangeGameMode);
- }
- }
|