From 41766c0d3c01285d30c503e8a3b267645a8365ec Mon Sep 17 00:00:00 2001 From: Baozw Date: Mon, 26 Sep 2022 14:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E6=9C=9F=E6=97=B6=E9=97=B4=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/FBX/Materials/fffenggee.mat | 76 ++++ .../Model/FBX/Materials/fffenggee.mat.meta | 9 + Assets/Scenes/PrepareLessons.unity | 44 +- Assets/Scripts/CheckDateUseful.cs | 384 ++++++++++++++++++ Assets/Scripts/CheckDateUseful.cs.meta | 11 + Assets/StreamingAssets/xml.meta | 9 + Assets/StreamingAssets/xml/Validity.xml | 7 + Assets/StreamingAssets/xml/Validity.xml.meta | 8 + Assets/TimeLimit.prefab | 42 ++ Assets/TimeLimit.prefab.meta | 7 + ProjectSettings/EditorBuildSettings.asset | 4 +- 11 files changed, 597 insertions(+), 4 deletions(-) create mode 100644 Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat create mode 100644 Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat.meta create mode 100644 Assets/Scripts/CheckDateUseful.cs create mode 100644 Assets/Scripts/CheckDateUseful.cs.meta create mode 100644 Assets/StreamingAssets/xml.meta create mode 100644 Assets/StreamingAssets/xml/Validity.xml create mode 100644 Assets/StreamingAssets/xml/Validity.xml.meta create mode 100644 Assets/TimeLimit.prefab create mode 100644 Assets/TimeLimit.prefab.meta diff --git a/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat b/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat new file mode 100644 index 00000000..24800328 --- /dev/null +++ b/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat @@ -0,0 +1,76 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: fffenggee + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 0, b: 0, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat.meta b/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat.meta new file mode 100644 index 00000000..a82c37a2 --- /dev/null +++ b/Assets/MobileCommunication/Model/FBX/Materials/fffenggee.mat.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5e3c835a2c540884f991c28886ee5c41 +timeCreated: 1664153274 +licenseType: Pro +NativeFormatImporter: + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/PrepareLessons.unity b/Assets/Scenes/PrepareLessons.unity index a59bf63b..1d49d9c5 100644 --- a/Assets/Scenes/PrepareLessons.unity +++ b/Assets/Scenes/PrepareLessons.unity @@ -9117,8 +9117,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 428} m_HandleRect: {fileID: 284} m_Direction: 0 - m_Value: 0 - m_Size: 0.9242243 + m_Value: 1 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -11204,3 +11204,43 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1336960344} +--- !u!1 &1615115639 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1615115641} + - component: {fileID: 1615115640} + m_Layer: 0 + m_Name: TimeLimit + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1615115640 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1615115639} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ed6059b4b0846c747ad210996932c322, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1615115641 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1615115639} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/CheckDateUseful.cs b/Assets/Scripts/CheckDateUseful.cs new file mode 100644 index 00000000..665ace5c --- /dev/null +++ b/Assets/Scripts/CheckDateUseful.cs @@ -0,0 +1,384 @@ +using UnityEngine; +using System.Collections; +using System; +using System.Xml; +using System.IO; +using System.Text; +using System.Security.Cryptography; +using System.Security.Cryptography.Xml; + +public class CheckDateUseful : MonoBehaviour { + + private bool IsQuit = false; + private bool IsShowTips = false; + // Use this for initialization + + private DateTime t1, t2, t11; + string original_filepath = ""; + string encode_filepath = ""; + string decode_filepath = ""; + private int time_days = 30;//有效期30天 + + // Use this for initialization + void Start() + { + DontDestroyOnLoad(gameObject); + t2 = DateTime.Now; + t1 = DateTime.Now; + + tipStyle = new GUIStyle(); + tipStyle.fontSize = 40; + tipStyle.normal.textColor = Color.red; + + original_filepath = Application.streamingAssetsPath + @"/xml/Validity.xml"; + encode_filepath = Application.streamingAssetsPath + @"/xml/enValidity.xml"; + decode_filepath = Application.streamingAssetsPath + @"/xml/deValidity.xml"; + + ControlXML(); + } + string appid = "AXKC"; + bool useFul = true; + DateTime RegistrationDate; + DateTime LastUseTime; + public DateTime GetRegistrationDate(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "RegistrationDate") + { + return Convert.ToDateTime(elem.InnerText); + } + } + } + return DateTime.Now; + } + public DateTime GetLastUseTime(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "LastUseTime") + { + return Convert.ToDateTime(elem.InnerText); + } + } + } + return DateTime.Now; + } + public void SetLastUseTime(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "LastUseTime") + { + elem.InnerText = Convert.ToString(DateTime.Now); + } + } + xmlDoc.Save(filepath); + } + } + public bool GetUseful(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "Useful") + { + return Convert.ToBoolean(elem.InnerText); + } + } + } + return false; + } + public void SetUsefulFalse(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "Useful") + { + elem.InnerText = Convert.ToString(false); + } + } + xmlDoc.Save(filepath); + } + } + public void FirstSetXML(string filepath) + { + if (File.Exists(filepath)) + { + XmlDocument xmlDoc = new XmlDocument(); + xmlDoc.Load(filepath); + XmlNode root = xmlDoc.SelectSingleNode("assets"); + XmlNodeList nodeList = root.ChildNodes; + foreach (XmlElement elem in nodeList) + { + if (elem.Name == "Useful") + { + elem.InnerText = Convert.ToString(true); + } + if (elem.Name == "FirstExecute") + { + elem.InnerText = Convert.ToString(true); + } + if (elem.Name == "RegistrationDate") + { + elem.InnerText = Convert.ToString(DateTime.Now); + } + if (elem.Name == "OverTime") + { + + } + if (elem.Name == "LastUseTime") + { + elem.InnerText = Convert.ToString(DateTime.Now); + } + } + xmlDoc.Save(filepath); + } + } + + private GUIStyle tipStyle; + private int timer = 5; + string tips = "试用期已到,"; + void OnGUI() + { + if (IsQuit) + { + t2 = DateTime.Now; + if (t2 - t11 > new TimeSpan(0, 0, 1)) + { + if (timer > 0) + timer--; + t11 = t2; + } + //GUI.Label(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 75, 300, 150), tips + timer + "秒后退出!", tipStyle); + Debug.LogWarning(tips); + if (t2 - t1 > new TimeSpan(0, 0, 5)) + { + Debug.Log("程序退出!"); + Application.Quit(); + } + } + if (IsShowTips) + { + t2 = DateTime.Now; + if (t2 - t11 > new TimeSpan(0, 0, 1)) + { + if (timer > 0) + timer--; + t11 = t2; + } + //GUI.Label(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 75, 300, 150), tips + timer + "秒后关闭提示!", tipStyle); + Debug.LogWarning(tips); + if (t2 - t1 > new TimeSpan(0, 0, 3)) + { + IsShowTips = false; + } + + } + } + // Update is called once per frame + + + //xml文件加密解密 + + void ControlXML() + { + if (File.Exists(original_filepath))//如果找到原始文件,证明这次是第一次运行该程序,配置文件数据更新并生成加密文件 + { + FirstSetXML(original_filepath); + GenerateEncodeXML1(original_filepath); + } + else + { + if (File.Exists(encode_filepath)) + { + fileDcryption(encode_filepath); + if (File.Exists(decode_filepath)) + { + CheckUseful(); + + GenerateEncodeXML1(decode_filepath); + File.Delete(decode_filepath); + } + } + else + { + tips = "未检测到配置文件,"; + IsQuit = true; + IsShowTips = false; + return; + } + } + } + + void CheckUseful() + { + useFul = GetUseful(decode_filepath); + if (!useFul) + { + tips = "试用期已到,"; + IsQuit = true; + IsShowTips = false; + return; + } + LastUseTime = GetLastUseTime(decode_filepath);//上一次使用的时间 + if (DateTime.Now < LastUseTime) + { + tips = "检测到时间不匹配,"; + SetUsefulFalse(decode_filepath); + IsQuit = true; + IsShowTips = false; + return; + } + RegistrationDate = GetRegistrationDate(decode_filepath);//注册时间 + TimeSpan span = DateTime.Now.Subtract(RegistrationDate); + int days = Math.Abs(span.Days); + if (days <= time_days) + { + tips = "试用期还剩" + (time_days - days).ToString() + "天,"; + IsShowTips = true; + IsQuit = false; + SetLastUseTime(decode_filepath); + } + else + { + tips = "试用期结束,"; + SetUsefulFalse(decode_filepath); + IsQuit = true; + IsShowTips = false; + return; + } + + + } + IEnumerator GenerateEncodeXML() + { + yield return new WaitForSeconds(1.0f); + fileEncryption(original_filepath, "assets"); + if (File.Exists(encode_filepath)) + { + File.Delete(original_filepath); + } + } + void GenerateEncodeXML1(string filepath) + { + fileEncryption(filepath, "assets"); + if (File.Exists(encode_filepath)) + { + File.Delete(filepath); + } + } + //加密xml文件 + private void Encrypt(XmlDocument doc, string ElementName, SymmetricAlgorithm key) + { + XmlElement elementEncrypt = doc.GetElementsByTagName(ElementName)[0] as XmlElement; + EncryptedXml eXml = new EncryptedXml(); + byte[] encryptElement = eXml.EncryptData(elementEncrypt, key, false);// + EncryptedData edElement = new EncryptedData(); + edElement.Type = EncryptedXml.XmlEncElementUrl; + string encryptionMethod = null; + + if (key is TripleDES) + { + encryptionMethod = EncryptedXml.XmlEncTripleDESUrl; + } + else if (key is DES) + { + encryptionMethod = EncryptedXml.XmlEncDESUrl; + } + + if (key is Rijndael) + { + switch (key.KeySize) + { + case 128: + encryptionMethod = EncryptedXml.XmlEncAES128Url; + break; + case 192: + encryptionMethod = EncryptedXml.XmlEncAES192Url; + break; + case 256: + encryptionMethod = EncryptedXml.XmlEncAES256Url; + break; + } + } + edElement.EncryptionMethod = new EncryptionMethod(encryptionMethod); + edElement.CipherData.CipherValue = encryptElement; + EncryptedXml.ReplaceElement(elementEncrypt, edElement, false); + } + + //XML文件解密 + private void Decrypt(XmlDocument doc, SymmetricAlgorithm Alg) + { + XmlElement encryptedElement = doc.GetElementsByTagName("EncryptedData")[0] as XmlElement; + EncryptedData edElement = new EncryptedData(); + edElement.LoadXml(encryptedElement); + EncryptedXml exml = new EncryptedXml(); + byte[] rgbOutput = exml.DecryptData(edElement, Alg); + exml.ReplaceData(encryptedElement, rgbOutput); + } + + + //举例,对某个XML文件加密 + private void fileEncryption(string filename,string ElementName) + { + RijndaelManaged key = new RijndaelManaged(); + //设置密钥:key为32位=数字或字母16个=汉子8个 + byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); + key.Key = byteKey; + XmlDocument xmldoc = new XmlDocument(); + xmldoc.PreserveWhitespace = true; + xmldoc.Load(filename);//想要加密的xml文件 + Encrypt(xmldoc, ElementName, key);//需要加密的节点 + if (key != null) + { + key.Clear(); + } + xmldoc.Save(encode_filepath);//生成加密后的xml文件 + } + //举例,对某个xml文件解密 + private void fileDcryption(string filename) + { + RijndaelManaged key = new RijndaelManaged(); + byte[] byteKey = Encoding.Unicode.GetBytes("1111111111111111"); + key.Key = byteKey; + XmlDocument xmldoc = new XmlDocument(); + xmldoc.PreserveWhitespace = true; + xmldoc.Load(encode_filepath);//加载要解密的xml文件 + Decrypt(xmldoc, key); + if (key != null) + { + key.Clear(); + } + xmldoc.Save(decode_filepath);//生成解密后的文件 + } +} diff --git a/Assets/Scripts/CheckDateUseful.cs.meta b/Assets/Scripts/CheckDateUseful.cs.meta new file mode 100644 index 00000000..75b13a72 --- /dev/null +++ b/Assets/Scripts/CheckDateUseful.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ed6059b4b0846c747ad210996932c322 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StreamingAssets/xml.meta b/Assets/StreamingAssets/xml.meta new file mode 100644 index 00000000..df17d58e --- /dev/null +++ b/Assets/StreamingAssets/xml.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 80e7eff0d94074846b3374624b977faa +folderAsset: yes +timeCreated: 1664154874 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StreamingAssets/xml/Validity.xml b/Assets/StreamingAssets/xml/Validity.xml new file mode 100644 index 00000000..be8d34a6 --- /dev/null +++ b/Assets/StreamingAssets/xml/Validity.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Assets/StreamingAssets/xml/Validity.xml.meta b/Assets/StreamingAssets/xml/Validity.xml.meta new file mode 100644 index 00000000..f3a56538 --- /dev/null +++ b/Assets/StreamingAssets/xml/Validity.xml.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8acd2c7bfc11de7469deb8a346682cf8 +timeCreated: 1664164866 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TimeLimit.prefab b/Assets/TimeLimit.prefab new file mode 100644 index 00000000..577b809f --- /dev/null +++ b/Assets/TimeLimit.prefab @@ -0,0 +1,42 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &7510964028916638499 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 7510964028916638501} + - component: {fileID: 7510964028916638500} + m_Layer: 0 + m_Name: TimeLimit + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &7510964028916638500 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 7510964028916638499} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ed6059b4b0846c747ad210996932c322, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &7510964028916638501 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 7510964028916638499} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.46200034, y: 0.101851225, z: -0.10841513} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/TimeLimit.prefab.meta b/Assets/TimeLimit.prefab.meta new file mode 100644 index 00000000..b2b13386 --- /dev/null +++ b/Assets/TimeLimit.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 857ebbe9fbeb13242934e0d2b659ba00 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index aab04be3..6e7bbc36 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -38,13 +38,13 @@ EditorBuildSettings: - enabled: 0 path: Assets/Scenes/0.unity guid: f6a70eed2bbad9740b9ad510468f5cd3 - - enabled: 0 + - enabled: 1 path: Assets/Scenes/11.unity guid: 7263093372205c54fa8ba0968ac76a9e - enabled: 0 path: Assets/Scenes/1.unity guid: 3374f42471f44b74aa371dd9c8b2d604 - - enabled: 1 + - enabled: 0 path: Assets/Scenes/2.unity guid: 7117ff1ea3af4c646a2b73c19a84af20 - enabled: 0