读取StreamingAssets路径下的Config.ini文件里的时间节点来进行判断,方便时间到了之后不用自己再打包了。这功能其实很好被破解,修改系统时间或者自己去找ini文件进行修改就能破解,作用不大,防君子不防小人吧。后面有机会再更新其他的限制功能
代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
using DG.Tweening;
using UnityEngine.UI;
public class LoadScene : MonoBehaviour
{
public string time;
public Text TipsTxt;
private void Awake()
{
Screen.SetResolution(1920, 1080, true);
ReadIni();
}
private void ReadIni()
{
string configFile = Application.streamingAssetsPath + "/config.ini";//打包好的“xxx_Data”目录貌似没有读取里面的文件权限
if (File.Exists(configFile))
{
ConfigIni ini = new ConfigIni(configFile);
time = ini.keyVal["DeadLine"];
Check();
}
}
private void Check()
{
string Timeyear = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd");
DateTime MaxDate = Convert.ToDateTime(time);
DateTime MinDate = Convert.ToDateTime(Timeyear);
int num = DateTime.Compare(MaxDate, MinDate);
if (num <= 0)
{
//Application.Quit();
Debug.Log("正在退出游戏");
TipsTxt.DOText("应用超时,请联系管理员 5秒后退出应用", 3f).SetEase(Ease.Linear).OnComplete(() =>
{
Invoke("QuitApp", 5f);
});
}
else if (num == 0)
{
TipsTxt.DOText("应用今日到期,请及时联系管理员", 3f).SetEase(Ease.Linear).OnComplete(() =>
{
Invoke("Load_Scene", 5f);
});
}
else
{
Debug.Log("正在进入游戏");
SceneManager.LoadScene(1);
}
}
private void QuitApp()
{
Application.Quit();
}
}