88 lines
2.6 KiB
C#
88 lines
2.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
public class LicenseUI : MonoBehaviour
|
|
{
|
|
public TMP_InputField userInputField; //用户名
|
|
public TMP_InputField licenseInputField; //验证号
|
|
public Button loginBtn;
|
|
public Button exitGame;
|
|
public GameObject licenseObj;
|
|
public GameObject errorTip;
|
|
public GameObject loading;
|
|
public GameObject content;
|
|
public LicenseManager licenseManager;
|
|
private void Awake()
|
|
{
|
|
exitGame.onClick.AddListener(() => {
|
|
#if UNITY_EDITOR //在编辑器模式下
|
|
EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
});
|
|
userInputField.onEndEdit.AddListener(value => { Datas.UserName = value; });//输入用户名
|
|
licenseInputField.onEndEdit.AddListener(value => { Datas.Licensecode = value; }); //输入验证号
|
|
loginBtn.onClick.AddListener(() => {
|
|
licenseManager.LicensePost(args =>
|
|
{
|
|
if (args)
|
|
{
|
|
licenseObj.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
errorTip.SetActive(true);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
licenseObj.SetActive(true);
|
|
loading.SetActive(true);
|
|
content.SetActive(false);
|
|
errorTip.SetActive(false);
|
|
string fileName = "encryptedData.txt";
|
|
if (IsFileExistsInStreamingAssets(fileName))
|
|
{
|
|
if (!string.IsNullOrEmpty(licenseManager.ReadDecryptedFile()))
|
|
{
|
|
string[] user = licenseManager.ReadDecryptedFile().Split('|');
|
|
Datas.UserName = user[0];
|
|
Datas.Licensecode = user[1];
|
|
}
|
|
licenseManager.LicensePost(args =>
|
|
{
|
|
if (args)
|
|
{
|
|
licenseObj.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
//errorTip.SetActive(true);
|
|
loading.SetActive(false);
|
|
errorTip.SetActive(false);
|
|
content.SetActive(true);
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
loading.SetActive(false);
|
|
errorTip.SetActive(false);
|
|
content.SetActive(true);
|
|
}
|
|
}
|
|
|
|
bool IsFileExistsInStreamingAssets(string fileName)
|
|
{
|
|
// 拼接出完整的文件路径
|
|
string filePath = Path.Combine(Application.streamingAssetsPath, fileName);
|
|
return File.Exists(filePath);
|
|
}
|
|
}
|