当前位置:网站首页>Unity limited time use limited trial time and use times
Unity limited time use limited trial time and use times
2022-06-30 05:07:00 【zjh_ three hundred and sixty-eight】
【 The time limit 】 modify Start() Function minTime and maxTime Time is enough . The time limit can also be accurate to seconds , such as :
DateTime minTime = Convert.ToDateTime("2019-4-23 12:22:05");【 Time limit 】SetPlayUseNumber() To limit the number of times , By modifying the key name, you can recalculate ("UseTime")
This script is a combination of limiting time and times , You can modify .
//***************************************************
// effect : Limit the time or frequency of use
// usage : The time limit , modify Start() Function
//SetPlayUseNumber() To limit the number of times , Modify key name ("UseTime") You can recalculate
//
//***************************************************
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SetUserTime : MonoBehaviour {
// Registered name , You can modify
string UseTime = "UseTime";
// Number of trials
int num = 500;
// Expiration prompt text ( Prompt panel )
public Button Btn_expire;
// Use this for initialization
void Start () {
//===( For instance from 3 month 1 The day begins , To 4 month 1 End of the day )
// As long as it's less than minTime Time or greater than maxTime Time , Will stop using
DateTime minTime = Convert.ToDateTime("2019-3-1");
DateTime maxTime = Convert.ToDateTime("2019-4-1");
if (minTime > DateTime.Now || DateTime.Now > maxTime)
{
//=== When it's due , Timeout prompt
UseTime = " It's due ";
num = 0;
print(" It's due ");
}
//=== This method is placed here , Time and times can be limited at the same time
SetPlayUseNumber();
//if (minTime < DateTime.Now && DateTime.Now < maxTime)
//{
// //=== For time limited functions
// // During this time, you can use xx function
//}
}
/// <summary>
/// Set the number of times users use
/// </summary>
void SetPlayUseNumber()
{
RegistryKey RootKey, RegKey;
// The name of the item is :HKEY_CURRENT_USER\Software
RootKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true);
// Open child :HKEY_CURRENT_USER\Software\MyRegDataApp
if ((RegKey = RootKey.OpenSubKey("MyProjectToControlUseTime", true)) == null)
{
RootKey.CreateSubKey("MyProjectToControlUseTime"); // non-existent , Then create a child
RegKey = RootKey.OpenSubKey("MyProjectToControlUseTime", true);
RegKey.SetValue(UseTime, (object)num);// Create key values , Storage usable times
print(" Instantiation ");
return;
}
try
{
object usetime = RegKey.GetValue(UseTime);// Read Key , The number of times that can be used
print(" You can also use :" + usetime + " Time ");
int newtime = int.Parse(usetime.ToString()) - 1;// The number of times that can be used is reduced 1
if (newtime < 0)
{
// Exit the program after expiration
RegKey.SetValue(UseTime, (object)newtime);
Btn_expire.gameObject.SetActive(true);
//Btn_expire.gameObject.transform.GetChild(0).GetComponent<Text>().text=" Trial expired , Please contact the Administrator ";
Invoke("OnQuit", 3);// Delayed exit
}
else
{
RegKey.SetValue(UseTime, (object)newtime); // Update key value , The number of times that can be used is reduced 1
//Btn_expire.gameObject.SetActive(false);
}
}
catch
{
RegKey.SetValue(UseTime, (object)num);
print(" Enter for the first time , Update usage ");
}
}
private void OnQuit()
{
Application.Quit();
}
}
====================================================
Extension add : By modifying the xml Configuration file to change the time limit . It is necessary to change the probation period for the project that has been stopped , And the problem of repeated packaging .
practice : Copy a xml File and rename it officeAll.xml, Then add a line inside <serverToTime>2020-12-31</serverToTime>, Add the following code to SetUserTime Script , And the serverToTime As the obtained final limit time, assign to maxTime.
void Start(){
//serverToTime By reading the time limited operation from the configuration file
string path_xml = System.Environment.CurrentDirectory + @"\ComputeBook\officeAll.xml";
string serverToTime;
if (System.IO.File.Exists(path_xml))
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(path_xml);
// In the configuration file, page 888 The actual effective time of the behavior , The rest are confusing documents
serverToTime = xmldoc.GetElementsByTagName("ServerToTime")[0].ChildNodes[0].InnerText;
}
else
{
serverToTime = "2020-12-31";
}
//...
DateTime minTime = Convert.ToDateTime("2019-3-1");
DateTime maxTime = Convert.ToDateTime(serverToTime );
//...
//...
}
边栏推荐
- Yolov5 torch installation
- Records of some problems encountered during unity development (continuously updated)
- Nestjs配置静态资源,模板引擎以及Post示例
- Unity application class and data file path
- Network communication problem locating steps
- 产生 BUG 测试人员需要自己去分析原因吗?
- Using the command line to convert JSON to dart file in fluent
- Parkour demo
- Unity supports the platform # define instruction of script
- [vcs+verdi joint simulation] ~ take the counter as an example
猜你喜欢

LxC and LXD container summary

Create transfer generation point

Some problems encountered in unity steamvr

Database base (Study & review for self use)

Redis cluster concept

Writing unityshader with sublimetext

【VCS+Verdi联合仿真】~ 以计数器为例

力扣59. 螺旋矩阵 II

Force buckle 59 Spiral matrix II

Connect() and disconnect() of socket in C #
随机推荐
The difference between SVG and canvas
On mask culling of unity
力扣977. 有序数组的平方
Sourcetree usage
Generate a slice of mesh Foundation
Unity3d learning notes-1 (C # learning)
Preorder traversal of Li Kou 589:n fork tree
Unity + hololens2 performance test
[vcs+verdi joint simulation] ~ take the counter as an example
Draw on screen border in Commodore 64
Four methods of unity ugui button binding events
Malignant bug: 1252 of unit MySQL export
Unreal 4 unavigationsystemv1 compilation error
Database base (Study & review for self use)
Unity application class and data file path
SCM learning notes: interrupt learning
Force buckle 59 Spiral matrix II
Create transfer generation point
Read and save txt files
力扣704. 二分查找