注册

作者: 荼蘼toome | 来源:发表于2022-09-19 11:57 被阅读0次
using UnityEngine;

public abstract class BasePanel : MonoBehaviour
{
    public GameObject Go;
    public object O;    
    string patnName;
    public BasePanel(Transform parent = null)
    {
        Init(parent);
        Open(parent);
    }
    public void Init(Transform parent)
    {
        patnName = "UI/" + GetType().Name;
        Go = Resources.Load<GameObject>(patnName);
        Go = GameObject.Instantiate<GameObject>(Go);
        if (parent != null)
        {
            Go.transform.SetParent(parent, false);
        }
        Go.name = GetType().Name;
        Go.SetActive(false);
    }
    public virtual void Open(object o)
    {
        O = o;
        Go.SetActive(true);
        SetPanel(o);
    }
    public abstract void SetPanel(object o);

    public virtual void Close()
    {
        Go.SetActive(false);
    }
}

Resoutces文件夹中加载预制体

/*
 * Filename: UIRegistration.cs
 * Created Date: 2020年07月01日 09:35:06 星期三
 * Author: zhlong
 * 
 * Copyright (c) 2019 Xuzhou LingTe Technology CO.,LTD
 */
using System;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 该类的功能描述
/// 无需写出实现细节
/// <example>
/// 如果使用该类使用比较复杂,给出使用demo代码
/// <code>
/// 此处添加范例代码
/// </code>
/// </example>
/// </summary>
namespace Zhlong.UI {
    public class UIRegistration : BasePanel {
        private GameObject g;
        string loginValue;
        string configPath;
        InputField inputFielfTxt;
        Button btnOK;
        private Text txtSN;
        /// <summary>
        /// 退出按钮
        /// </summary>
        private Button _Exit;
        public class Model//当前界面要传入的数据
        {
            public string str;
            public Model()
            {

            }
            public Model(string _str)
            {
                str = _str;
            }
        }

        Model model;
        public UIRegistration(Transform t=null) : base(t)//数据赋值
        {

        }
        void PanelInit()
        {
            configPath = Application.dataPath+ "/login.byte";
            inputFielfTxt = Go.FindNodeName("inputFielfTxt").GetComponent<InputField>();
            btnOK = Go.FindNodeName("BtnOk").GetComponent<Button>();
            _Exit = Go.FindNodeName ( "_Exit" ).GetComponent<Button> ();
            txtSN = Go.FindNodeName("txtSN").GetComponent<Text>();
            btnOK.Add(()=> {
                Debug.Log("OK");
                if (inputFielfTxt.text != "") 
                {
                    if (Encryption(GetMacAddress()) == inputFielfTxt.text) 
                    {
                        Debug.LogError("注册成功!");
                        File.WriteAllText(configPath,inputFielfTxt.text);
                        AddUI._Ins._IsOK = true;
                        Close ();
                        return;
                    }
                    Debug.Log(GetMacAddress()+"注册失败!");
                    AddUI._Ins._IsOK = false;
                }
            });

            _Exit.Add ( ( ) => 
            {
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#else
                Application.Quit();
#endif

            } );
            txtSN.text = "你的SN码:"+GetMacAddress();
        }
        /// <summary>
        /// 获取PC识别码 
        /// </summary>
        /// <returns></returns>
        private static string GetMacAddress()
        {
            string physicalAddress = "";

            NetworkInterface[] nice = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adaper in nice)
            {

                //Debug.Log(adaper.Description);

                if (adaper.Description == "en0")
                {
                    physicalAddress = adaper.GetPhysicalAddress().ToString();
                    break;
                }
                else
                {
                    physicalAddress = adaper.GetPhysicalAddress().ToString();

                    if (physicalAddress != "")
                    {
                        break;
                    };
                }
            }
            return physicalAddress;
        }
        public override void Open(object o)//打开界面
        {
            base.Open(o);
            Transform tParent = Go.transform.parent;
           // Debug.LogError(tParent.childCount);
            Go.transform.SetSiblingIndex(3);
        }
        public override void Close()//关闭界面
        {
            base.Close();
           // UILevel2Manager.Instance.IsRegistered = true;
        }

        public override void SetPanel(object o)
        {
            //model = (Model)o;
            // Debug.LogError(model.str);
            PanelInit();
            if (File.Exists(configPath))
            {
                loginValue = File.ReadAllText(configPath);
                if (Encryption(GetMacAddress()) == loginValue)
                {
                    AddUI._Ins._IsOK = true;
                    Close();
                    Debug.LogError("已注册");
                    return;
                }
            }
            Debug.LogError("需要注册");
            AddUI._Ins._IsOK = false;
        }
        string Encryption(string mac)
        {
            char[] strs = mac.ToArray();
            int num = 0;
            for (int i = 0; i < strs.Length; i++)
            {
                num += stringToInt(strs[i].ToString());
            }
            num = num * 6 / 2;
            return num + ".LTJD";
        }

        int stringToInt(string str)
        {
            switch (str)
            {
                case "A":
                    return 155;
                case "B":
                    return 22;
                case "C":
                    return 14;
                case "D":
                    return 45;
                case "E":
                    return 152;
                case "F":
                    return 454;
                case "G":
                    return 327;
                case "H":
                    return 421;
                case "I":
                    return 429;
                case "J":
                    return 244;
                case "K":
                    return 454;
                case "L":
                    return 473;
                case "M":
                    return 122;
                case "N":
                    return 277;
                case "O":
                    return 129;
                case "P":
                    return 973;
                case "Q":
                    return 528;
                case "R":
                    return 772;
                case "S":
                    return 553;
                case "T":
                    return 537;
                case "U":
                    return 877;
                case "V":
                    return 321;
                case "W":
                    return 624;
                case "X":
                    return 752;
                case "Y":
                    return 429;
                case "Z":
                    return 450;
                default:
                    return 136;
            }
        }
    }
}

相关文章

  • BroadcastReceiver动态注册,发送和接收流程分析与

    broadcast的注册分为动态注册和静态注册,静态注册由PackageManagerService完成,动态注册...

  • 深入了解组件

    组件注册   组件注册分为全局注册和局部注册  全局注册   局部注册   基础组件的自动化全局注册可能你的许多组...

  • BroadcastReceiver工作过程

    注册过程(分析动态注册) 广播注册分为静态注册和动态注册。 静态注册的广播在应用安装时由系统自动完成注册,即由PM...

  • Vue 之 组件

    组件注册 组件注册分为两种: 全局注册 和 局部注册 全局注册:全局注册的行为必须在根 Vue 实例 ...

  • vue的组件注册

    vue的组件注册: 全局注册 局部注册

  • 就是咯

    注册注册

  • eventbus

    注册eventbus 有注册就要有取消注册,在页面onDestroy()方法中调用 注册 取消注册 发出事件,传递数据

  • 如何设计一款APP的注册模块

    一、注册模块需要考虑的因素   通常注册模块需要考虑的因素有如下几条: 注册使用的帐号 注册密码 注册验证码 注册...

  • Dubbo(学习中)

    Dubbo提供的注册中心 Multicast注册中心 Zookeeper注册中心 Redis注册中心 Simple...

  • 个人博客—用户注册

    个人博客—用户注册 点击头部的注册按钮,弹出注册dialog注册dialog 注册表单验证 账号、密码、邮箱输入格...

网友评论

      本文标题:注册

      本文链接:https://www.haomeiwen.com/subject/pvzmortx.html