85 lines
2.4 KiB
C#
Raw Normal View History

2025-09-08 14:51:28 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class DataLicense : MonoBehaviour
{
public GameObject obj;
public Button exitGame;
// Start is called before the first frame update
void Start()
{
exitGame.onClick.AddListener(() => {
#if UNITY_EDITOR //在编辑器模式下
EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
});
//CreatTimer("0|0");
UpdateDataLicense(() =>
{
obj.SetActive(true);
}, () =>
{
obj.SetActive(false);
});
}
public void UpdateDataLicense(UnityAction action1=null,UnityAction action2=null)
{
try
{
string[] datas = DecryptFileReader.ReadAndDecryptData("License.txt", () => {
Debug.Log("弹出ui界面提示仿真文件损坏请联系管理员进行修复");
action1?.Invoke();
}).Split('|');
if (datas[0]=="0"&& datas[1]=="0")
{
CreatTimer($"{1}|{GetPhysicalAddress()}");
}
else if (datas[0]=="1")
{
if (datas[1]== GetPhysicalAddress())
{
Debug.Log("验证通过,");
action2?.Invoke();
}
else
{
Debug.Log("当前设备ID跟程序ID不一致");
action1?.Invoke();
}
}
}
catch (Exception e)
{
action1?.Invoke();
}
}
public void CreatTimer(string value)
{
string strMerge = value;
Debug.Log(strMerge);
EncryptFileCreator.EncryptAndSaveData(strMerge, "License.txt");
}
string GetPhysicalAddress()
{
//string physicalAddress = "";
//NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
//foreach (NetworkInterface ni in nis)
//{
// if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && ni.OperationalStatus == OperationalStatus.Up)
// {
// physicalAddress = ni.GetPhysicalAddress().ToString();
// break;
// }
//}
return SystemInfo.deviceUniqueIdentifier;
}
}