Unity通过本地时间/网络时间对软件进行限制使用
public class TimeLimited : MonoBehaviour
{
public GameObject SYQ,LWTS;
public void Start()
{
//网络时间
#region 获取时间戳
string str = GetWebClient("http://www.hko.gov.hk/cgi-bin/gts/time5a.pr?a=2");
//string str = GetTimeStamp(); // 验证时间戳该有的长度
//Console.WriteLine(str);
string timeStamp = str.Split('=')[1].Substring(0, 10); //网页获取的数据长度超了,所以要裁剪
//Console.WriteLine(timeStamp);
DateTime datetime = GetTime(timeStamp);
Debug.Log((int)datetime.Year + "年" + (int)datetime.Month + "月" + (int)datetime.Day + "日");//输出时间
if ((int)datetime.Year > 2020&& (int)datetime.Month > 11&& (int)datetime.Day > 15) //判断是否大于2021年
{
Debug.Log(datetime + "123456789");
transform.GetComponent<CameraController>().enabled = false;
SYQ.SetActive(true);
}
#endregion
}
void Update()
{
//本地时间
if (System.DateTime.Today.Year > 2020 && System.DateTime.Today.Month > 11 && System.DateTime.Today.Day > 15)//限制使用日期2021.10.2日
{
SYQ.SetActive(true);
transform.GetComponent<CameraController>().enabled = false;
Debug.Log(1234);
}
IsConnectedInternet();
}
[DllImport("winInet.dll")] //引用外部库
private static extern bool InternetGetConnectedState(ref int dwFlag, int dwReserved); //库中函数
#region 判断本地的连接状态
private bool IsConnectedInternet()
{
int dwFlag = new int();
if (!InternetGetConnectedState(ref dwFlag, 0))
{
Debug.Log("当前没有联网,请您先联网后再进行操作!");
LWTS.gameObject.SetActive(true);
if ((dwFlag & 0x14) == 0) return false;
Debug.LogWarning("本地系统处于脱机模式。");
return false;
}
else
{
if ((dwFlag & 0x01) != 0)
{
Debug.Log("调制解调器上网。");
LWTS.gameObject.SetActive(false);
return true;
}
else if ((dwFlag & 0x02) != 0)
{
Debug.Log("网卡上网。");
LWTS.gameObject.SetActive(false);
return true;
}
else if ((dwFlag & 0x04) != 0)
{
Debug.Log("代理服务器上网。");
LWTS.gameObject.SetActive(false);
return true;
}
else if ((dwFlag & 0x40) != 0)
{
Debug.Log("虽然可以联网,但可能链接也可能不连接。");
LWTS.gameObject.SetActive(false);
return true;
}
}
return false;
}
#endregion
private static string GetWebClient(string url)
{
string strHTML = "";
WebClient myWebClient = new WebClient();
Stream myStream = myWebClient.OpenRead(url);
StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));
strHTML = sr.ReadToEnd();
myStream.Close();
return strHTML;
}
#region 获取时间戳,本方法只是为了测试时间戳样式
private static string GetTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds).ToString();
}
#endregion
/// <summary>
/// 时间戳转为C#格式时间
/// </summary>
/// <param name="timeStamp">Unix时间戳格式</param>
/// <returns>C#格式时间</returns>
public static DateTime GetTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
}
Unity通过本地时间/网络时间对软件进行限制使用相关推荐
- esp32获取网络时间和天气
@[esp32获取网络时间和天气] esp32获取网络时间和天气 目录 一.库的获取 二.esp32连接wifi 三.oled显示 四.汉字或图片取模放在oled中显示 五.esp32获取网络时间 六 ...
- Unity判断PC本地的网络连接状态、获取网络时间
Unity判断PC本地的网络连接状态 [DllImport("winInet.dll")]//引用外部库 private static extern bool InternetGe ...
- python实现软件登陆过程中的试用时间校验(网络时间和本地时间双校验)
# !/usr/bin/env python3 # -*- coding: UTF-8 -*- """ @des :""" import r ...
- Esp8266 进阶之路36【外设篇】乐鑫esp8266芯片SDK编程驱动时间芯片 ds1302,同步网络时间到本地,再也不怕掉电断网也可以同步时间了!(附带Demo)
本系列博客学习由非官方人员 半颗心脏 潜心所力所写,仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 1. Esp8266之 搭建开发环境,开始一个"hello ...
- 获取网络时间并刷新本地时间(源码2)
因为上次那个获取网络时间失效了(使用的是37端口),获取网络时间并刷新本地时间(源码1) 所以网上又找了一份代码,使用的是123端口,虽然没有测试成功,这里也做下记录,估计是本机环境问题,过两天再进行 ...
- python获取网络时间_python获取网络时间和本地时间
今天我们来看一下如何用python获取网络时间和本地时间,直接上代码吧,代码中都有注释. python获取网络时间获取网络时间 def getBeijinTime(): ""&qu ...
- 设定软件使用期限,根据网络时间保护试用软件产品的方法
思路很简单(容易破解): 1. 在代码内设定最后使用期限 2. 程序运行时首先从网络获取时间 3. 获取网络时间失败(如用户未联网)或者网络时间显示已经超过设定期限,程序退出. 4. 特别注意:程序需 ...
- Arduino ESP32 获取网络时间并同步本地RTC时钟
Arduino ESP32 获取网络时间并同步本地RTC时钟 相关篇<Arduino ESP32 最简单直接获取网络时间方法> 在 ArduinoESP32核心支持库当中已经包含相关的获取 ...
- Java 获取本地时间与网络时间
Java获取的时间分为本地时间和网络时间,一般情况下开发中获取的都是本地时间,但是有些情况也需要我们去获取网络时间,以校验时间的准确性. 下面我会分别介绍获取本地时间和网络时间的方法: 获取本地时间 ...
最新文章
- 【bzoj4916】神犇和蒟蒻 杜教筛
- 计算机考试一年有肌肉,阅卷老师最想看到什么样的字体?电脑阅卷时代,这种字体很吃香...
- 好事多磨:Ogre1.7 编译记
- 粉丝提问:求问大神您会查exif吗?
- hadoop 2.5.0安装和配置
- 流量主系列|微信AI人脸转换小程序源码
- EasyUI Datagrid 自定义列、Foolter及单元格编辑
- scrapy 的依赖库安装和出现def write(self, data, async=False):的解决方法
- .Net Core中使用ref和SpanT提高程序性能
- 单身狗应该怎么过七夕节?
- 《C#图解教程》读书笔记之五:委托和事件
- db2 java驱动下载_IBM DB2 jdbc驱动
- vue particles.js 登录背景实现粒子动效
- 支持向量回归机(SVR)代码
- 【色彩管理】HSI色彩模式详解
- 启发式搜索求解八数码问题(Java实现,八数码小项目已开源)
- ijkplayer 代码走读之 h264 解封装器应用详解
- unix bsd linux shell bash GNU之间的联系,歪讲Linux(一)
- English--consonant_爆破音
- mysql替换后的zzigu_MySQL导入数据报错Got a packet bigger than‘max_allowed_packet’bytes错误的解决方法...