From 28f9c1da4e15da09e10d73086b96d8bb5ba2e2cd Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Wed, 23 Apr 2025 13:36:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Editor/TimerLock.cs | 11 + Assets/Editor/TimerLock.cs.meta | 11 + Assets/Editor/Tools.cs | 51 ++ Assets/Editor/Tools.cs.meta | 11 + .../UIPrefabs/TimerCheckPanel.prefab | 630 ++++++++++++++++++ .../UIPrefabs/TimerCheckPanel.prefab.meta | 7 + Assets/StreamingAssets/Timer.txt | 1 + Assets/StreamingAssets/Timer.txt.meta | 7 + Assets/TimerLock.asset | 15 + Assets/TimerLock.asset.meta | 8 + .../_Scripts/Application/States/HomeState.cs | 12 + .../Application/States/TimerCheckState.cs | 24 + .../States/TimerCheckState.cs.meta | 11 + .../Application/UI/TimerCheckPanel.cs | 31 + .../Application/UI/TimerCheckPanel.cs.meta | 11 + Assets/_Scripts/NetWork.meta | 8 + Assets/_Scripts/NetWork/Encryption.meta | 8 + .../NetWork/Encryption/DateManager.cs | 91 +++ .../NetWork/Encryption/DateManager.cs.meta | 11 + .../NetWork/Encryption/DecryptFileReader.cs | 41 ++ .../Encryption/DecryptFileReader.cs.meta | 11 + .../NetWork/Encryption/EncryptFileCreator.cs | 56 ++ .../Encryption/EncryptFileCreator.cs.meta | 11 + Assets/_Scripts/NetWork/HttpRestful.cs | 73 ++ Assets/_Scripts/NetWork/HttpRestful.cs.meta | 11 + Assets/_Scripts/NetWork/Licence.meta | 8 + .../_Scripts/NetWork/Licence/LicenceData.cs | 46 ++ .../NetWork/Licence/LicenceData.cs.meta | 11 + .../NetWork/Licence/LicenseManager.cs | 179 +++++ .../NetWork/Licence/LicenseManager.cs.meta | 11 + 30 files changed, 1417 insertions(+) create mode 100644 Assets/Editor/TimerLock.cs create mode 100644 Assets/Editor/TimerLock.cs.meta create mode 100644 Assets/Editor/Tools.cs create mode 100644 Assets/Editor/Tools.cs.meta create mode 100644 Assets/Resources/UIPrefabs/TimerCheckPanel.prefab create mode 100644 Assets/Resources/UIPrefabs/TimerCheckPanel.prefab.meta create mode 100644 Assets/StreamingAssets/Timer.txt create mode 100644 Assets/StreamingAssets/Timer.txt.meta create mode 100644 Assets/TimerLock.asset create mode 100644 Assets/TimerLock.asset.meta create mode 100644 Assets/_Scripts/Application/States/TimerCheckState.cs create mode 100644 Assets/_Scripts/Application/States/TimerCheckState.cs.meta create mode 100644 Assets/_Scripts/Application/UI/TimerCheckPanel.cs create mode 100644 Assets/_Scripts/Application/UI/TimerCheckPanel.cs.meta create mode 100644 Assets/_Scripts/NetWork.meta create mode 100644 Assets/_Scripts/NetWork/Encryption.meta create mode 100644 Assets/_Scripts/NetWork/Encryption/DateManager.cs create mode 100644 Assets/_Scripts/NetWork/Encryption/DateManager.cs.meta create mode 100644 Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs create mode 100644 Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs.meta create mode 100644 Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs create mode 100644 Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs.meta create mode 100644 Assets/_Scripts/NetWork/HttpRestful.cs create mode 100644 Assets/_Scripts/NetWork/HttpRestful.cs.meta create mode 100644 Assets/_Scripts/NetWork/Licence.meta create mode 100644 Assets/_Scripts/NetWork/Licence/LicenceData.cs create mode 100644 Assets/_Scripts/NetWork/Licence/LicenceData.cs.meta create mode 100644 Assets/_Scripts/NetWork/Licence/LicenseManager.cs create mode 100644 Assets/_Scripts/NetWork/Licence/LicenseManager.cs.meta diff --git a/Assets/Editor/TimerLock.cs b/Assets/Editor/TimerLock.cs new file mode 100644 index 0000000..a7482a9 --- /dev/null +++ b/Assets/Editor/TimerLock.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "ʱ", menuName = "ʱ/ļ")] +public class TimerLock : ScriptableObject +{ + [Header("Ч")] + public string time; + +} diff --git a/Assets/Editor/TimerLock.cs.meta b/Assets/Editor/TimerLock.cs.meta new file mode 100644 index 0000000..2c653f7 --- /dev/null +++ b/Assets/Editor/TimerLock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5b8343931d7c9a49a1ff9597f3ba0c2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor/Tools.cs b/Assets/Editor/Tools.cs new file mode 100644 index 0000000..fa854c1 --- /dev/null +++ b/Assets/Editor/Tools.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using UnityEditor; +using UnityEngine; + +#if UNITY_EDITOR +public class Tools +{ + [MenuItem("Tools/ʱ")] + private static void TimerLock() + { + //Դļ + //Ǽ̳ScriptableObject + TimerLock asset = ScriptableObject.CreateInstance(); + //ǰһԴֻǴڴУҪ浽 + //ͨ༭APIһԴļڶΪԴļAssetsĿ¼µ· + AssetDatabase.CreateAsset(asset, "Assets/TimerLock.asset"); + //洴Դ + AssetDatabase.SaveAssets(); + //ˢ½ + AssetDatabase.Refresh(); + } + + [MenuItem("Tools/Timerļ")] + private static void GeneratorTimer() + { + if (File.Exists(Application.dataPath + "/TimerLock.asset")) + { + string path = "Assets/TimerLock.asset"; + var asset = AssetDatabase.LoadAssetAtPath(path); + if (asset != null) + { + if (string.IsNullOrEmpty(asset.time) == false) + { + //һλȡȡϵͳʱ + DateTime currentDateTime = DateTime.Now; + string RecordData = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + string strMerge = asset.time + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, "Timer.txt"); + } + } + } + //ˢ½ + AssetDatabase.Refresh(); + } + + + + +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Tools.cs.meta b/Assets/Editor/Tools.cs.meta new file mode 100644 index 0000000..08a17ec --- /dev/null +++ b/Assets/Editor/Tools.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0772e5557591b3a4997bc2f77ef34f50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab b/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab new file mode 100644 index 0000000..890a676 --- /dev/null +++ b/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab @@ -0,0 +1,630 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &603515846068347574 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2973387460174964899} + - component: {fileID: 4046774654178239024} + - component: {fileID: 6775752147316619189} + m_Layer: 5 + m_Name: Other2_N + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2973387460174964899 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 603515846068347574} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 9133111343023862921} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.12200001, y: 0.5231482} + m_AnchorMax: {x: 0.874, y: 0.8561482} + m_AnchoredPosition: {x: 1.5, y: 1} + m_SizeDelta: {x: 7, y: -4} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &4046774654178239024 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 603515846068347574} + m_CullTransparentMesh: 1 +--- !u!114 &6775752147316619189 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 603515846068347574} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 7ace1598f8a7c3d47b2c127e89fe6a21, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!1 &1146598296151246231 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4750655449581826011} + - component: {fileID: 4966594276472824005} + - component: {fileID: 1823834173995265821} + - component: {fileID: 1798522582073850381} + m_Layer: 5 + m_Name: Train_N + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &4750655449581826011 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1146598296151246231} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2888913759714920061} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 0} + m_AnchoredPosition: {x: 1.3491, y: 330} + m_SizeDelta: {x: 284, y: 76} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &4966594276472824005 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1146598296151246231} + m_CullTransparentMesh: 1 +--- !u!114 &1823834173995265821 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1146598296151246231} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 97d5d667b4207cd4198d9accb49a2e1c, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!114 &1798522582073850381 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1146598296151246231} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 2 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 21300000, guid: 0e1346da76c650844ac909b4fc2c6d49, + type: 3} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1823834173995265821} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!1 &2888913759714920062 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2888913759714920061} + - component: {fileID: 2888913759714920060} + m_Layer: 5 + m_Name: TrainModelPanel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2888913759714920061 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913759714920062} + 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_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 2888913760214439239} + - {fileID: 4750655449581826011} + m_Father: {fileID: 4130714088394774955} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &2888913759714920060 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913759714920062} + m_CullTransparentMesh: 1 +--- !u!1 &2888913760214439352 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2888913760214439239} + - component: {fileID: 2888913760214439237} + - component: {fileID: 2888913760214439238} + - component: {fileID: 8166912465334887831} + m_Layer: 5 + m_Name: Teach_N + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2888913760214439239 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913760214439352} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2888913759714920061} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 0} + m_AnchoredPosition: {x: 1.3491, y: 415.5491} + m_SizeDelta: {x: 284, y: 76} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &2888913760214439237 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913760214439352} + m_CullTransparentMesh: 1 +--- !u!114 &2888913760214439238 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913760214439352} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: e52ed5e3cd6db80459c9520802557f8f, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!114 &8166912465334887831 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2888913760214439352} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 2 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 21300000, guid: ef43cff673d43ef48badac85cfd8b156, + type: 3} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 2888913760214439238} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!1 &2901388735067139032 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 78317203956937394} + - component: {fileID: 2943517008154441021} + - component: {fileID: 3672005570292551768} + m_Layer: 5 + m_Name: Other1_N + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &78317203956937394 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2901388735067139032} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 9133111343023862921} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.100375, y: 0.20066665} + m_AnchorMax: {x: 0.89500004, y: 0.545} + m_AnchoredPosition: {x: 4.5, y: -0.5} + m_SizeDelta: {x: 11, y: 2} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &2943517008154441021 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2901388735067139032} + m_CullTransparentMesh: 1 +--- !u!114 &3672005570292551768 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2901388735067139032} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 4b3ac25c5ebd0ab41b0c5e3744d70e0e, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!1 &6683858983085824027 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8762010044699360691} + - component: {fileID: 2698470933306118203} + - component: {fileID: 7593153994056117987} + m_Layer: 5 + m_Name: BiaoTi_N + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &8762010044699360691 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6683858983085824027} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 9133111343023862921} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 274} + m_SizeDelta: {x: 1851, y: 112} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &2698470933306118203 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6683858983085824027} + m_CullTransparentMesh: 1 +--- !u!114 &7593153994056117987 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6683858983085824027} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: a8ceb856dc4f19c49b678813dc40f9d2, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!1 &8912481142875709138 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4130714088394774955} + m_Layer: 5 + m_Name: TimerCheckPanel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &4130714088394774955 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8912481142875709138} + 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_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 9133111343023862921} + - {fileID: 2888913759714920061} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 1920, y: 1080} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!1 &9133111343023862922 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 9133111343023862921} + - component: {fileID: 9133111343023862919} + - component: {fileID: 9133111343023862920} + m_Layer: 5 + m_Name: TrainBGPanel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &9133111343023862921 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9133111343023862922} + 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_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 78317203956937394} + - {fileID: 2973387460174964899} + - {fileID: 8762010044699360691} + m_Father: {fileID: 4130714088394774955} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &9133111343023862919 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9133111343023862922} + m_CullTransparentMesh: 1 +--- !u!114 &9133111343023862920 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9133111343023862922} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300000, guid: 9e4be6af4716004489f80f843948fa4a, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 diff --git a/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab.meta b/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab.meta new file mode 100644 index 0000000..5bdc35d --- /dev/null +++ b/Assets/Resources/UIPrefabs/TimerCheckPanel.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2339bd97a05734748b4394b9b5415761 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StreamingAssets/Timer.txt b/Assets/StreamingAssets/Timer.txt new file mode 100644 index 0000000..ca338a4 --- /dev/null +++ b/Assets/StreamingAssets/Timer.txt @@ -0,0 +1 @@ +ILBJ05 lj@{~PjaP+Z}> \ No newline at end of file diff --git a/Assets/StreamingAssets/Timer.txt.meta b/Assets/StreamingAssets/Timer.txt.meta new file mode 100644 index 0000000..3caaee2 --- /dev/null +++ b/Assets/StreamingAssets/Timer.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: aa0c91508fecffb4fb68596a0a07da40 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TimerLock.asset b/Assets/TimerLock.asset new file mode 100644 index 0000000..b7b6bb4 --- /dev/null +++ b/Assets/TimerLock.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c5b8343931d7c9a49a1ff9597f3ba0c2, type: 3} + m_Name: TimerLock + m_EditorClassIdentifier: + time: 2025-07-06 00:00:00 diff --git a/Assets/TimerLock.asset.meta b/Assets/TimerLock.asset.meta new file mode 100644 index 0000000..ecf186f --- /dev/null +++ b/Assets/TimerLock.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f30da0ad8d81325448a5006790548dd4 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/Application/States/HomeState.cs b/Assets/_Scripts/Application/States/HomeState.cs index bf49111..9dcd462 100644 --- a/Assets/_Scripts/Application/States/HomeState.cs +++ b/Assets/_Scripts/Application/States/HomeState.cs @@ -1,5 +1,7 @@ using CG.Framework; +using CG.UTility; using System; +using UnityEngine; /******************************************************************************** *Create By CG *Function ҳ״̬ @@ -15,6 +17,16 @@ namespace ZXK.LouDiXvMuNiu public override void EnterState() { UI_Manage.Instance.ShowPanel("HomePanel", Type.GetType("ZXK.LouDiXvMuNiu.HomePanel"), UIGroup.Main); + DateManager.UpdateTime(Tip, Tip, success: () => + { + }); + } + public void Tip(string str) + { + PopUpMng.PopAlert("", str, "ȷ", () => + { + Application.Quit(); + }); } } } diff --git a/Assets/_Scripts/Application/States/TimerCheckState.cs b/Assets/_Scripts/Application/States/TimerCheckState.cs new file mode 100644 index 0000000..f5a92c6 --- /dev/null +++ b/Assets/_Scripts/Application/States/TimerCheckState.cs @@ -0,0 +1,24 @@ +using CG.Framework; +using CG.UTility; +using System; +using UnityEngine; +/******************************************************************************** +*Create By CG +*Function ҳ״̬ +*********************************************************************************/ +namespace ZXK.LouDiXvMuNiu +{ + public class TimerCheckState : State + { + public override string _SceneName => "TimerCheck"; + public TimerCheckState(StateContext stateContext) : base(stateContext) + { + } + public override void EnterState() + { + + + } + + } +} diff --git a/Assets/_Scripts/Application/States/TimerCheckState.cs.meta b/Assets/_Scripts/Application/States/TimerCheckState.cs.meta new file mode 100644 index 0000000..83d5ca7 --- /dev/null +++ b/Assets/_Scripts/Application/States/TimerCheckState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ab0e00d8e8cede74982f2b8e93253470 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/Application/UI/TimerCheckPanel.cs b/Assets/_Scripts/Application/UI/TimerCheckPanel.cs new file mode 100644 index 0000000..ef7a7eb --- /dev/null +++ b/Assets/_Scripts/Application/UI/TimerCheckPanel.cs @@ -0,0 +1,31 @@ +using CG.Framework; +using CG.UTility; +using System; +/******************************************************************************* +*Create By CG +*Function +*******************************************************************************/ +namespace ZXK.LouDiXvMuNiu +{ + public class TimerCheckPanel : UIBase + { + protected override void Awake() + { + base.Awake(); + + + PopUpMng.PopAlert("ʾ", "ǰģ", "ȷ", () => { + if (GameManager.Instance._StateContext.GetState().Name.Equals("ExamState")) + { + PopUpMng._TriAble = false; + UI_Manage.Instance.ShowPanel("ScoreDataPanel", Type.GetType("ZXK.LouDiXvMuNiu.ScoreDataPanel"), UIGroup.Tip); + } + }); + + + + + + } + } +} \ No newline at end of file diff --git a/Assets/_Scripts/Application/UI/TimerCheckPanel.cs.meta b/Assets/_Scripts/Application/UI/TimerCheckPanel.cs.meta new file mode 100644 index 0000000..453a2a8 --- /dev/null +++ b/Assets/_Scripts/Application/UI/TimerCheckPanel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fd50c7322bfdad14d8f7cf2a9e33e0c1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork.meta b/Assets/_Scripts/NetWork.meta new file mode 100644 index 0000000..00d442c --- /dev/null +++ b/Assets/_Scripts/NetWork.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 212a0a4f9a45b9740af050a33918ac7b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Encryption.meta b/Assets/_Scripts/NetWork/Encryption.meta new file mode 100644 index 0000000..65aade6 --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb335401f53d3c94490f449b410da1ba +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Encryption/DateManager.cs b/Assets/_Scripts/NetWork/Encryption/DateManager.cs new file mode 100644 index 0000000..daeff58 --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/DateManager.cs @@ -0,0 +1,91 @@ +using System; +using System.IO; +using UnityEngine; +using UnityEngine.Events; + +public class DateManager +{ + + public static string EndTimer = "2025-07-06 00:00:00";//结束时间 + private static string RecordData; + private void Start() + { + // CreatTimer(); + } + + /// + /// 更新系统时间 + /// + public static void UpdateTime(UnityAction error = null, UnityAction timeOut = null, UnityAction update = null, UnityAction success = null) + { + try + { + string datas = DecryptFileReader.ReadAndDecryptData("Timer.txt"); + EndTimer = datas.Split('|')[0]; + RecordData = datas.Split('|')[1]; + //第一次获取获取系统时间 + DateTime currentDateTime = DateTime.Now; + string Data = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + if (DateTime.TryParse(RecordData, out DateTime recordDateTime) && DateTime.TryParse(Data, out DateTime nowDateTime)) + { + if (recordDateTime > nowDateTime) + { + Debug.Log("仿真文件被损坏,请联系管理员进行修复"); + error?.Invoke("仿真文件被损坏,请联系管理员进行修复"); + } + else + { + //把上一次存储得系统时间更新到最新 + string timer = "Timer.txt"; + RecordData = Data; + string strMerge = EndTimer + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, timer); + update?.Invoke(); + } + } + } + catch (Exception e) + { + Debug.LogError($"数据出错: {e.Message}"); + error?.Invoke($"数据出错: {e.Message}"); + } + + if (JudgeExpire()) + { + Debug.Log("请联系管理员进行升级"); + timeOut?.Invoke("请联系管理员进行升级"); + return; + } + success?.Invoke(); + } + + /// + /// 判断是否到期 + /// + /// + public static bool JudgeExpire() + { + if (DateTime.TryParse(EndTimer, out DateTime endDataTime) && DateTime.TryParse(RecordData, out DateTime recordDateTime)) + { + //结束日期小于目前日期代表到期 + if (endDataTime < recordDateTime) + { + return true; + } + } + return false; + } + + + /// + /// 给客户打包的时候,需要设置EndTimer,然后运行一次生成文件并注释掉 + /// + public static void CreatTimer() + { + //第一次获取获取系统时间 + DateTime currentDateTime = DateTime.Now; + RecordData = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + string strMerge = EndTimer + "|" + RecordData; + EncryptFileCreator.EncryptAndSaveData(strMerge, "Timer.txt"); + } +} diff --git a/Assets/_Scripts/NetWork/Encryption/DateManager.cs.meta b/Assets/_Scripts/NetWork/Encryption/DateManager.cs.meta new file mode 100644 index 0000000..8246b5b --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/DateManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 989d94de1a3619e4ea11eebacb08d0f7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs new file mode 100644 index 0000000..1c6d60f --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs @@ -0,0 +1,41 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class DecryptFileReader +{ + private static byte[] key = Encoding.UTF8.GetBytes("Sixteen byte key"); // 加密密钥,需与加密时一致 + private static byte[] iv = Encoding.UTF8.GetBytes("InitializationVe"); // 确保IV长度为16字节 + + public static string ReadAndDecryptData(string filePath) + { + string fullPath = Path.Combine(Application.streamingAssetsPath, filePath); + if (File.Exists(filePath)) return ""; + // 读取加密文件 + byte[] encryptedData = File.ReadAllBytes(fullPath); + + // 创建AES解密器 + using (Aes aesAlg = Aes.Create()) + { + aesAlg.Key = key; + aesAlg.IV = iv; + + ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); + + // 创建内存流和加密流 + using (MemoryStream msDecrypt = new MemoryStream(encryptedData)) + { + using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) + { + byte[] decryptedBytes = new byte[encryptedData.Length]; + int decryptedByteCount = csDecrypt.Read(decryptedBytes, 0, decryptedBytes.Length); + + // 将解密后的数据转换为字符串 + string decryptedData = Encoding.UTF8.GetString(decryptedBytes, 0, decryptedByteCount); + return decryptedData; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs.meta b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs.meta new file mode 100644 index 0000000..a4452c9 --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 354bc54210a77764ebad2d49b5e927ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs b/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs new file mode 100644 index 0000000..e19b7f2 --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs @@ -0,0 +1,56 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class EncryptFileCreator +{ + private static byte[] key = Encoding.UTF8.GetBytes("Sixteen byte key"); // 加密密钥,需16字节 + private static byte[] iv = Encoding.UTF8.GetBytes("InitializationVe"); // 确保IV长度为16字节 + + public static void EncryptAndSaveData(string data,string path) + { + string filePath = Path.Combine(Application.streamingAssetsPath, path); + if (!File.Exists(filePath)) + { + try + { + // 创建文件 + File.WriteAllText(filePath, ""); + Debug.Log("文件已创建"); + } + catch (IOException e) + { + Debug.LogError($"创建文件时出错: {e.Message}"); + } + } + // 将数据转换为字节数组 + byte[] plainText = Encoding.UTF8.GetBytes(data); + + // 创建AES加密器 + using (Aes aesAlg = Aes.Create()) + { + aesAlg.Key = key; + aesAlg.IV = iv; + + ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); + + // 创建内存流和加密流 + using (MemoryStream msEncrypt = new MemoryStream()) + { + using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) + { + csEncrypt.Write(plainText, 0, plainText.Length); + csEncrypt.FlushFinalBlock(); + + // 获取加密后的数据 + byte[] encryptedData = msEncrypt.ToArray(); + + // 保存加密文件到StreamingAssets文件夹 + string fullPath = Path.Combine(Application.streamingAssetsPath, filePath); + File.WriteAllBytes(fullPath, encryptedData); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs.meta b/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs.meta new file mode 100644 index 0000000..77d8e4b --- /dev/null +++ b/Assets/_Scripts/NetWork/Encryption/EncryptFileCreator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 22f7660ba2e708d4eb33622fe324499b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/HttpRestful.cs b/Assets/_Scripts/NetWork/HttpRestful.cs new file mode 100644 index 0000000..8079d5a --- /dev/null +++ b/Assets/_Scripts/NetWork/HttpRestful.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections; +using UnityEngine; +using UnityEngine.Networking; +using ZXKFramework; + +public class HttpRestful : SingletonDdol +{ + public void Get(string url, Action actionResult = null) + { + StartCoroutine(_Get(url, actionResult)); + } + + private IEnumerator _Get(string url, Action action) + { + using (UnityWebRequest request = UnityWebRequest.Get(url)) + { + yield return request.SendWebRequest(); + + string resstr = ""; + if (request.isNetworkError || request.isHttpError) + { + resstr = request.error; + } + else + { + resstr = request.downloadHandler.text; + } + + if (action != null) + { + action(request.isHttpError, resstr); + } + } + } + public void Post(string url, string form, Action callBack, string Header = null, string HeaderValue = null, int timeOut = 3) + { + + StartCoroutine(_Post(url, form, callBack, Header, HeaderValue, timeOut)); + } + + public IEnumerator _Post(string url, string form, Action callBack, string Header = null, string HeaderValue = null, int timeOut = 3) + { + //请求链接,并将form对象发送到远程服务器 + using (UnityWebRequest webRequest = UnityWebRequest.Post(url, form, "application/json"))//;charset=utf-8 + { + if (!string.IsNullOrEmpty(Header) && !string.IsNullOrEmpty(HeaderValue)) + { + webRequest.SetRequestHeader(Header, HeaderValue); + } + webRequest.timeout = timeOut * 1000; + yield return webRequest.SendWebRequest(); + if (webRequest.result!= UnityWebRequest.Result.Success) + { + Debug.Log(webRequest.error); + callBack?.Invoke(false, webRequest.downloadHandler); + } + else + { + callBack?.Invoke(true, webRequest.downloadHandler); + } + //if (webRequest.isHttpError || webRequest.isNetworkError) + //{ + // //Debug.LogError("==========="); + // callBack?.Invoke(false, null); + //} + //else + //{ + // callBack?.Invoke(true, webRequest.downloadHandler); + //} + }; + } +} \ No newline at end of file diff --git a/Assets/_Scripts/NetWork/HttpRestful.cs.meta b/Assets/_Scripts/NetWork/HttpRestful.cs.meta new file mode 100644 index 0000000..2fa9020 --- /dev/null +++ b/Assets/_Scripts/NetWork/HttpRestful.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cca16177d7a134a43a4fb3320d5b8fc7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Licence.meta b/Assets/_Scripts/NetWork/Licence.meta new file mode 100644 index 0000000..a4c0b9c --- /dev/null +++ b/Assets/_Scripts/NetWork/Licence.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 32677377141e60248a7a2484825ce1d4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Licence/LicenceData.cs b/Assets/_Scripts/NetWork/Licence/LicenceData.cs new file mode 100644 index 0000000..d84ee2c --- /dev/null +++ b/Assets/_Scripts/NetWork/Licence/LicenceData.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LicenceData +{ + public string project_id; + public string user_name; + public string license_code; + public string host_id; + public string duration; //使用时长 + public string sign; +} +public class Datas +{ + public static string Project_id = "7"; + public static string secretKey = "pZNwkYoMRp7MG_O7aGtmA"; + public static string UserName; + public static string Licensecode; + public static string Hostid; + public static int Duration;//持续时间 +} +[Serializable] +public class License +{ + public int id; + public string user_name; + public string license_code; + public int is_authorized; + public string host_id; + public string authorization_at; + public string authorization_end_at; + public string created_at; + public int login_count; + public int duration; + public string last_login; +} + +[Serializable] +public class LicenseValidationResponse +{ + public string status; + public string message; + public License license; +} \ No newline at end of file diff --git a/Assets/_Scripts/NetWork/Licence/LicenceData.cs.meta b/Assets/_Scripts/NetWork/Licence/LicenceData.cs.meta new file mode 100644 index 0000000..de5c59a --- /dev/null +++ b/Assets/_Scripts/NetWork/Licence/LicenceData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f40d10c2dcbad941ac179b38fde96bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/NetWork/Licence/LicenseManager.cs b/Assets/_Scripts/NetWork/Licence/LicenseManager.cs new file mode 100644 index 0000000..06c24c2 --- /dev/null +++ b/Assets/_Scripts/NetWork/Licence/LicenseManager.cs @@ -0,0 +1,179 @@ +using LitJson; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Security.Cryptography; +using System.Text; +using UnityEngine; + +public class LicenseManager : MonoBehaviour +{ + private Dictionary Data = new(); + private LicenseValidationResponse LicenseRes = new LicenseValidationResponse(); + private string Hostid = ""; + + public void Init() + { + Hostid = GetPhysicalAddress(); + Datas.Hostid = Hostid; + } + public LicenceData GetLicenceData(string projectid, string userName, string licensecode, string hostid, int duration) + { + Data.Clear(); + LicenceData licence = new LicenceData(); + licence.project_id = projectid; + licence.user_name = userName; + licence.license_code = licensecode; + licence.host_id = hostid; + licence.duration = duration.ToString(); + if (!Data.ContainsKey("project_id")) + { + Data.Add("project_id", licence.project_id); + } + if (!Data.ContainsKey("user_name")) + { + Data.Add("user_name", licence.user_name); + } + if (!Data.ContainsKey("license_code")) + { + Data.Add("license_code", licence.license_code); + } + if (!Data.ContainsKey("host_id")) + { + Data.Add("host_id", licence.host_id); + } + if (!Data.ContainsKey("duration")) + { + Data.Add("duration", licence.duration); + } + licence.sign = GenerateSignature(Datas.secretKey, Data); + return licence; + } + /// + /// 请求 + /// + /// + /// + public void LicensePost(Action callBack = null) + { + LicenceData licence = GetLicenceData(Datas.Project_id, Datas.UserName, Datas.Licensecode, Datas.Hostid, Datas.Duration); + string json = JsonMapper.ToJson(licence); + HttpRestful.Instance.Post("https://locallicense.zxkedu.com/api/license/validate/", json, (m, n) => + { + LicenseRes = JsonMapper.ToObject(n.text); + if (LicenseRes.status == "success") + { + EncryptedFile(); + } + callBack.Invoke(m); + }); + } + + /// + /// 生成密匙 + /// + /// + /// + /// + public string GenerateSignature(string secretKey, Dictionary data) + { + // 添加当前时间戳 + //string timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); + //获取当前时间戳并四舍五入到最近的分钟 + long timestamp = (long)(DateTimeOffset.UtcNow.ToUnixTimeSeconds() / 60) * 60; + //long timestamp = (long)(GetTimestamp() / 60) * 60; + if (!data.ContainsKey("timestamp")) + { + data.Add("timestamp", timestamp.ToString()); + } + else + { + data["timestamp"] = timestamp.ToString(); + } + // 对键值对进行排序 + var sortedData = data.OrderBy(kvp => kvp.Key); + Debug.Log("sortedData对键值对进行排序:" + sortedData); + + // 构建查询字符串 + string queryString = string.Join("&", sortedData.Select(kvp => $"{kvp.Key}={kvp.Value}")); + Debug.Log("queryString构建查询字符串:" + queryString); + // 使用HMAC-SHA256生成签名 + using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey))) + { + byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(queryString)); + Debug.Log("生成签名:" + BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant()); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } + } + + public void StartSetDuration() + { + if (gameObject.activeSelf) + { + StartCoroutine(SetDuration(60f)); + } + } + + IEnumerator SetDuration(float times) + { + while (true) + { + yield return new WaitForSeconds(times); + Datas.Duration++; + LicensePost(); + Datas.Duration = 0; + } + } + public string GetMachineGuid() + { + if (string.IsNullOrEmpty(Hostid)) + { + NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces(); + foreach (NetworkInterface ni in nis) + { + if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || + ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) + { + Hostid = ni.GetPhysicalAddress().ToString(); + break; + } + } + } + return Hostid; + } + + string GetPhysicalAddress() + { + //string physicalAddress = ""; + //NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces(); + //foreach (NetworkInterface ni in nis) + //{ + // if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && ni.OperationalStatus == OperationalStatus.Up) + // { + // physicalAddress = ni.GetPhysicalAddress().ToString(); + // break; + // } + //} + return SystemInfo.deviceUniqueIdentifier; + } + + /// + /// 本地存储Hostid + /// + public void EncryptedFile() + { + string dataToEncrypt = Datas.UserName + "|" + Datas.Licensecode + "|"; + EncryptFileCreator.EncryptAndSaveData(dataToEncrypt, "encryptedData.txt"); + } + /// + /// 读取Hostid + /// + /// + public string ReadDecryptedFile() + { + string decryptedData = DecryptFileReader.ReadAndDecryptData("encryptedData.txt"); + return decryptedData; + } +} diff --git a/Assets/_Scripts/NetWork/Licence/LicenseManager.cs.meta b/Assets/_Scripts/NetWork/Licence/LicenseManager.cs.meta new file mode 100644 index 0000000..b85899a --- /dev/null +++ b/Assets/_Scripts/NetWork/Licence/LicenseManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13a2f840c2d90a44b8473ca7cf9adef1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: