77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using System.IO;
|
||
using LitJson;
|
||
using System;
|
||
|
||
namespace ZXKFramework
|
||
{
|
||
/// <summary>
|
||
/// 本地授权管理
|
||
/// </summary>
|
||
public class LocalLicenseManager
|
||
{
|
||
//当前界面停留的总时间(秒)
|
||
private float _passTime = 0;
|
||
//用于减少打印次数,间隔1秒进行打印显示 l
|
||
private float _lastPassTime = 1;
|
||
private bool _hasRefeshed = false;
|
||
LocalLicenseDataNex localLicenseData = new LocalLicenseDataNex();
|
||
private long _nextDayMidNight;
|
||
public Action<bool, string> callBack = null;
|
||
|
||
public void CreateLicense()
|
||
{
|
||
string loPath = Application.persistentDataPath + "/LocalLicense/LocalLicense.txt";
|
||
localLicenseData._nextDayMidNight = TimeTools.GetNextDayZeroTimeStamp(3).ToString();
|
||
string loData = UnityTools.GetJson(localLicenseData);
|
||
Debug.Log(loData);
|
||
TextTools.Create(loPath, loData);
|
||
}
|
||
|
||
public bool ReadLicence()
|
||
{
|
||
string loPath = Application.persistentDataPath + "/LocalLicense/LocalLicense.txt";
|
||
if (File.Exists(loPath))
|
||
{
|
||
string loData = TextTools.Read(loPath);
|
||
localLicenseData = JsonMapper.ToObject<LocalLicenseDataNex>(loData);
|
||
_nextDayMidNight = long.Parse(localLicenseData._nextDayMidNight);
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打开授权文件位置
|
||
/// </summary>
|
||
public void OpenPath()
|
||
{
|
||
string loPath = Application.persistentDataPath + "/LocalLicense";
|
||
UnityTools.CreateDirectory(loPath);
|
||
UnityTools.OpenDirectory(loPath);
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
_passTime += Time.deltaTime;
|
||
if (_passTime - _lastPassTime > 1)
|
||
{
|
||
_lastPassTime = _passTime;
|
||
if (TimeTools.TimeStampNow >= _nextDayMidNight && !_hasRefeshed)
|
||
{
|
||
//到点之后执行回调
|
||
_hasRefeshed = true;
|
||
callBack?.Invoke(true, "对不起,您的授权已经过期");
|
||
}
|
||
else
|
||
{
|
||
callBack?.Invoke(false, $"授权剩余时间 : {TimeTools.ConvertSecToDHMS((int)(_nextDayMidNight - TimeTools.TimeStampNow))}");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|