unity制作软件试用版功能
1、軟件試用基本上沒(méi)有什么難點(diǎn),就是聯(lián)網(wǎng)獲取時(shí)間,然后與規(guī)定試用時(shí)間對(duì)比,超過(guò)了就強(qiáng)行退出App,沒(méi)有超過(guò)就不做操作,話不多說(shuō),上代碼:
//當(dāng)前年、月、日、時(shí)、分、秒float curYear, curMonth, curDay, curHours, curMin, curSec;//截至XX年public const float year = 2023;//截至XX月public const float month = 10;//截至XX日public const float day = 31;//截至XX時(shí)public const float hours = 00;//截至XX分public const float min = 00;//截至XX秒public const float sec = 0;async void Awake(){await timerAsync();}async Task timerAsync(){char[] zifi = new char[] { '-', ':', ';', };var json = await new HttpClient().GetStringAsync($"https://apps.game.qq.com/CommArticle/app/reg/gdate.php");string shijian = json.Remove(0, 20);var fengge = shijian.Split(zifi);curYear = float.Parse(shijian.Substring(0, 4));Debug.Log($"{shijian}");curMonth = float.Parse(fengge[0]);curDay = float.Parse(fengge[2].Substring(0, 2));curHours = float.Parse(fengge[2].Substring(2, 3));curMin = float.Parse(fengge[3]);curSec = float.Parse(fengge[4].Substring(0, 2));Debug.Log($"原格式=>{shijian}");Debug.Log($"轉(zhuǎn)換后格式=>{curYear}{curMonth}{curDay}{curHours}{curMin}{curSec}");}private void FixedUpdate(){curYear = System.DateTime.Now.Year;curMonth = System.DateTime.Now.Month;curDay = System.DateTime.Now.Day;curHours = System.DateTime.Now.Hour;curMin = System.DateTime.Now.Minute;curSec = System.DateTime.Now.Second;if (curYear > year){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curYear < year){return;}else if (curYear == year){if (curMonth > month){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curMonth < month){return;}else if (curMonth == month){if (curDay > day){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curDay < day){return;}else if (curDay == day){if (curHours > hours){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curHours < hours){return;}else if (curHours == hours){if (curMin > min){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curMin < min){return;}else if (curMin == min){if (curSec > sec){ #if UNITY_EDITORUnityEditor.EditorApplication.isPlaying = false; #endif #if UNITY_STANDALONE_WINApplication.Quit(); #endif #if UNITY_ANDROIDApplication.Quit(); #endif}else if (curSec <= sec){return;}}}}}}}private void OnGUI(){GUIStyle gs = new GUIStyle();gs.fontSize = 20;gs.normal.textColor = Color.white;GUI.Label(new Rect(750, 30, 200, 60), "體驗(yàn)版:截止日期為" + year + "年" + month + "月" + day + "日" + min + "分" + sec + "秒", gs);}我也是網(wǎng)上看的,但是忘記原作者了,我自己簡(jiǎn)略修改了部分東西,原作者如果看到了可以聯(lián)系我刪除
2、當(dāng)我們?cè)囉冒嬗卸?jí)應(yīng)用時(shí),肯定不希望啟動(dòng)器關(guān)了,但是程序還在運(yùn)行,那我們可以像steam一樣,我們?cè)谟螒驎r(shí)關(guān)閉steam,游戲也會(huì)一同關(guān)閉,這段代碼寫(xiě)在”OnDestroy“當(dāng)腳本被回收,也就是應(yīng)用被關(guān)閉時(shí)啟用(也可以這么理解)OnDestroy最好寫(xiě)在總控腳本
processName是進(jìn)程名字,當(dāng)我們運(yùn)行程序時(shí)可以打開(kāi)任務(wù)管理器看進(jìn)程名,然后獲取現(xiàn)在所有進(jìn)程名,遍歷對(duì)比,當(dāng)有進(jìn)程名和processName相同時(shí),殺死進(jìn)程
這就是原理,還是挺簡(jiǎn)單的
void OnDestroy(){processName = "3D";System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();foreach (System.Diagnostics.Process process in processes){try{if (!process.HasExited && process.ProcessName == processName)process.Kill();}catch (InvalidOperationException ex){Debug.Log(ex);}}}總結(jié)
以上是生活随笔為你收集整理的unity制作软件试用版功能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 硬盘分区表的修复(Ubuntu安装盘的另
- 下一篇: 数字三角阵