using System; using System.Collections; using System.IO; using System.Xml; using UnityEngine; using UnityEngine.SceneManagement; public enum GameModel { easy, normal, hard } public enum GameControllerModel { mouse, keyboard, joystack } public class UIController : MonoBehaviour { public UIInput acc; public UIInput pass; public UIInput Regacc; public UIInput RegPass; public UIInput RegPass1; public UIButton login; public UIButton Register; public UIButton Setting; public UIPopupList gameModleList; public UIPopupList gameControllerModelList; public GameObject MessageBox; GameControllerModel gameControllerModel = GameControllerModel.mouse; GameModel gameModel = GameModel.normal; string path; void Start() { path = Application.dataPath + "/userInfo.xml"; Setting.onClick.Add(new EventDelegate(SetSave)); Register.onClick.Add(new EventDelegate(RegisterSave)); login.onClick.Add(new EventDelegate(LogIn)); } public void LogIn() { string Account = ""; string PassWord = ""; if (File.Exists(path)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); XmlNodeList list = xmlDoc.SelectSingleNode("userInfo").ChildNodes; foreach (XmlElement item in list) { if (item.Name == "acc") { Account = item.InnerText; Debug.Log("Account="+ Account); } if (item.Name == "pass") { PassWord = item.InnerText; Debug.Log("PassWord="+ PassWord); } } if (acc.value != "" && pass.value != "" && PassWord.Equals(pass.value) && Account.Equals(acc.value)) { Debug.Log("登陆成功"); SceneManager.LoadScene("ReaperStart"); } } else { OpenMessageBox("输入的账号后密码有错"); } } private void RegisterSave() { if (Regacc.value != "" && RegPass.value != "" && RegPass1.value != "" && RegPass.value.Equals(RegPass1.value)) { PlayerPrefs.SetString("pass", RegPass.value); PlayerPrefs.SetString("acc", Regacc.value); XmlDocument xmlDocument = new XmlDocument(); XmlNode node = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null); xmlDocument.AppendChild(node); XmlNode userInfo = xmlDocument.CreateElement("userInfo"); XmlElement acc = xmlDocument.CreateElement("acc"); acc.InnerText = Regacc.value; XmlElement pass = xmlDocument.CreateElement("pass"); pass.InnerText = RegPass.value; userInfo.AppendChild(acc); userInfo.AppendChild(pass); xmlDocument.AppendChild(userInfo); xmlDocument.Save(path); } else { OpenMessageBox("输入的账号后密码有错"); } } private void SetSave() { switch (gameControllerModelList.value) { case "鼠标": gameControllerModel = GameControllerModel.mouse; break; case "键盘": gameControllerModel = GameControllerModel.keyboard; break; case "手柄": gameControllerModel = GameControllerModel.joystack; break; } switch (gameModleList.value) { case "鼠标": gameModel = GameModel.easy; break; case "键盘": gameModel = GameModel.normal; break; case "手柄": gameModel = GameModel.hard; break; } } void OpenMessageBox(string text) { MessageBox.GetComponentInChildren<TweenPosition>().PlayForward(); MessageBox.GetComponentInChildren<UILabel>().text = text; } }