输入授权码后软件可正常运行,否则各种错误
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class XKSecurity : MonoBehaviour {
string _key = "这里输入你的授权码";
string _history = "2019-11-1";
int _openDay = 2;
bool _isOpen = true;
int _winWidth;
int _winHeight;
void Start () {
_winWidth = Screen.width;
_winHeight = Screen.height;
_itemHeight = _winHeight / 10;
_startX = _winWidth / 5;
int openDay = _openDay;
DateTime historyTime = Convert.ToDateTime(_history);
System.DateTime currentTime = System.DateTime.Now;
TimeSpan ts = currentTime - historyTime;
//PlayerPrefs.SetInt("XKSecurity", 1);
_openDay = PlayerPrefs.GetInt("XKSecurity", _openDay);
if(ts.Days>_openDay)
{
_isOpen = false;
}else
{
Destroy(gameObject);
}
}
string key;
int _InternalHeight = 20;
int _itemHeight;
int _itemWidth;
int _startX;
bool _isOpenSuccess = false;
bool _isOpenfail = false;
private void OnGUI()
{
if (!_isOpen)
{
//去掉材质
MeshRenderer[] gos = GameObject.FindObjectsOfType<MeshRenderer>();
foreach(var go in gos)
{
Destroy(go);
}
//去掉ui事件
UnityEngine.EventSystems.EventSystem uievent = GameObject.FindObjectOfType<UnityEngine.EventSystems.EventSystem>();
if(uievent)
{
Destroy(uievent.gameObject);
}
//去掉uiCanvas
UnityEngine.UI.CanvasScaler canvasScaler = GameObject.FindObjectOfType<UnityEngine.UI.CanvasScaler>();
if (canvasScaler)
{
Destroy(canvasScaler.gameObject);
}
key = GUI.TextField(new Rect(_startX, _winHeight/5, _winHeight/2, _itemHeight), key);
GUIStyle fontStyle = new GUIStyle();
fontStyle.fontSize = 40;
GUI.Label(new Rect(_startX, _winHeight / 5 + _itemHeight+ _InternalHeight, _winWidth/ 2, _itemHeight), "请输入轩科授权码", fontStyle);
GUI.Label(new Rect(_startX, _winHeight / 5 + 2*_itemHeight+ _InternalHeight, _winWidth/ 2, _itemHeight), "授权码请联系轩科客服:13719347300", fontStyle);
fontStyle.fontSize = 20;
if (GUI.Button(new Rect(_startX, _winHeight / 5 + 3*_itemHeight + _InternalHeight, _winWidth / 5, _itemHeight), "sure"))
{
if (key.Equals(_key))
{
PlayerPrefs.SetInt("XKSecurity", 365+ _openDay);
_isOpen = true;
_isOpenSuccess = true;
_isOpenfail = false;
}
else
{
_isOpenfail = true;
}
}
}
GUIStyle fontStyle2 = new GUIStyle();
fontStyle2.fontSize = 40;
fontStyle2.normal.textColor = new Color(1, 0, 0);
if (_isOpenSuccess)
{
GUI.Label(new Rect(_startX, _winHeight / 2, _winWidth / 2, _itemHeight), "授权成功:请重启!", fontStyle2);
}
if (_isOpenfail)
{
GUI.Label(new Rect(_startX, _winHeight * 0.8f, _winWidth / 2, _itemHeight), "授权码不对:请重新输入", fontStyle2);
}
}
}