zoukankan      html  css  js  c++  java
  • XML保存账号密码

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

      

  • 相关阅读:
    条件变量:为什么要与互斥锁配套使用?为什么要使用while来避免虚假唤醒?
    【转】高性能IO之Reactor模式
    LeetCode127:单词接龙
    CF1245F: Daniel and Spring Cleaning
    权值线段树学习笔记
    luogu_4317: 花神的数论题
    luogu_2605: 基站选址
    入门平衡树: Treap
    CF1244C: The Football Season
    luogu_1156: 垃圾陷阱
  • 原文地址:https://www.cnblogs.com/DazeJiang/p/14269240.html
Copyright © 2011-2022 走看看