diff --git a/Editor/BuildHotfix/BuildHotfixHelper.cs b/Editor/BuildHotfix/BuildHotfixHelper.cs index fd08aad..23c25b2 100644 --- a/Editor/BuildHotfix/BuildHotfixHelper.cs +++ b/Editor/BuildHotfix/BuildHotfixHelper.cs @@ -57,7 +57,7 @@ public static void CopyHotfixCode() continue; } - File.Copy(srcPath, Path.Combine(CodeDir, hotfix + Utility.Const.FileNameSuffix.Binary), true); + File.Copy(srcPath, Path.Combine(CodeDir, hotfix + FileNameSuffix.Binary), true); } Debug.Log($"复制Hotfix DLL到{CodeDir}完成"); @@ -78,7 +78,7 @@ public static void CopyAOTCode() Directory.CreateDirectory(AOTCodeDir); } - FileHelper.CleanDirectory(AOTCodeDir); + FileUtility.CleanDirectory(AOTCodeDir); DirectoryInfo directoryInfo = new DirectoryInfo(Application.dataPath); string path = Path.Combine(directoryInfo.Parent.FullName, "HybridCLRData", "AssembliesPostIl2CppStrip", EditorUserBuildSettings.activeBuildTarget.ToString()); @@ -95,7 +95,7 @@ public static void CopyAOTCode() foreach (var fileInfo in files) { stringBuilder.AppendLine(fileInfo.Name); - fileInfo.CopyTo(AOTCodeDir + "/" + fileInfo.Name + Utility.Const.FileNameSuffix.Binary, true); + fileInfo.CopyTo(AOTCodeDir + "/" + fileInfo.Name + FileNameSuffix.Binary, true); } Debug.Log(stringBuilder); diff --git a/Editor/BuildProduct/BuildProductHelper.cs b/Editor/BuildProduct/BuildProductHelper.cs index 3a147f8..5e17d90 100644 --- a/Editor/BuildProduct/BuildProductHelper.cs +++ b/Editor/BuildProduct/BuildProductHelper.cs @@ -17,11 +17,13 @@ namespace GameFrameX.Editor public static class BuildProductHelper { private static string _buildPath; + private const int ScreenWidth = 1080; + private const int ScreenHeight = 1920; private static List RunHook(System.Type hookType) { List result = new List(); - var types = Utility.Assembly.GetTypes(); + var types = AssemblyUtility.GetTypes(); foreach (var type in types) { if (type.IsAbstract) @@ -87,8 +89,8 @@ public static void BuildPlayerToActiveBuildTarget() if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSX) { PlayerSettings.fullScreenMode = FullScreenMode.Windowed; - PlayerSettings.defaultScreenHeight = 720; - PlayerSettings.defaultScreenWidth = 1280; + PlayerSettings.defaultScreenHeight = ScreenHeight; + PlayerSettings.defaultScreenWidth = ScreenWidth; } AssetDatabase.SaveAssets(); @@ -113,8 +115,8 @@ public static void BuildPlayerToWindows64BuildTarget() { HotFixEditorCompilerHelper.AddEditor(); PlayerSettings.fullScreenMode = FullScreenMode.Windowed; - PlayerSettings.defaultScreenHeight = 720; - PlayerSettings.defaultScreenWidth = 1280; + PlayerSettings.defaultScreenHeight = ScreenHeight; + PlayerSettings.defaultScreenWidth = ScreenWidth; EditorUserBuildSettings.selectedStandaloneTarget = BuildTarget.StandaloneWindows64; UpdateBuildTime(); AssetDatabase.SaveAssets(); @@ -142,7 +144,7 @@ public static void BuildPlayerToWindows64BuildTarget() var pathName = Path.GetDirectoryName(resultDirectory); Debug.Log("Build Output Path:" + resultDirectory); - // ZipHelper.CompressDirectory(resultDirectory, pathName + ".zip"); + // ZipUtility.CompressDirectory(resultDirectory, pathName + ".zip"); } finally { @@ -166,8 +168,8 @@ public static void BuildPlayerToWindows32BuildTarget() { HotFixEditorCompilerHelper.AddEditor(); PlayerSettings.fullScreenMode = FullScreenMode.Windowed; - PlayerSettings.defaultScreenHeight = 720; - PlayerSettings.defaultScreenWidth = 1280; + PlayerSettings.defaultScreenHeight = ScreenHeight; + PlayerSettings.defaultScreenWidth = ScreenWidth; EditorUserBuildSettings.selectedStandaloneTarget = BuildTarget.StandaloneWindows; UpdateBuildTime(); AssetDatabase.SaveAssets(); @@ -196,7 +198,7 @@ public static void BuildPlayerToWindows32BuildTarget() var pathName = Path.GetDirectoryName(resultDirectory); Debug.Log("Build Output Path:" + resultDirectory); - // ZipHelper.CompressDirectory(resultDirectory, pathName + ".zip"); + // ZipUtility.CompressDirectory(resultDirectory, pathName + ".zip"); } finally { @@ -219,8 +221,8 @@ public static void BuildPlayerToMacBuildTarget() HotFixEditorCompilerHelper.AddEditor(); // PlayerSettings.SplashScreen.show = false; PlayerSettings.fullScreenMode = FullScreenMode.Windowed; - PlayerSettings.defaultScreenHeight = 720; - PlayerSettings.defaultScreenWidth = 1280; + PlayerSettings.defaultScreenHeight = ScreenHeight; + PlayerSettings.defaultScreenWidth = ScreenWidth; UpdateBuildTime(); AssetDatabase.SaveAssets(); @@ -247,7 +249,7 @@ public static void BuildPlayerToMacBuildTarget() var pathName = Path.GetDirectoryName(resultDirectory); Debug.Log("Build Output Path:" + resultDirectory); - // ZipHelper.CompressDirectory(resultDirectory, pathName + ".zip"); + // ZipUtility.CompressDirectory(resultDirectory, pathName + ".zip"); } finally { @@ -439,7 +441,7 @@ private static void BuildAppBundleForAndroid() EditorUserBuildSettings.buildAppBundle = true; // 开启符号表的输出 - EditorUserBuildSettings.androidCreateSymbolsZip = true; + EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Debugging; AssetDatabase.SaveAssets(); _buildPath = aabFilePath; RunPreHookBuild(); @@ -725,9 +727,7 @@ private static string BuildOutputPath() switch (EditorUserBuildSettings.activeBuildTarget) { case BuildTarget.StandaloneOSX: - case BuildTarget.StandaloneOSXIntel: case BuildTarget.StandaloneWindows: - case BuildTarget.StandaloneLinux: case BuildTarget.StandaloneWindows64: case BuildTarget.WebGL: case BuildTarget.StandaloneLinux64: diff --git a/Editor/Cropping/CroppingWindow.cs b/Editor/Cropping/CroppingWindow.cs index b638ad9..ffc4e5b 100644 --- a/Editor/Cropping/CroppingWindow.cs +++ b/Editor/Cropping/CroppingWindow.cs @@ -77,7 +77,7 @@ private void OnGUI() else { string searchText = _searchText.ToLower(); - var types = Utility.Assembly.GetTypes(); + var types = AssemblyUtility.GetTypes(); var result = new List(); foreach (var type in types) { @@ -138,7 +138,7 @@ private void OnGUI() private void Generate(string targetTypeName) { _generatedText = string.Empty; - var targetType = Utility.Assembly.GetType(targetTypeName); + var targetType = AssemblyUtility.GetType(targetTypeName); if (targetType != null) { var types = targetType.Assembly.GetTypes(); diff --git a/Editor/Extension.meta b/Editor/Extension.meta new file mode 100644 index 0000000..5db8468 --- /dev/null +++ b/Editor/Extension.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c04bb00a646555f4fabf2f6dd1e3c405 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Extension/ObjectExtensions.cs b/Editor/Extension/ObjectExtensions.cs new file mode 100644 index 0000000..d5af0a9 --- /dev/null +++ b/Editor/Extension/ObjectExtensions.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace GameFrameX.Editor +{ + public static class ObjectExtensions + { + public static string GetAssetPath(this Object obj) + { + return AssetDatabase.GetAssetPath(obj); + } + + public static string GetAssetGUID(this Object obj) + { + return AssetDatabase.AssetPathToGUID(GetAssetPath(obj)); + } + + public static Texture2D[] GetMaterialTextures(this Material material) + { + var result = new List(); + + var dependencies = EditorUtility.CollectDependencies(new Object[] {material}); + foreach (var item in dependencies) + { + if (!(item is Texture2D texture)) + { + continue; + } + + result.Add(texture); + } + + return result.ToArray(); + } + } +} \ No newline at end of file diff --git a/Editor/Extension/ObjectExtensions.cs.meta b/Editor/Extension/ObjectExtensions.cs.meta new file mode 100644 index 0000000..cb77407 --- /dev/null +++ b/Editor/Extension/ObjectExtensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: abdd10e42c51468abed7b9025a649975 +timeCreated: 1638280702 \ No newline at end of file diff --git a/Editor/Helper.meta b/Editor/Helper.meta new file mode 100644 index 0000000..00efc5a --- /dev/null +++ b/Editor/Helper.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8e2aa8fce62841798ddd456074d7cadf +timeCreated: 1781012607 \ No newline at end of file diff --git a/Runtime/Utility/Utility.cs b/Editor/Helper/EditorHelper.cs similarity index 64% rename from Runtime/Utility/Utility.cs rename to Editor/Helper/EditorHelper.cs index 3b2472f..75ab9e6 100644 --- a/Runtime/Utility/Utility.cs +++ b/Editor/Helper/EditorHelper.cs @@ -1,17 +1,17 @@ -// ========================================================================================== +// ========================================================================================== // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 // GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights // 均受中华人民共和国及相关国际法律法规保护。 // are protected by the laws of the People's Republic of China and relevant international regulations. -// +// // 使用本项目须严格遵守相应法律法规及开源许可证之规定。 // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// +// // 本项目采用 Apache License 2.0 许可证分发, // This project is licensed under the Apache License 2.0, // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 // please refer to the LICENSE file in the root directory of the source code for the full license text. -// +// // 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 // It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, // 侵犯他人合法权益等法律法规所禁止的行为! @@ -20,7 +20,7 @@ // Any legal disputes and liabilities arising from secondary development based on this project // 本项目组织与贡献者概不承担。 // shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// +// // GitHub 仓库:https://github.com/GameFrameX // GitHub Repository: https://github.com/GameFrameX // Gitee 仓库:https://gitee.com/GameFrameX @@ -31,15 +31,51 @@ // Official Documentation: https://gameframex.doc.alianblank.com/ // ========================================================================================== -namespace GameFrameX.Runtime +using UnityEditor; +using UnityEngine; + +namespace GameFrameX.Editor { /// - /// 实用函数集。 + /// 编辑器帮助类。 /// /// - /// Utility functions collection. + /// Editor helper class. /// - public static partial class Utility + public static class EditorHelper { + public static bool DeveloperMode + { + get => EditorPrefs.GetBool("DeveloperMode"); + set => EditorPrefs.SetBool("DeveloperMode", value); + } + + private static string _projectRoot; + public static string ProjectRoot + { + get + { + if (string.IsNullOrEmpty(_projectRoot)) + { + _projectRoot = Application.dataPath.Replace("/Assets", ""); + } + + return _projectRoot; + } + } + + private static string _projectRootWithSplit; + public static string ProjectRootWithSplit + { + get + { + if (string.IsNullOrEmpty(_projectRootWithSplit)) + { + _projectRootWithSplit = ProjectRoot + "/"; + } + + return _projectRootWithSplit; + } + } } } \ No newline at end of file diff --git a/Editor/Helper/EditorHelper.cs.meta b/Editor/Helper/EditorHelper.cs.meta new file mode 100644 index 0000000..f403e87 --- /dev/null +++ b/Editor/Helper/EditorHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8ec718a698c74f42a694d3c9d6e93b79 +timeCreated: 1781012689 \ No newline at end of file diff --git a/Editor/Inspector/BaseComponentInspector.cs b/Editor/Inspector/BaseComponentInspector.cs index 1157f0b..cbe8d54 100644 --- a/Editor/Inspector/BaseComponentInspector.cs +++ b/Editor/Inspector/BaseComponentInspector.cs @@ -224,7 +224,7 @@ private void RefreshTypeNames() NoneOptionName }; - textHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(Utility.Text.ITextHelper))); + textHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(GameFrameworkText.ITextHelper))); m_TextHelperTypeNames = textHelperTypeNames.ToArray(); m_TextHelperTypeNameIndex = 0; if (!string.IsNullOrEmpty(m_TextHelperTypeName.stringValue)) @@ -278,7 +278,7 @@ private void RefreshTypeNames() NoneOptionName }; - compressionHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(Utility.Compression.ICompressionHelper))); + compressionHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(GameFrameworkCompression.ICompressionHelper))); m_CompressionHelperTypeNames = compressionHelperTypeNames.ToArray(); m_CompressionHelperTypeNameIndex = 0; if (!string.IsNullOrEmpty(m_CompressionHelperTypeName.stringValue)) @@ -296,7 +296,7 @@ private void RefreshTypeNames() NoneOptionName }; - jsonHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(Utility.Json.IJsonHelper))); + jsonHelperTypeNames.AddRange(TypeHelper.GetRuntimeTypeNames(typeof(GameFrameworkJson.IJsonHelper))); m_JsonHelperTypeNames = jsonHelperTypeNames.ToArray(); m_JsonHelperTypeNameIndex = 0; if (!string.IsNullOrEmpty(m_JsonHelperTypeName.stringValue)) diff --git a/Editor/Inspector/ComponentTypeComponentInspector.cs b/Editor/Inspector/ComponentTypeComponentInspector.cs index 349ff1c..ce6f29a 100644 --- a/Editor/Inspector/ComponentTypeComponentInspector.cs +++ b/Editor/Inspector/ComponentTypeComponentInspector.cs @@ -57,7 +57,7 @@ protected void RefreshComponentTypeNames(System.Type type) NoneOptionName }; - managerTypeNames.AddRange(Utility.Assembly.GetRuntimeTypeNames(type)); + managerTypeNames.AddRange(AssemblyUtility.GetRuntimeTypeNames(type)); ComponentTypeNames = managerTypeNames.ToArray(); ComponentTypeNameIndex = 0; if (!ComponentType.stringValue.IsNullOrEmpty()) diff --git a/Editor/Inspector/ObjectPoolComponentInspector.cs b/Editor/Inspector/ObjectPoolComponentInspector.cs index 235ce01..1df439e 100644 --- a/Editor/Inspector/ObjectPoolComponentInspector.cs +++ b/Editor/Inspector/ObjectPoolComponentInspector.cs @@ -114,8 +114,8 @@ private void DrawObjectPool(ObjectPoolBase objectPool) { EditorGUILayout.LabelField(string.IsNullOrEmpty(objectInfo.Name) ? "" : objectInfo.Name, objectPool.AllowMultiSpawn - ? Utility.Text.Format("{0}\t{1}\t{2}\t{3}\t{4:yyyy-MM-dd HH:mm:ss}", objectInfo.Locked, objectInfo.SpawnCount, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()) - : Utility.Text.Format("{0}\t{1}\t{2}\t{3}\t{4:yyyy-MM-dd HH:mm:ss}", objectInfo.Locked, objectInfo.IsInUse, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime())); + ? GameFrameworkText.Format("{0}\t{1}\t{2}\t{3}\t{4:yyyy-MM-dd HH:mm:ss}", objectInfo.Locked, objectInfo.SpawnCount, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()) + : GameFrameworkText.Format("{0}\t{1}\t{2}\t{3}\t{4:yyyy-MM-dd HH:mm:ss}", objectInfo.Locked, objectInfo.IsInUse, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime())); } if (GUILayout.Button("Release")) @@ -130,27 +130,27 @@ private void DrawObjectPool(ObjectPoolBase objectPool) if (GUILayout.Button("Export CSV Data")) { - string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, Utility.Text.Format("Object Pool Data - {0}.csv", objectPool.Name), string.Empty); + string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, GameFrameworkText.Format("Object Pool Data - {0}.csv", objectPool.Name), string.Empty); if (!string.IsNullOrEmpty(exportFileName)) { try { int index = 0; string[] data = new string[objectInfos.Length + 1]; - data[index++] = Utility.Text.Format("Name,Locked,{0},Custom Can Release Flag,Priority,Last Use Time", objectPool.AllowMultiSpawn ? "Count" : "In Use"); + data[index++] = GameFrameworkText.Format("Name,Locked,{0},Custom Can Release Flag,Priority,Last Use Time", objectPool.AllowMultiSpawn ? "Count" : "In Use"); foreach (ObjectInfo objectInfo in objectInfos) { data[index++] = objectPool.AllowMultiSpawn - ? Utility.Text.Format("{0},{1},{2},{3},{4},{5:yyyy-MM-dd HH:mm:ss}", objectInfo.Name, objectInfo.Locked, objectInfo.SpawnCount, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()) - : Utility.Text.Format("{0},{1},{2},{3},{4},{5:yyyy-MM-dd HH:mm:ss}", objectInfo.Name, objectInfo.Locked, objectInfo.IsInUse, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()); + ? GameFrameworkText.Format("{0},{1},{2},{3},{4},{5:yyyy-MM-dd HH:mm:ss}", objectInfo.Name, objectInfo.Locked, objectInfo.SpawnCount, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()) + : GameFrameworkText.Format("{0},{1},{2},{3},{4},{5:yyyy-MM-dd HH:mm:ss}", objectInfo.Name, objectInfo.Locked, objectInfo.IsInUse, objectInfo.CustomCanReleaseFlag, objectInfo.Priority, objectInfo.LastUseTime.ToLocalTime()); } File.WriteAllLines(exportFileName, data, Encoding.UTF8); - Debug.Log(Utility.Text.Format("Export object pool CSV data to '{0}' success.", exportFileName)); + Debug.Log(GameFrameworkText.Format("Export object pool CSV data to '{0}' success.", exportFileName)); } catch (Exception exception) { - Debug.LogError(Utility.Text.Format("Export object pool CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception)); + Debug.LogError(GameFrameworkText.Format("Export object pool CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception)); } } } diff --git a/Editor/Inspector/ReferencePoolComponentInspector.cs b/Editor/Inspector/ReferencePoolComponentInspector.cs index fbae4f6..1d5bde9 100644 --- a/Editor/Inspector/ReferencePoolComponentInspector.cs +++ b/Editor/Inspector/ReferencePoolComponentInspector.cs @@ -113,7 +113,7 @@ public override void OnInspectorGUI() if (GUILayout.Button("Export CSV Data")) { - string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, Utility.Text.Format("Reference Pool Data - {0}.csv", assemblyReferencePoolInfo.Key), string.Empty); + string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, GameFrameworkText.Format("Reference Pool Data - {0}.csv", assemblyReferencePoolInfo.Key), string.Empty); if (!string.IsNullOrEmpty(exportFileName)) { try @@ -123,15 +123,15 @@ public override void OnInspectorGUI() data[index++] = "Class Name,Full Class Name,Unused,Using,Acquire,Release,Add,Remove"; foreach (ReferencePoolInfo referencePoolInfo in assemblyReferencePoolInfo.Value) { - data[index++] = Utility.Text.Format("{0},{1},{2},{3},{4},{5},{6},{7}", referencePoolInfo.Type.Name, referencePoolInfo.Type.FullName, referencePoolInfo.UnusedReferenceCount, referencePoolInfo.UsingReferenceCount, referencePoolInfo.AcquireReferenceCount, referencePoolInfo.ReleaseReferenceCount, referencePoolInfo.AddReferenceCount, referencePoolInfo.RemoveReferenceCount); + data[index++] = GameFrameworkText.Format("{0},{1},{2},{3},{4},{5},{6},{7}", referencePoolInfo.Type.Name, referencePoolInfo.Type.FullName, referencePoolInfo.UnusedReferenceCount, referencePoolInfo.UsingReferenceCount, referencePoolInfo.AcquireReferenceCount, referencePoolInfo.ReleaseReferenceCount, referencePoolInfo.AddReferenceCount, referencePoolInfo.RemoveReferenceCount); } File.WriteAllLines(exportFileName, data, Encoding.UTF8); - Debug.Log(Utility.Text.Format("Export reference pool CSV data to '{0}' success.", exportFileName)); + Debug.Log(GameFrameworkText.Format("Export reference pool CSV data to '{0}' success.", exportFileName)); } catch (Exception exception) { - Debug.LogError(Utility.Text.Format("Export reference pool CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception)); + Debug.LogError(GameFrameworkText.Format("Export reference pool CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception)); } } } @@ -159,7 +159,7 @@ private void OnEnable() private void DrawReferencePoolInfo(ReferencePoolInfo referencePoolInfo) { - EditorGUILayout.LabelField(m_ShowFullClassName ? referencePoolInfo.Type.FullName : referencePoolInfo.Type.Name, Utility.Text.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", referencePoolInfo.UnusedReferenceCount, referencePoolInfo.UsingReferenceCount, referencePoolInfo.AcquireReferenceCount, referencePoolInfo.ReleaseReferenceCount, referencePoolInfo.AddReferenceCount, referencePoolInfo.RemoveReferenceCount)); + EditorGUILayout.LabelField(m_ShowFullClassName ? referencePoolInfo.Type.FullName : referencePoolInfo.Type.Name, GameFrameworkText.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", referencePoolInfo.UnusedReferenceCount, referencePoolInfo.UsingReferenceCount, referencePoolInfo.AcquireReferenceCount, referencePoolInfo.ReleaseReferenceCount, referencePoolInfo.AddReferenceCount, referencePoolInfo.RemoveReferenceCount)); } private int Comparison(ReferencePoolInfo a, ReferencePoolInfo b) diff --git a/Editor/Misc/HelperInfo.cs b/Editor/Misc/HelperInfo.cs index 6e9e8df..414ea29 100644 --- a/Editor/Misc/HelperInfo.cs +++ b/Editor/Misc/HelperInfo.cs @@ -62,14 +62,14 @@ public HelperInfo(string name) public void Init(SerializedObject serializedObject) { - m_HelperTypeName = serializedObject.FindProperty(Utility.Text.Format("m_{0}HelperTypeName", m_Name)); - m_CustomHelper = serializedObject.FindProperty(Utility.Text.Format("m_Custom{0}Helper", m_Name)); + m_HelperTypeName = serializedObject.FindProperty(GameFrameworkText.Format("m_{0}HelperTypeName", m_Name)); + m_CustomHelper = serializedObject.FindProperty(GameFrameworkText.Format("m_Custom{0}Helper", m_Name)); } public void Draw() { string displayName = FieldNameForDisplay(m_Name); - int selectedIndex = EditorGUILayout.Popup(Utility.Text.Format("{0} Helper", displayName), m_HelperTypeNameIndex, m_HelperTypeNames); + int selectedIndex = EditorGUILayout.Popup(GameFrameworkText.Format("{0} Helper", displayName), m_HelperTypeNameIndex, m_HelperTypeNames); if (selectedIndex != m_HelperTypeNameIndex) { m_HelperTypeNameIndex = selectedIndex; @@ -81,7 +81,7 @@ public void Draw() EditorGUILayout.PropertyField(m_CustomHelper); if (m_CustomHelper.objectReferenceValue == null) { - EditorGUILayout.HelpBox(Utility.Text.Format("You must set Custom {0} Helper.", displayName), MessageType.Error); + EditorGUILayout.HelpBox(GameFrameworkText.Format("You must set Custom {0} Helper.", displayName), MessageType.Error); } } } @@ -93,7 +93,7 @@ public void Refresh() CustomOptionName }; - helperTypeNameList.AddRange(Utility.Assembly.GetRuntimeTypeNames(typeof(T))); + helperTypeNameList.AddRange(AssemblyUtility.GetRuntimeTypeNames(typeof(T))); m_HelperTypeNames = helperTypeNameList.ToArray(); m_HelperTypeNameIndex = 0; diff --git a/Editor/Misc/OpenFolder.cs b/Editor/Misc/OpenFolder.cs index 5d95fc4..9405fee 100644 --- a/Editor/Misc/OpenFolder.cs +++ b/Editor/Misc/OpenFolder.cs @@ -98,7 +98,7 @@ public static void OpenFolderConsoleLogPath() /// 要打开的文件夹的路径。 public static void Execute(string folder) { - folder = Utility.Text.Format("\"{0}\"", folder); + folder = GameFrameworkText.Format("\"{0}\"", folder); switch (Application.platform) { case RuntimePlatform.WindowsEditor: @@ -110,7 +110,7 @@ public static void Execute(string folder) break; default: - throw new GameFrameworkException(Utility.Text.Format("Not support open folder on '{0}' platform.", Application.platform)); + throw new GameFrameworkException(GameFrameworkText.Format("Not support open folder on '{0}' platform.", Application.platform)); } } } diff --git a/Editor/Misc/ProjectPathTitlebarModifier.cs b/Editor/Misc/ProjectPathTitlebarModifier.cs new file mode 100644 index 0000000..772a3f9 --- /dev/null +++ b/Editor/Misc/ProjectPathTitlebarModifier.cs @@ -0,0 +1,65 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +namespace GameFrameX.Editor +{ + public class ProjectPathTitlebarModifier + { + private const int Delay = 2000; + + [InitializeOnLoadMethod] + private static void Init() + { + _ = ModifyTitleAsync(); + } + + private static async Task ModifyTitleAsync() + { + await Task.Delay(Delay); + ModifyTitle(); + } + + private static void ModifyTitle() + { + var tEditorApplication = typeof(EditorApplication); + var tApplicationTitleDescriptor = tEditorApplication.Assembly.GetTypes() + .FirstOrDefault(x => x.FullName == "UnityEditor.ApplicationTitleDescriptor"); + if (tApplicationTitleDescriptor == null) + { + // Unity 内部类型不存在时放弃修改, 避免版本升级后初始化报错 + return; + } + + var eiUpdateMainWindowTitle = + tEditorApplication.GetEvent("updateMainWindowTitle", BindingFlags.Static | BindingFlags.NonPublic); + var miUpdateMainWindowTitle = + tEditorApplication.GetMethod("UpdateMainWindowTitle", BindingFlags.Static | BindingFlags.NonPublic); + + var delegateType = typeof(Action<>).MakeGenericType(tApplicationTitleDescriptor); + var methodInfo = ((Action) UpdateWindowTitle).Method; + var del = Delegate.CreateDelegate(delegateType, null, methodInfo); + + eiUpdateMainWindowTitle.GetAddMethod(true).Invoke(null, new object[] {del}); + miUpdateMainWindowTitle.Invoke(null, new object[0]); + eiUpdateMainWindowTitle.GetRemoveMethod(true).Invoke(null, new object[] {del}); + } + + private static void UpdateWindowTitle(object desc) + { + var fieldInfo = typeof(EditorApplication).Assembly.GetTypes() + .FirstOrDefault(x => x.FullName == "UnityEditor.ApplicationTitleDescriptor") + .GetField("title", BindingFlags.Instance | BindingFlags.Public); + if (fieldInfo == null) + { + return; + } + + var str = fieldInfo.GetValue(desc) as string; + fieldInfo.SetValue(desc, $"{str} {Application.dataPath.Replace("/Assets", "")}"); + } + } +} diff --git a/Editor/Misc/ProjectPathTitlebarModifier.cs.meta b/Editor/Misc/ProjectPathTitlebarModifier.cs.meta new file mode 100644 index 0000000..3545e72 --- /dev/null +++ b/Editor/Misc/ProjectPathTitlebarModifier.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d1cf9ee3b4d07e042b4d3860b9dba890 +timeCreated: 1780552441 \ No newline at end of file diff --git a/Editor/Misc/TypeHelper.cs b/Editor/Misc/TypeHelper.cs index d2b06af..f835e50 100644 --- a/Editor/Misc/TypeHelper.cs +++ b/Editor/Misc/TypeHelper.cs @@ -43,9 +43,9 @@ namespace GameFrameX.Editor /// public static class TypeHelper { - private static readonly string[] RuntimeAssemblyNames = Utility.Assembly.GetAssemblies().Where(m => !m.FullName.Contains("Editor")).Select(m => m.FullName).ToArray(); + private static readonly string[] RuntimeAssemblyNames = AssemblyUtility.GetAssemblies().Where(m => !m.FullName.Contains("Editor")).Select(m => m.FullName).ToArray(); - private static readonly string[] RuntimeOrEditorAssemblyNames = Utility.Assembly.GetAssemblies().Select(m => m.FullName).ToArray(); + private static readonly string[] RuntimeOrEditorAssemblyNames = AssemblyUtility.GetAssemblies().Select(m => m.FullName).ToArray(); /// /// 在运行时程序集中获取指定基类的所有子类的名称。 diff --git a/Editor/Utility.meta b/Editor/Utility.meta new file mode 100644 index 0000000..4b79b63 --- /dev/null +++ b/Editor/Utility.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9fdfd339ec8a4d8b99bbb3f617714df5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utility/ShellUtility.cs b/Editor/Utility/ShellUtility.cs new file mode 100644 index 0000000..71553cf --- /dev/null +++ b/Editor/Utility/ShellUtility.cs @@ -0,0 +1,276 @@ +using System.Diagnostics; +using System.Text; +using System.Threading; + +namespace GameFrameX.Editor +{ + public static partial class ShellUtility + { + public delegate void ShellRequestAbortEventHandler(bool kill); + + /// + /// Using this interface the user can monitor what is the output of the command and even abort it. + /// You can use one monitor on multiple commands in a row. + /// + public interface IShellMonitor + { + // NOTE: These methods can be called from a different thread! + void AppendCommand(string command, string args); // Append shell command + arguments. + void AppendOutputLine(string line); // Append line from the output stream. + void AppendErrorLine(string line); // Append line from the error stream. + + bool AbortRequested { get; } // If true, all subsequent commands will abort immediately. + + event ShellRequestAbortEventHandler RequestAbort; // Invoked when user requests abort of the operation. + // Kill will terminate the process immediately. If false, it will ask politely. + } + + public struct ShellArgs + { + public string Command; + public string Args; + public string WorkingDirectory; + public bool WaitForOutput; + + public int + WaitTimeout; // WaitTimeout is in milliseconds. -1 means forever. Only if WaitForOutput is true. + + public IShellMonitor Monitor; + } + + public struct ShellResult + { + public string Command; + public string Args; + + public string Output; + public string Error; + + public bool HasErrors => !string.IsNullOrEmpty(Error); + } + + public const string USER_ABORTED_LOG = "User aborted the operation..."; + + public static ShellResult ExecuteCommand(string command, string args) + { + return ExecuteCommand(command, args, true); + } + + public static ShellResult ExecuteCommand(string command, string args, IShellMonitor monitor) + { + return ExecuteCommand(command, args, true, monitor); + } + + public static ShellResult ExecuteCommand(string command, string args, bool waitForOutput, + IShellMonitor monitor = null) + { + return ExecuteCommand(new ShellArgs() + { + Command = command, + Args = args, + WaitForOutput = waitForOutput, + WaitTimeout = -1, + Monitor = monitor + }); + } + + public static ShellResult ExecuteCommand(string command, string args, int waitTimeout, + IShellMonitor monitor = null) + { + return ExecuteCommand(new ShellArgs() + { + Command = command, + Args = args, + WaitForOutput = true, + WaitTimeout = waitTimeout, + Monitor = monitor + }); + } + + public static ShellResult ExecuteCommand(ShellArgs shellArgs) + { + shellArgs.Command = shellArgs.Command ?? string.Empty; + shellArgs.Args = shellArgs.Args ?? string.Empty; + shellArgs.WorkingDirectory = shellArgs.WorkingDirectory ?? string.Empty; + + var result = new ShellResult(); + + result.Command = shellArgs.Command; + result.Args = shellArgs.Args; + result.Output = string.Empty; + result.Error = string.Empty; + + if (shellArgs.Monitor != null) + { + if (shellArgs.Monitor.AbortRequested) + { + result.Error = USER_ABORTED_LOG; + return result; + } + + shellArgs.Monitor.AppendCommand(shellArgs.Command, shellArgs.Args); + } + + var processStartInfo = new ProcessStartInfo(shellArgs.Command, shellArgs.Args); + processStartInfo.RedirectStandardOutput = true; + processStartInfo.RedirectStandardError = true; + processStartInfo.RedirectStandardInput = true; + processStartInfo.CreateNoWindow = true; + processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; + processStartInfo.UseShellExecute = false; + processStartInfo.WorkingDirectory = shellArgs.WorkingDirectory; + + Process process; + try + { + process = Process.Start(processStartInfo); + // Input is not supported so close it directly. Prevents hangs when CLI prompts the user for something (authentication for example). + process.StandardInput.Close(); + } + catch (System.Exception ex) + { + // Most probably file not found. + result.Error = ex.ToString(); + + if (shellArgs.Monitor != null) + { + shellArgs.Monitor.AppendErrorLine(result.Error); + } + + return result; + } + + // Run and forget... + // TODO: No Process.Dispose() called - leak?! + if (!shellArgs.WaitForOutput) + { + result.Output = string.Empty; + result.Error = string.Empty; + + return result; + } + + // + // Handle aborting. + // + ShellRequestAbortEventHandler abortHandler = null; + if (shellArgs.Monitor != null) + { + abortHandler = (bool kill) => + { + shellArgs.Monitor?.AppendErrorLine(USER_ABORTED_LOG); + + // TODO: Is this thread safe? + if (kill) + { + process.Kill(); + } + else + { + process.CloseMainWindow(); + } + }; + + shellArgs.Monitor.RequestAbort += abortHandler; + } + + // + // Subscribe for standard output. + // + var outputBuilder = new StringBuilder(); + DataReceivedEventHandler outputReadLineHandler = null; + outputReadLineHandler = (sender, args) => + { + // Lock - check the Builder usage at the end. + lock (outputBuilder) + { + if (args.Data != null) + { + outputBuilder.AppendLine(args.Data); + if (shellArgs.Monitor != null) + { + shellArgs.Monitor.AppendOutputLine(args.Data); + } + } + } + }; + process.OutputDataReceived += outputReadLineHandler; + process.BeginOutputReadLine(); + + // + // Subscribe for error output. + // + var errorBuilder = new StringBuilder(); + DataReceivedEventHandler errorReadLineHandler = null; + errorReadLineHandler = (sender, args) => + { + // Lock - check the Builder usage at the end. + lock (errorBuilder) + { + if (args.Data != null) + { + errorBuilder.AppendLine(args.Data); + if (shellArgs.Monitor != null) + { + shellArgs.Monitor.AppendErrorLine(args.Data); + } + } + } + }; + process.ErrorDataReceived += errorReadLineHandler; + process.BeginErrorReadLine(); + + if (shellArgs.WaitTimeout < 0) + { + process.WaitForExit(); + } + else + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + while (!process.HasExited && stopwatch.ElapsedMilliseconds < shellArgs.WaitTimeout) + { + Thread.Sleep(20); + } + + stopwatch.Stop(); + + // If process is still running, the timeout kicked in. + if (!process.HasExited) + { + result.Error += $"Command [{shellArgs.Command} {shellArgs.Args}] timed out."; + } + } + + process.OutputDataReceived -= outputReadLineHandler; + lock (outputBuilder) + { + // When the main thread gets here, the process will not be running (unless it timed out), + // but the OutputDataReceived thread might still be appending the final strings. Lock it! + result.Output = outputBuilder.ToString(); + } + + process.ErrorDataReceived -= errorReadLineHandler; + lock (errorBuilder) + { + // Same as above. Concat if error was present. + result.Error += errorBuilder.ToString(); + } + + if (shellArgs.Monitor != null) + { + shellArgs.Monitor.RequestAbort -= abortHandler; + } + + // Dispose() (invoking Close()) will wait for the process to finish. + // If process is stuck, this will hang Unity on recompile / exit. + // Not calling Dispose() in that regard will leak some resources / processes, but that shouldn't be the normal case anyway. + if (process.HasExited) + { + process.Dispose(); + } + + return result; + } + } +} \ No newline at end of file diff --git a/Editor/Utility/ShellUtility.cs.meta b/Editor/Utility/ShellUtility.cs.meta new file mode 100644 index 0000000..24d6f2e --- /dev/null +++ b/Editor/Utility/ShellUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9cd4f0f10eb741438e18fe77dbf5e7a8 +timeCreated: 1786546563 \ No newline at end of file diff --git a/Runtime/Base/BaseComponent.cs b/Runtime/Base/BaseComponent.cs index 7d2eb89..f254d9e 100644 --- a/Runtime/Base/BaseComponent.cs +++ b/Runtime/Base/BaseComponent.cs @@ -1,388 +1,388 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using UnityEngine; - -namespace GameFrameX.Runtime -{ - /// - /// 基础组件。 - /// - /// - /// Base component that provides core game framework functionality including frame rate control, - /// game speed management, background running settings, and helper initializations. - /// - [DisallowMultipleComponent] - [AddComponentMenu("GameFrameX/Base")] - [UnityEngine.Scripting.Preserve] - [GameFrameXAutoComponent(-10000)] - [DefaultExecutionOrder(-500)] - public sealed class BaseComponent : GameFrameworkComponent - { - private const int DefaultDpi = 96; // default windows dpi - - private float m_GameSpeedBeforePause = 1f; - - // [SerializeField] private bool m_EditorResourceMode = true; - - [SerializeField] private string m_TextHelperTypeName = "GameFrameX.Runtime.DefaultTextHelper"; - - [SerializeField] private string m_VersionHelperTypeName = "GameFrameX.Runtime.DefaultVersionHelper"; - - [SerializeField] private string m_LogHelperTypeName = "GameFrameX.Runtime.DefaultLogHelper"; - - [SerializeField] private string m_CompressionHelperTypeName = "GameFrameX.Runtime.DefaultCompressionHelper"; - - [SerializeField] private string m_JsonHelperTypeName = "GameFrameX.Runtime.LitJsonHelper"; - - [SerializeField] private int m_FrameRate = 30; - - [SerializeField] private float m_GameSpeed = 1f; - - [SerializeField] private bool m_RunInBackground = true; - - [SerializeField] private bool m_NeverSleep = true; - - /// - /// 获取或设置游戏帧率。 / Gets or sets the game frame rate. - /// - [UnityEngine.Scripting.Preserve] - public int FrameRate - { - get { return m_FrameRate; } - set { Application.targetFrameRate = m_FrameRate = value; } - } - - /// - /// 获取或设置游戏速度。 / Gets or sets the game speed. - /// - [UnityEngine.Scripting.Preserve] - public float GameSpeed - { - get { return m_GameSpeed; } - set { Time.timeScale = m_GameSpeed = value >= 0f ? value : 0f; } - } - - /// - /// 获取游戏是否暂停。 / Gets whether the game is paused. - /// - [UnityEngine.Scripting.Preserve] - public bool IsGamePaused - { - get { return m_GameSpeed <= 0f; } - } - - /// - /// 获取是否正常游戏速度。 / Gets whether the game is running at normal speed. - /// - [UnityEngine.Scripting.Preserve] - public bool IsNormalGameSpeed - { - get { return m_GameSpeed == 1f; } - } - - /// - /// 获取或设置是否允许后台运行。 / Gets or sets whether the game can run in background. - /// - [UnityEngine.Scripting.Preserve] - public bool RunInBackground - { - get { return m_RunInBackground; } - set { Application.runInBackground = m_RunInBackground = value; } - } - - /// - /// 获取或设置是否禁止休眠。 / Gets or sets whether sleep is disabled. - /// - [UnityEngine.Scripting.Preserve] - public bool NeverSleep - { - get { return m_NeverSleep; } - set - { - m_NeverSleep = value; - Screen.sleepTimeout = value ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; - } - } - - /// - /// 游戏框架组件初始化。 / Initializes the game framework component. - /// - protected override void Awake() - { - IsAutoRegister = false; - base.Awake(); - - DontDestroyOnLoad(gameObject); - InitTextHelper(); - InitVersionHelper(); - InitLogHelper(); - // Log.Info("Game Framework Version: {0}", GameFramework.Version.GameFrameworkVersion); - Log.Info("Game Version: {0}, Unity Version: {1}", GameVersion.AppVersion, Application.unityVersion); -#if UNITY_5_3_OR_NEWER || UNITY_5_3 - InitCompressionHelper(); - InitJsonHelper(); - - Utility.Converter.ScreenDpi = Screen.dpi; - if (Utility.Converter.ScreenDpi <= 0) - { - Utility.Converter.ScreenDpi = DefaultDpi; - } - - // m_EditorResourceMode &= Application.isEditor; - // if (m_EditorResourceMode) - // { - // Log.Info( - // "During this run, Game Framework will use editor resource files, which you should validate first."); - // } - - Application.targetFrameRate = m_FrameRate; - Time.timeScale = m_GameSpeed; - Application.runInBackground = m_RunInBackground; - Screen.sleepTimeout = m_NeverSleep ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; -#else - Log.Error("Game Framework only applies with Unity 5.3 and above, but current Unity version is {0}.", Application.unityVersion); - GameEntry.Shutdown(ShutdownType.Quit); -#endif -#if UNITY_5_6_OR_NEWER - Application.lowMemory += OnLowMemory; -#endif - } - - private void Start() - { - } - - private void Update() - { - GameFrameworkEntry.Update(Time.deltaTime, Time.unscaledDeltaTime); - } - - private void OnApplicationQuit() - { -#if UNITY_5_6_OR_NEWER - Application.lowMemory -= OnLowMemory; -#endif - StopAllCoroutines(); - } - - private void OnDestroy() - { - GameFrameworkEntry.Shutdown(); - } - - /// - /// 暂停游戏。 / Pauses the game. - /// - [UnityEngine.Scripting.Preserve] - public void PauseGame() - { - if (IsGamePaused) - { - return; - } - - m_GameSpeedBeforePause = GameSpeed; - GameSpeed = 0f; - } - - /// - /// 恢复游戏。 / Resumes the game. - /// - [UnityEngine.Scripting.Preserve] - public void ResumeGame() - { - if (!IsGamePaused) - { - return; - } - - GameSpeed = m_GameSpeedBeforePause; - } - - /// - /// 重置为正常游戏速度。 / Resets to normal game speed. - /// - [UnityEngine.Scripting.Preserve] - public void ResetNormalGameSpeed() - { - if (IsNormalGameSpeed) - { - return; - } - - GameSpeed = 1f; - } - - internal void Shutdown() - { - Destroy(gameObject); - } - - private void InitTextHelper() - { - if (string.IsNullOrEmpty(m_TextHelperTypeName)) - { - return; - } - - Type textHelperType = Utility.Assembly.GetType(m_TextHelperTypeName); - if (textHelperType == null) - { - Log.Error("Can not find text helper type '{0}'.", m_TextHelperTypeName); - return; - } - - Utility.Text.ITextHelper textHelper = (Utility.Text.ITextHelper)Activator.CreateInstance(textHelperType); - if (textHelper == null) - { - Log.Error("Can not create text helper instance '{0}'.", m_TextHelperTypeName); - return; - } - - Utility.Text.SetTextHelper(textHelper); - } - - private void InitVersionHelper() - { - if (string.IsNullOrEmpty(m_VersionHelperTypeName)) - { - return; - } - - var versionHelperType = Utility.Assembly.GetType(m_VersionHelperTypeName); - if (versionHelperType == null) - { - throw new GameFrameworkException(Utility.Text.Format("Can not find version helper type '{0}'.", - m_VersionHelperTypeName)); - } - - var versionHelper = (GameVersion.IVersionHelper)Activator.CreateInstance(versionHelperType); - if (versionHelper == null) - { - throw new GameFrameworkException(Utility.Text.Format("Can not create version helper instance '{0}'.", - m_VersionHelperTypeName)); - } - - GameVersion.SetVersionHelper(versionHelper); - } - - private void InitLogHelper() - { - if (string.IsNullOrEmpty(m_LogHelperTypeName)) - { - return; - } - - var logHelperType = Utility.Assembly.GetType(m_LogHelperTypeName); - if (logHelperType == null) - { - throw new GameFrameworkException(Utility.Text.Format("Can not find log helper type '{0}'.", m_LogHelperTypeName)); - } - - var logHelper = (GameFrameworkLog.ILogHelper)Activator.CreateInstance(logHelperType); - if (logHelper == null) - { - throw new GameFrameworkException(Utility.Text.Format("Can not create log helper instance '{0}'.", m_LogHelperTypeName)); - } - - GameFrameworkLog.SetLogHelper(logHelper); - } - - private void InitCompressionHelper() - { - if (string.IsNullOrEmpty(m_CompressionHelperTypeName)) - { - return; - } - - var compressionHelperType = Utility.Assembly.GetType(m_CompressionHelperTypeName); - if (compressionHelperType == null) - { - Log.Error("Can not find compression helper type '{0}'.", m_CompressionHelperTypeName); - return; - } - - var compressionHelper = (Utility.Compression.ICompressionHelper)Activator.CreateInstance(compressionHelperType); - if (compressionHelper == null) - { - Log.Error("Can not create compression helper instance '{0}'.", m_CompressionHelperTypeName); - return; - } - - Utility.Compression.SetCompressionHelper(compressionHelper); - } - - private void InitJsonHelper() - { - if (string.IsNullOrEmpty(m_JsonHelperTypeName)) - { - return; - } - - var jsonHelperType = Utility.Assembly.GetType(m_JsonHelperTypeName); - if (jsonHelperType == null) - { - Log.Error("Can not find JSON helper type '{0}'.", m_JsonHelperTypeName); - return; - } - - var jsonHelper = (Utility.Json.IJsonHelper)Activator.CreateInstance(jsonHelperType); - if (jsonHelper == null) - { - Log.Error("Can not create JSON helper instance '{0}'.", m_JsonHelperTypeName); - return; - } - - Utility.Json.SetJsonHelper(jsonHelper); - } - - private void OnLowMemory() - { - Log.Info("Low memory reported..."); - - var objectPoolComponent = GameEntry.GetComponent(); - if (objectPoolComponent != null) - { - objectPoolComponent.ReleaseAllUnused(); - } - - /*AssetComponent resourceComponent = GameEntry.GetComponent(); - if (resourceComponent != null) - { - // resourceComponent.ForceUnloadUnusedAssets(true); - }*/ - } - } -} +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using UnityEngine; + +namespace GameFrameX.Runtime +{ + /// + /// 基础组件。 + /// + /// + /// Base component that provides core game framework functionality including frame rate control, + /// game speed management, background running settings, and helper initializations. + /// + [DisallowMultipleComponent] + [AddComponentMenu("GameFrameX/Base")] + [UnityEngine.Scripting.Preserve] + [GameFrameXAutoComponent(-10000)] + [DefaultExecutionOrder(-500)] + public sealed class BaseComponent : GameFrameworkComponent + { + private const int DefaultDpi = 96; // default windows dpi + + private float m_GameSpeedBeforePause = 1f; + + // [SerializeField] private bool m_EditorResourceMode = true; + + [SerializeField] private string m_TextHelperTypeName = "GameFrameX.Runtime.DefaultTextHelper"; + + [SerializeField] private string m_VersionHelperTypeName = "GameFrameX.Runtime.DefaultVersionHelper"; + + [SerializeField] private string m_LogHelperTypeName = "GameFrameX.Runtime.DefaultLogHelper"; + + [SerializeField] private string m_CompressionHelperTypeName = "GameFrameX.Runtime.DefaultCompressionHelper"; + + [SerializeField] private string m_JsonHelperTypeName = "GameFrameX.Runtime.LitJsonHelper"; + + [SerializeField] private int m_FrameRate = 30; + + [SerializeField] private float m_GameSpeed = 1f; + + [SerializeField] private bool m_RunInBackground = true; + + [SerializeField] private bool m_NeverSleep = true; + + /// + /// 获取或设置游戏帧率。 / Gets or sets the game frame rate. + /// + [UnityEngine.Scripting.Preserve] + public int FrameRate + { + get { return m_FrameRate; } + set { Application.targetFrameRate = m_FrameRate = value; } + } + + /// + /// 获取或设置游戏速度。 / Gets or sets the game speed. + /// + [UnityEngine.Scripting.Preserve] + public float GameSpeed + { + get { return m_GameSpeed; } + set { Time.timeScale = m_GameSpeed = value >= 0f ? value : 0f; } + } + + /// + /// 获取游戏是否暂停。 / Gets whether the game is paused. + /// + [UnityEngine.Scripting.Preserve] + public bool IsGamePaused + { + get { return m_GameSpeed <= 0f; } + } + + /// + /// 获取是否正常游戏速度。 / Gets whether the game is running at normal speed. + /// + [UnityEngine.Scripting.Preserve] + public bool IsNormalGameSpeed + { + get { return m_GameSpeed == 1f; } + } + + /// + /// 获取或设置是否允许后台运行。 / Gets or sets whether the game can run in background. + /// + [UnityEngine.Scripting.Preserve] + public bool RunInBackground + { + get { return m_RunInBackground; } + set { Application.runInBackground = m_RunInBackground = value; } + } + + /// + /// 获取或设置是否禁止休眠。 / Gets or sets whether sleep is disabled. + /// + [UnityEngine.Scripting.Preserve] + public bool NeverSleep + { + get { return m_NeverSleep; } + set + { + m_NeverSleep = value; + Screen.sleepTimeout = value ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; + } + } + + /// + /// 游戏框架组件初始化。 / Initializes the game framework component. + /// + protected override void Awake() + { + IsAutoRegister = false; + base.Awake(); + + DontDestroyOnLoad(gameObject); + InitTextHelper(); + InitVersionHelper(); + InitLogHelper(); + // Log.Info("Game Framework Version: {0}", GameFramework.Version.GameFrameworkVersion); + Log.Info("Game Version: {0}, Unity Version: {1}", GameVersion.AppVersion, Application.unityVersion); +#if UNITY_5_3_OR_NEWER || UNITY_5_3 + InitCompressionHelper(); + InitJsonHelper(); + + ConverterUtility.ScreenDpi = Screen.dpi; + if (ConverterUtility.ScreenDpi <= 0) + { + ConverterUtility.ScreenDpi = DefaultDpi; + } + + // m_EditorResourceMode &= Application.isEditor; + // if (m_EditorResourceMode) + // { + // Log.Info( + // "During this run, Game Framework will use editor resource files, which you should validate first."); + // } + + Application.targetFrameRate = m_FrameRate; + Time.timeScale = m_GameSpeed; + Application.runInBackground = m_RunInBackground; + Screen.sleepTimeout = m_NeverSleep ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; +#else + Log.Error("Game Framework only applies with Unity 5.3 and above, but current Unity version is {0}.", Application.unityVersion); + GameEntry.Shutdown(ShutdownType.Quit); +#endif +#if UNITY_5_6_OR_NEWER + Application.lowMemory += OnLowMemory; +#endif + } + + private void Start() + { + } + + private void Update() + { + GameFrameworkEntry.Update(Time.deltaTime, Time.unscaledDeltaTime); + } + + private void OnApplicationQuit() + { +#if UNITY_5_6_OR_NEWER + Application.lowMemory -= OnLowMemory; +#endif + StopAllCoroutines(); + } + + private void OnDestroy() + { + GameFrameworkEntry.Shutdown(); + } + + /// + /// 暂停游戏。 / Pauses the game. + /// + [UnityEngine.Scripting.Preserve] + public void PauseGame() + { + if (IsGamePaused) + { + return; + } + + m_GameSpeedBeforePause = GameSpeed; + GameSpeed = 0f; + } + + /// + /// 恢复游戏。 / Resumes the game. + /// + [UnityEngine.Scripting.Preserve] + public void ResumeGame() + { + if (!IsGamePaused) + { + return; + } + + GameSpeed = m_GameSpeedBeforePause; + } + + /// + /// 重置为正常游戏速度。 / Resets to normal game speed. + /// + [UnityEngine.Scripting.Preserve] + public void ResetNormalGameSpeed() + { + if (IsNormalGameSpeed) + { + return; + } + + GameSpeed = 1f; + } + + internal void Shutdown() + { + Destroy(gameObject); + } + + private void InitTextHelper() + { + if (string.IsNullOrEmpty(m_TextHelperTypeName)) + { + return; + } + + Type textHelperType = AssemblyUtility.GetType(m_TextHelperTypeName); + if (textHelperType == null) + { + Log.Error("Can not find text helper type '{0}'.", m_TextHelperTypeName); + return; + } + + GameFrameworkText.ITextHelper textHelper = (GameFrameworkText.ITextHelper)Activator.CreateInstance(textHelperType); + if (textHelper == null) + { + Log.Error("Can not create text helper instance '{0}'.", m_TextHelperTypeName); + return; + } + + GameFrameworkText.SetTextHelper(textHelper); + } + + private void InitVersionHelper() + { + if (string.IsNullOrEmpty(m_VersionHelperTypeName)) + { + return; + } + + var versionHelperType = AssemblyUtility.GetType(m_VersionHelperTypeName); + if (versionHelperType == null) + { + throw new GameFrameworkException(GameFrameworkText.Format("Can not find version helper type '{0}'.", + m_VersionHelperTypeName)); + } + + var versionHelper = (GameVersion.IVersionHelper)Activator.CreateInstance(versionHelperType); + if (versionHelper == null) + { + throw new GameFrameworkException(GameFrameworkText.Format("Can not create version helper instance '{0}'.", + m_VersionHelperTypeName)); + } + + GameVersion.SetVersionHelper(versionHelper); + } + + private void InitLogHelper() + { + if (string.IsNullOrEmpty(m_LogHelperTypeName)) + { + return; + } + + var logHelperType = AssemblyUtility.GetType(m_LogHelperTypeName); + if (logHelperType == null) + { + throw new GameFrameworkException(GameFrameworkText.Format("Can not find log helper type '{0}'.", m_LogHelperTypeName)); + } + + var logHelper = (GameFrameworkLog.ILogHelper)Activator.CreateInstance(logHelperType); + if (logHelper == null) + { + throw new GameFrameworkException(GameFrameworkText.Format("Can not create log helper instance '{0}'.", m_LogHelperTypeName)); + } + + GameFrameworkLog.SetLogHelper(logHelper); + } + + private void InitCompressionHelper() + { + if (string.IsNullOrEmpty(m_CompressionHelperTypeName)) + { + return; + } + + var compressionHelperType = AssemblyUtility.GetType(m_CompressionHelperTypeName); + if (compressionHelperType == null) + { + Log.Error("Can not find compression helper type '{0}'.", m_CompressionHelperTypeName); + return; + } + + var compressionHelper = (GameFrameworkCompression.ICompressionHelper)Activator.CreateInstance(compressionHelperType); + if (compressionHelper == null) + { + Log.Error("Can not create compression helper instance '{0}'.", m_CompressionHelperTypeName); + return; + } + + GameFrameworkCompression.SetCompressionHelper(compressionHelper); + } + + private void InitJsonHelper() + { + if (string.IsNullOrEmpty(m_JsonHelperTypeName)) + { + return; + } + + var jsonHelperType = AssemblyUtility.GetType(m_JsonHelperTypeName); + if (jsonHelperType == null) + { + Log.Error("Can not find JSON helper type '{0}'.", m_JsonHelperTypeName); + return; + } + + var jsonHelper = (GameFrameworkJson.IJsonHelper)Activator.CreateInstance(jsonHelperType); + if (jsonHelper == null) + { + Log.Error("Can not create JSON helper instance '{0}'.", m_JsonHelperTypeName); + return; + } + + GameFrameworkJson.SetJsonHelper(jsonHelper); + } + + private void OnLowMemory() + { + Log.Info("Low memory reported..."); + + var objectPoolComponent = GameEntry.GetComponent(); + if (objectPoolComponent != null) + { + objectPoolComponent.ReleaseAllUnused(); + } + + /*AssetComponent resourceComponent = GameEntry.GetComponent(); + if (resourceComponent != null) + { + // resourceComponent.ForceUnloadUnusedAssets(true); + }*/ + } + } +} \ No newline at end of file diff --git a/Runtime/Base/DataStruct/TypeNamePair.cs b/Runtime/Base/DataStruct/TypeNamePair.cs index 8713587..8931107 100644 --- a/Runtime/Base/DataStruct/TypeNamePair.cs +++ b/Runtime/Base/DataStruct/TypeNamePair.cs @@ -106,7 +106,7 @@ public override string ToString() } string typeName = m_Type.FullName; - return (string.IsNullOrEmpty(m_Name) ? typeName : Utility.Text.Format("{0}.{1}", typeName, m_Name)) ?? string.Empty; + return (string.IsNullOrEmpty(m_Name) ? typeName : GameFrameworkText.Format("{0}.{1}", typeName, m_Name)) ?? string.Empty; } /// diff --git a/Runtime/Base/EventPool/EventPool.cs b/Runtime/Base/EventPool/EventPool.cs index 429eedd..b80d8b1 100644 --- a/Runtime/Base/EventPool/EventPool.cs +++ b/Runtime/Base/EventPool/EventPool.cs @@ -222,11 +222,11 @@ public void Subscribe(string id, EventHandler handler) } else if ((_eventPoolMode & EventPoolMode.AllowMultiHandler) != EventPoolMode.AllowMultiHandler) { - throw new GameFrameworkException(Utility.Text.Format("Event '{0}' not allow multi handler.", id)); + throw new GameFrameworkException(GameFrameworkText.Format("Event '{0}' not allow multi handler.", id)); } else if ((_eventPoolMode & EventPoolMode.AllowDuplicateHandler) != EventPoolMode.AllowDuplicateHandler && Check(id, handler)) { - throw new GameFrameworkException(Utility.Text.Format("Event '{0}' not allow duplicate handler.", id)); + throw new GameFrameworkException(GameFrameworkText.Format("Event '{0}' not allow duplicate handler.", id)); } else { @@ -390,7 +390,7 @@ private void HandleEvent(object sender, T e) if (noHandlerException) { ReferencePool.Release(e); - throw new GameFrameworkException(Utility.Text.Format("Event '{0}' not allow no handler.", e.Id)); + throw new GameFrameworkException(GameFrameworkText.Format("Event '{0}' not allow no handler.", e.Id)); } ReferencePool.Release(e); diff --git a/Runtime/Base/GameFrameworkEntry.cs b/Runtime/Base/GameFrameworkEntry.cs index 6928b8b..6ac3e6c 100644 --- a/Runtime/Base/GameFrameworkEntry.cs +++ b/Runtime/Base/GameFrameworkEntry.cs @@ -81,7 +81,7 @@ public static void Shutdown() s_GameFrameworkModules.Clear(); ReferencePool.ClearAll(); - Utility.Marshal.FreeCachedHGlobal(); + MarshalUtility.FreeCachedHGlobal(); GameFrameworkLog.SetLogHelper(null); } @@ -100,21 +100,21 @@ public static T GetModule() where T : class if (!interfaceType.IsInterface) { - throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName)); } if (!interfaceType.FullName.StartsWith("GameFrameX.", StringComparison.Ordinal)) { - throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName)); } if (!s_ModuleTypeMap.TryGetValue(interfaceType, out Type moduleType)) { - string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); + string moduleName = GameFrameworkText.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); moduleType = Type.GetType(moduleName); if (moduleType == null) { - throw new GameFrameworkException(Utility.Text.Format("Can not find Game Framework module type '{0}'.", moduleName)); + throw new GameFrameworkException(GameFrameworkText.Format("Can not find Game Framework module type '{0}'.", moduleName)); } } @@ -156,12 +156,12 @@ public static void RegisterModule(Type interfaceType, Type implType) { if (!interfaceType.IsInterface) { - throw new GameFrameworkException(Utility.Text.Format("You must register module by interface, but '{0}' is not.", interfaceType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("You must register module by interface, but '{0}' is not.", interfaceType.FullName)); } if (!implType.IsClass || implType.IsInterface || implType.IsAbstract) { - throw new GameFrameworkException(Utility.Text.Format("You must register module by Class and not Interface and Abstract, but '{0}' is not.", implType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("You must register module by Class and not Interface and Abstract, but '{0}' is not.", implType.FullName)); } if (!s_ModuleTypeMap.TryGetValue(interfaceType, out _)) @@ -183,7 +183,7 @@ private static GameFrameworkModule CreateModule(Type moduleType) var module = (GameFrameworkModule)Activator.CreateInstance(moduleType); if (module == null) { - throw new GameFrameworkException(Utility.Text.Format("Can not create module '{0}'.", moduleType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Can not create module '{0}'.", moduleType.FullName)); } var current = s_GameFrameworkModules.First; diff --git a/Runtime/Base/GameFrameworkSerializer.cs b/Runtime/Base/GameFrameworkSerializer.cs index fcf8892..b4e6885 100644 --- a/Runtime/Base/GameFrameworkSerializer.cs +++ b/Runtime/Base/GameFrameworkSerializer.cs @@ -203,7 +203,7 @@ public bool Serialize(Stream stream, T data, byte version) stream.WriteByte(version); if (!_serializeCallbacks.TryGetValue(version, out var callback)) { - throw new GameFrameworkException(Utility.Text.Format("Serialize callback '{0}' is not exist.", version)); + throw new GameFrameworkException(GameFrameworkText.Format("Serialize callback '{0}' is not exist.", version)); } return callback(stream, data); @@ -226,13 +226,13 @@ public T Deserialize(Stream stream) byte header2 = (byte)stream.ReadByte(); if (header0 != header[0] || header1 != header[1] || header2 != header[2]) { - throw new GameFrameworkException(Utility.Text.Format("Header is invalid, need '{0}{1}{2}', current '{3}{4}{5}'.", (char)header[0], (char)header[1], (char)header[2], (char)header0, (char)header1, (char)header2)); + throw new GameFrameworkException(GameFrameworkText.Format("Header is invalid, need '{0}{1}{2}', current '{3}{4}{5}'.", (char)header[0], (char)header[1], (char)header[2], (char)header0, (char)header1, (char)header2)); } byte version = (byte)stream.ReadByte(); if (!_deserializeCallbacks.TryGetValue(version, out var callback)) { - throw new GameFrameworkException(Utility.Text.Format("Deserialize callback '{0}' is not exist.", version)); + throw new GameFrameworkException(GameFrameworkText.Format("Deserialize callback '{0}' is not exist.", version)); } return callback(stream); diff --git a/Runtime/Base/ReferencePool/ReferencePool.cs b/Runtime/Base/ReferencePool/ReferencePool.cs index cdc1670..e4fb120 100644 --- a/Runtime/Base/ReferencePool/ReferencePool.cs +++ b/Runtime/Base/ReferencePool/ReferencePool.cs @@ -272,7 +272,7 @@ private static void InternalCheckReferenceType(Type referenceType) if (!typeof(IReference).IsAssignableFrom(referenceType)) { - throw new GameFrameworkException(Utility.Text.Format("Reference type '{0}' is invalid.", referenceType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Reference type '{0}' is invalid.", referenceType.FullName)); } } diff --git a/Runtime/Base/Variable/GenericVariable.cs b/Runtime/Base/Variable/GenericVariable.cs index e00af40..23f3ded 100644 --- a/Runtime/Base/Variable/GenericVariable.cs +++ b/Runtime/Base/Variable/GenericVariable.cs @@ -104,7 +104,7 @@ public override void SetValue(object value) { if (value != null && !(value is T)) { - throw new GameFrameworkException(Utility.Text.Format("Cannot set value of type '{0}' to variable of type '{1}'.", value.GetType().FullName, typeof(T).FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Cannot set value of type '{0}' to variable of type '{1}'.", value.GetType().FullName, typeof(T).FullName)); } _value = (value == null) ? default(T) : (T)value; diff --git a/Runtime/Constant.meta b/Runtime/Constant.meta new file mode 100644 index 0000000..b177ef1 --- /dev/null +++ b/Runtime/Constant.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 79a97e0b27284e00912037b4f180a380 +timeCreated: 1787481219 \ No newline at end of file diff --git a/Runtime/Constant/FileNameSuffix.cs b/Runtime/Constant/FileNameSuffix.cs new file mode 100644 index 0000000..275c05f --- /dev/null +++ b/Runtime/Constant/FileNameSuffix.cs @@ -0,0 +1,119 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +namespace GameFrameX.Runtime +{ + /// + /// 文件名后缀常量。 + /// + /// + /// File name suffix constants. + /// + public static partial class FileNameSuffix + { + /// + /// Json 文件 + /// + public const string Json = ".json"; + + /// + /// Wav 文件 + /// + public const string Wav = ".wav"; + + /// + /// Mp3 文件 + /// + public const string Mp3 = ".mp3"; + + /// + /// Xml 文件 + /// + public const string Xml = ".xml"; + + /// + /// 文本文件 + /// + public const string Txt = ".txt"; + + /// + /// 日志文件 + /// + public const string Log = ".log"; + + /// + /// CSharp 文件 + /// + public const string CSharp = ".cs"; + + /// + /// Zip 压缩文件 + /// + public const string Zip = ".zip"; + + /// + /// 图片PNG + /// + public const string PNG = ".png"; + + /// + /// 图片JPG + /// + public const string JPG = ".jpg"; + + /// + /// 二进制文件 + /// + public const string Binary = ".bytes"; + + /// + /// 配置文件 + /// + public const string Config = ".config"; + + /// + /// DLL 文件 + /// + public const string DLL = ".dll"; + + /// + /// PDB 调试文件 + /// + public const string PDB = ".pdb"; + + /// + /// Asset 文件 + /// + public const string Asset = ".asset"; + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Const.FileNameSuffix.cs.meta b/Runtime/Constant/FileNameSuffix.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Const.FileNameSuffix.cs.meta rename to Runtime/Constant/FileNameSuffix.cs.meta diff --git a/Runtime/Extension/Extension/BinaryExtension.cs b/Runtime/Extension/Extension/BinaryExtension.cs index 09c2629..c3ad89c 100644 --- a/Runtime/Extension/Extension/BinaryExtension.cs +++ b/Runtime/Extension/Extension/BinaryExtension.cs @@ -236,8 +236,8 @@ public static string ReadEncryptedString(this BinaryReader binaryReader, byte[] cachedBytes[i] = binaryReader.ReadByte(); } - Utility.Encryption.GetSelfXorBytes(cachedBytes, 0, length, encryptBytes); - string value = Utility.Converter.GetString(cachedBytes, 0, length); + EncryptionUtility.GetSelfXorBytes(cachedBytes, 0, length, encryptBytes); + string value = ConverterUtility.GetString(cachedBytes, 0, length); Array.Clear(cachedBytes, 0, length); return value; } @@ -261,13 +261,13 @@ public static void WriteEncryptedString(this BinaryWriter binaryWriter, string v } var cachedBytes = s_CachedBytes ?? (s_CachedBytes = new byte[byte.MaxValue + 1]); - int length = Utility.Converter.GetBytes(value, cachedBytes); + int length = ConverterUtility.GetBytes(value, cachedBytes); if (length > byte.MaxValue) { - throw new GameFrameworkException(Utility.Text.Format("String '{0}' is too long.", value)); + throw new GameFrameworkException(GameFrameworkText.Format("String '{0}' is too long.", value)); } - Utility.Encryption.GetSelfXorBytes(cachedBytes, encryptBytes); + EncryptionUtility.GetSelfXorBytes(cachedBytes, encryptBytes); binaryWriter.Write((byte)length); binaryWriter.Write(cachedBytes, 0, length); } diff --git a/Runtime/Extension/Extension/CollectionExtensions.cs b/Runtime/Extension/Extension/CollectionExtensions.cs index 592a328..4c97d9b 100644 --- a/Runtime/Extension/Extension/CollectionExtensions.cs +++ b/Runtime/Extension/Extension/CollectionExtensions.cs @@ -111,7 +111,6 @@ public static int RemoveIf(this Dictionary self, Fun #endregion - #region ICollectionExtensions /// @@ -229,5 +228,30 @@ public static void AddRange(this HashSet c, IEnumerable e) c.Add(item); } } + + /// + /// 根据指定键选择器对集合进行去重。 + /// + /// + /// Returns distinct elements from a collection based on a key selector. + /// + /// 源集合元素类型 / Source collection element type + /// 键选择器返回的键类型 / Key type returned by the key selector + /// 要去重的源集合 / Source collection to deduplicate + /// 用于选择比较键的函数 / Function to select the comparison key + /// 去重后的集合 / Deduplicated collection + [UnityEngine.Scripting.Preserve] + public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) + { + var identifiedKeys = new HashSet(); + + foreach (var item in source) + { + if (identifiedKeys.Add(keySelector(item))) + { + yield return item; + } + } + } } } \ No newline at end of file diff --git a/Runtime/Extension/Extension/StringExtensions.cs b/Runtime/Extension/Extension/StringExtensions.cs index 3d48d31..ad4bd4b 100644 --- a/Runtime/Extension/Extension/StringExtensions.cs +++ b/Runtime/Extension/Extension/StringExtensions.cs @@ -120,6 +120,31 @@ public static bool StartsWithFast(this string self, string target) return (bp == bLen); } + public static int ToInt(this string str, int def = 0) + { + return !int.TryParse(str, out var ret) ? def : ret; + } + + public static long ToLong(this string str, long def = 0) + { + return !long.TryParse(str, out var ret) ? def : ret; + } + + public static float ToFloat(this string str, float def = 0f) + { + return !float.TryParse(str, out var ret) ? def : ret; + } + + public static double ToDouble(this string str, double def = 0) + { + return !double.TryParse(str, out var ret) ? def : ret; + } + + public static T ToEnum(this string str, bool ignoreCase = false, T def = default) where T : struct + { + return !Enum.TryParse(str, ignoreCase, out var ret) ? def : ret; + } + /// /// 字符串转字符数组 /// @@ -479,5 +504,6 @@ public static string ReadLine(this string rawString, ref int position) return null; } + } } \ No newline at end of file diff --git a/Runtime/Extension/UnityEngine.Camera.meta b/Runtime/Extension/UnityEngine.Camera.meta new file mode 100644 index 0000000..82fc8f0 --- /dev/null +++ b/Runtime/Extension/UnityEngine.Camera.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5e93c52f4c934565a18c97388575467b +timeCreated: 1787492835 \ No newline at end of file diff --git a/Runtime/Helper/CameraHelper.cs b/Runtime/Extension/UnityEngine.Camera/UnityEngine.CameraExtension.cs similarity index 86% rename from Runtime/Helper/CameraHelper.cs rename to Runtime/Extension/UnityEngine.Camera/UnityEngine.CameraExtension.cs index 48300f2..8071f77 100644 --- a/Runtime/Helper/CameraHelper.cs +++ b/Runtime/Extension/UnityEngine.Camera/UnityEngine.CameraExtension.cs @@ -4,14 +4,8 @@ namespace GameFrameX.Runtime { - /// - /// 相机帮助类。 - /// - /// - /// Camera helper class. - /// [UnityEngine.Scripting.Preserve] - public static class CameraHelper + public static class UnityEngineCameraExtension { /// /// 获取相机快照。 @@ -23,7 +17,7 @@ public static class CameraHelper /// 缩放比例,默认为0.5 / Scale factor, default is 0.5 /// 捕获的纹理 / Captured texture [UnityEngine.Scripting.Preserve] - public static Texture2D GetCaptureScreenshot(Camera main, float scale = 0.5f) + public static Texture2D GetCaptureScreenshot(this Camera main, float scale = 0.5f) { Rect rect = new Rect(0, 0, Screen.width * scale, Screen.height * scale); string name = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); diff --git a/Runtime/Helper/CameraHelper.cs.meta b/Runtime/Extension/UnityEngine.Camera/UnityEngine.CameraExtension.cs.meta similarity index 100% rename from Runtime/Helper/CameraHelper.cs.meta rename to Runtime/Extension/UnityEngine.Camera/UnityEngine.CameraExtension.cs.meta diff --git a/Runtime/Extension/UnityEngine.GameObject/UnityEngine.GameObjectExtension.cs b/Runtime/Extension/UnityEngine.GameObject/UnityEngine.GameObjectExtension.cs index fbfc5b0..44e03c4 100644 --- a/Runtime/Extension/UnityEngine.GameObject/UnityEngine.GameObjectExtension.cs +++ b/Runtime/Extension/UnityEngine.GameObject/UnityEngine.GameObjectExtension.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.SceneManagement; using UnityEngine.Scripting; namespace GameFrameX.Runtime @@ -14,15 +16,20 @@ public static class UnityEngineGameObjectExtension /// 销毁组件。 /// /// - /// Destroys the component attached to the same GameObject. + /// Destroys the component. In editor non-playing mode, the component is destroyed immediately. /// - /// 目标组件。 / The target component. + /// 目标组件。 / The target component. [Preserve] - public static void DestroyComponent(this Component self) + public static void DestroyComponent(this Component component) { - var component = self.GetComponent(self.GetType()); - if (component != null) + if (!ReferenceEquals(component, null)) { + if (Application.isEditor && !Application.isPlaying) + { + UnityEngine.Object.DestroyImmediate(component); + return; + } + UnityEngine.Object.Destroy(component); } } @@ -104,21 +111,166 @@ public static bool InScene(this GameObject gameObject) } /// - /// 递归设置游戏对象的层次。 + /// 设置对象的层 /// - /// - /// Sets the layer of the GameObject and all its children recursively. - /// - /// 对象。 / The GameObject instance. - /// 目标层次的编号。 / The target layer number. + /// 游戏对象 + /// 层 + /// 是否设置子物体 [Preserve] - public static void SetLayerRecursively(this GameObject gameObject, int layer) + public static void SetLayer(this GameObject gameObject, int layer, bool recursively = true) { + if (!recursively) + { + gameObject.layer = layer; + return; + } + + // GetComponentsInChildren 的结果包含自身, 无需单独设置 gameObject.layer CachedTransforms.Clear(); gameObject.GetComponentsInChildren(true, CachedTransforms); - foreach (var tf in CachedTransforms) + foreach (var sg in CachedTransforms) + { + sg.gameObject.layer = layer; + } + } + + /// + /// 销毁子物体。 + /// + /// + /// Destroys all child objects of the specified game object. + /// + /// 父物体 / Parent game object + [Preserve] + public static void RemoveChildren(this GameObject gameObject) + { + for (var i = gameObject.transform.childCount - 1; i >= 0; i--) + { + gameObject.transform.GetChild(i).gameObject.DestroyObject(); + } + } + + /// + /// 销毁游戏物体 + /// + /// + [Preserve] + public static void DestroyObject(this GameObject gameObject) + { + if (!ReferenceEquals(gameObject, null)) + { + if (Application.isEditor && !Application.isPlaying) + { + UnityEngine.Object.DestroyImmediate(gameObject); + return; + } + + UnityEngine.Object.Destroy(gameObject); + } + } + + /// + /// 销毁游戏物体 + /// + /// + [Preserve] + public static void Destroy(this GameObject gameObject) + { + gameObject.DestroyObject(); + } + + /// + /// 在指定场景中查找特定名称的节点。 + /// + /// 节点名称。 + /// 场景名称。 + /// 找到的节点的GameObject实例,如果没有找到返回null。 + [Preserve] + public static GameObject FindChildGamObjectByName(string nodeName, string sceneName = null) + { + Scene scene; + if (sceneName.IsNullOrWhiteSpace()) + { + scene = SceneManager.GetActiveScene(); + } + else + { + scene = SceneManager.GetSceneByName(sceneName); + if (!scene.isLoaded) + { + return null; + } + } + + var rootObjects = scene.GetRootGameObjects(); + foreach (var rootObject in rootObjects) + { + var result = FindChildGamObjectByName(rootObject, nodeName); + if (result.IsNotNull()) + { + return result; + } + } + + return null; + } + + /// + /// 根据游戏对象名称查询子对象 + /// + /// + /// + /// + [Preserve] + public static GameObject FindChildGamObjectByName(this GameObject gameObject, string name) + { + var transform = gameObject.transform.FindChildName(name); + if (transform.IsNotNull()) + { + return transform.gameObject; + } + + return null; + } + + /// + /// 创建游戏对象 + /// + /// + /// + /// + [Preserve] + public static GameObject CreateChild(this GameObject gameObject, string name) + { + Debug.Assert(!ReferenceEquals(gameObject, null), nameof(gameObject) + " == null"); + return gameObject.transform.CreateChild(name); + } + + /// + /// 重置游戏对象的变换数据 + /// + /// + /// + [Preserve] + public static void ResetTransform(this GameObject gameObject) + { + gameObject.transform.localScale = Vector3.one; + gameObject.transform.localPosition = Vector3.zero; + gameObject.transform.localRotation = Quaternion.identity; + } + + /// + /// 设置对象的显示排序层 + /// + /// 游戏对象 + /// 显示层 + [Preserve] + public static void SetSortingGroupLayer(this GameObject gameObject, string sortingLayer) + { + SortingGroup[] sortingGroups = gameObject.GetComponentsInChildren(); + foreach (SortingGroup sg in sortingGroups) { - tf.gameObject.layer = layer; + sg.sortingLayerName = sortingLayer; } } } diff --git a/Runtime/Extension/UnityEngine.Renderer.meta b/Runtime/Extension/UnityEngine.Renderer.meta new file mode 100644 index 0000000..144075c --- /dev/null +++ b/Runtime/Extension/UnityEngine.Renderer.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 485bf44a913d4baf9bb92f8a28d85fa6 +timeCreated: 1787492856 \ No newline at end of file diff --git a/Runtime/Helper/UnityRendererHelper.cs b/Runtime/Extension/UnityEngine.Renderer/UnityEngine.RendererExtension.cs similarity index 87% rename from Runtime/Helper/UnityRendererHelper.cs rename to Runtime/Extension/UnityEngine.Renderer/UnityEngine.RendererExtension.cs index c517392..ff2d727 100644 --- a/Runtime/Helper/UnityRendererHelper.cs +++ b/Runtime/Extension/UnityEngine.Renderer/UnityEngine.RendererExtension.cs @@ -9,7 +9,7 @@ namespace GameFrameX.Runtime /// Unity renderer helper class. /// [UnityEngine.Scripting.Preserve] - public static class UnityRendererHelper + public static class UnityEngineRendererExtension { /// /// 判断渲染组件是否在相机范围内。 @@ -21,7 +21,7 @@ public static class UnityRendererHelper /// 相机对象 / Camera object /// 如果渲染组件在相机范围内返回 true;否则返回 false / true if visible; otherwise false [UnityEngine.Scripting.Preserve] - public static bool IsVisibleFrom(Renderer renderer, Camera camera) + public static bool IsVisibleFrom(this Renderer renderer, Camera camera) { Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera); return GeometryUtility.TestPlanesAABB(planes, renderer.bounds); @@ -34,7 +34,7 @@ public static bool IsVisibleFrom(Renderer renderer, Camera camera) /// 相机对象 /// 如果渲染组件在相机范围内返回true,否则返回false [UnityEngine.Scripting.Preserve] - public static bool IsVisibleFrom(MeshRenderer renderer, Camera camera) + public static bool IsVisibleFrom(this MeshRenderer renderer, Camera camera) { Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera); return GeometryUtility.TestPlanesAABB(planes, renderer.bounds); diff --git a/Runtime/Helper/UnityRendererHelper.cs.meta b/Runtime/Extension/UnityEngine.Renderer/UnityEngine.RendererExtension.cs.meta similarity index 100% rename from Runtime/Helper/UnityRendererHelper.cs.meta rename to Runtime/Extension/UnityEngine.Renderer/UnityEngine.RendererExtension.cs.meta diff --git a/Runtime/Extension/UnityEngine.Transform/UnityEngine.TransformExtension.cs b/Runtime/Extension/UnityEngine.Transform/UnityEngine.TransformExtension.cs index efbd6fc..f0678c5 100644 --- a/Runtime/Extension/UnityEngine.Transform/UnityEngine.TransformExtension.cs +++ b/Runtime/Extension/UnityEngine.Transform/UnityEngine.TransformExtension.cs @@ -383,5 +383,20 @@ public static void Reset(this Transform transform) transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; } + + /// + /// 创建游戏对象 + /// + /// + /// + /// + [UnityEngine.Scripting.Preserve] + public static GameObject CreateChild(this Transform transform, string name) + { + Debug.Assert(!ReferenceEquals(transform, null), nameof(transform) + " == null"); + var gameObject = new GameObject(name); + gameObject.transform.SetParent(transform); + return gameObject; + } } -} +} \ No newline at end of file diff --git a/Runtime/GameFrameXCroppingHelper.cs b/Runtime/GameFrameXCroppingHelper.cs index b682b6c..bee49fe 100644 --- a/Runtime/GameFrameXCroppingHelper.cs +++ b/Runtime/GameFrameXCroppingHelper.cs @@ -7,7 +7,7 @@ public class GameFrameXCroppingHelper : MonoBehaviour private void Start() { #if ENABLE_GAME_FRAME_X_DO_TWEEN - _ = typeof(GameFrameX.Runtime.DoTweenHelper); + _ = typeof(GameFrameX.Runtime.DoTweenUtility); #endif _ = typeof(BinaryExtension); _ = typeof(BufferExtension); @@ -18,25 +18,26 @@ private void Start() _ = typeof(GameFrameX.ObjectPool.ObjectPoolBase); _ = typeof(GameFrameX.ObjectPool.ObjectPoolManager); _ = typeof(GameFrameX.ObjectPool.ReleaseObjectFilterCallback<>); - _ = typeof(GameFrameX.Runtime.ApplicationHelper); + _ = typeof(GameFrameX.Runtime.ApplicationUtility); _ = typeof(GameFrameX.Runtime.BaseComponent); _ = typeof(GameFrameX.Runtime.BaseEventArgs); _ = typeof(GameFrameX.Runtime.BindableProperty<>); - _ = typeof(GameFrameX.Runtime.CameraHelper); _ = typeof(GameFrameX.Runtime.DefaultCompressionHelper); _ = typeof(GameFrameX.Runtime.DefaultLogHelper); _ = typeof(GameFrameX.Runtime.DefaultTextHelper); _ = typeof(GameFrameX.Runtime.DefaultVersionHelper); - _ = typeof(GameFrameX.Runtime.DistinctHelper); _ = typeof(GameFrameX.Runtime.EventPool<>); _ = typeof(GameFrameX.Runtime.EventPoolMode); - _ = typeof(GameFrameX.Runtime.FileHelper); _ = typeof(GameFrameX.Runtime.GameEntry); _ = typeof(GameFrameX.Runtime.GameFrameworkComponent); + _ = typeof(GameFrameX.Runtime.GameFrameworkCompression); + _ = typeof(GameFrameX.Runtime.GameFrameworkCompression.ICompressionHelper); _ = typeof(GameFrameX.Runtime.GameFrameworkEntry); _ = typeof(GameFrameX.Runtime.GameFrameworkEventArgs); _ = typeof(GameFrameX.Runtime.GameFrameworkException); _ = typeof(GameFrameX.Runtime.GameFrameworkGuard); + _ = typeof(GameFrameX.Runtime.GameFrameworkJson); + _ = typeof(GameFrameX.Runtime.GameFrameworkJson.IJsonHelper); _ = typeof(GameFrameX.Runtime.GameFrameworkLinkedList<>); _ = typeof(GameFrameX.Runtime.GameFrameworkLinkedList<>.Enumerator); _ = typeof(GameFrameX.Runtime.GameFrameworkLinkedListRange<>); @@ -53,21 +54,19 @@ private void Start() _ = typeof(GameFrameX.Runtime.GameFrameworkSerializer<>.SerializeCallback); _ = typeof(GameFrameX.Runtime.GameFrameworkSerializer<>.TryGetValueCallback); _ = typeof(GameFrameX.Runtime.GameFrameworkSingleton<>); + _ = typeof(GameFrameX.Runtime.GameFrameworkText); + _ = typeof(GameFrameX.Runtime.GameFrameworkText.ITextHelper); _ = typeof(GameFrameX.Runtime.GameFrameXCroppingHelper); - _ = typeof(GameFrameX.Runtime.GameObjectHelper); + _ = typeof(GameFrameX.Runtime.GameObjectUtility); _ = typeof(GameFrameX.Runtime.Helper); _ = typeof(GameFrameX.Runtime.IReference); _ = typeof(GameFrameX.Runtime.LitJsonHelper); _ = typeof(GameFrameX.Runtime.ITaskAgent<>); _ = typeof(GameFrameX.Runtime.Log); - _ = typeof(GameFrameX.Runtime.MathHelper); - _ = typeof(GameFrameX.Runtime.NetworkHelper); + _ = typeof(GameFrameX.Runtime.MathUtility); _ = typeof(GameFrameX.Runtime.ObjectDontDestroyOnLoad); - _ = typeof(GameFrameX.Runtime.ObjectHelper); _ = typeof(GameFrameX.Runtime.ObjectPoolComponent); - _ = typeof(GameFrameX.Runtime.PathHelper); - _ = typeof(GameFrameX.Runtime.PositionHelper); - _ = typeof(GameFrameX.Runtime.RandomHelper); + _ = typeof(GameFrameX.Runtime.PositionUtility); _ = typeof(GameFrameX.Runtime.ReferencePool); _ = typeof(GameFrameX.Runtime.ReferencePoolComponent); _ = typeof(GameFrameX.Runtime.ReferencePoolInfo); @@ -82,40 +81,30 @@ private void Start() _ = typeof(GameFrameX.Runtime.TaskStatus); _ = typeof(GameFrameX.Runtime.TimerHelper); _ = typeof(GameFrameX.Runtime.TypeNamePair); - _ = typeof(GameFrameX.Runtime.UnityRendererHelper); - _ = typeof(GameFrameX.Runtime.Utility); - _ = typeof(GameFrameX.Runtime.Utility.Assembly); - _ = typeof(GameFrameX.Runtime.Utility.Asset); - _ = typeof(GameFrameX.Runtime.Utility.Asset.Path); - _ = typeof(GameFrameX.Runtime.Utility.Compression); - _ = typeof(GameFrameX.Runtime.Utility.Compression.ICompressionHelper); - _ = typeof(GameFrameX.Runtime.Utility.Const); - _ = typeof(GameFrameX.Runtime.Utility.Const.FileNameSuffix); - _ = typeof(GameFrameX.Runtime.Utility.Converter); - _ = typeof(GameFrameX.Runtime.Utility.Encryption); - _ = typeof(GameFrameX.Runtime.Utility.Encryption.Aes); - _ = typeof(GameFrameX.Runtime.Utility.Encryption.Dsa); - _ = typeof(GameFrameX.Runtime.Utility.Encryption.Rsa); - _ = typeof(GameFrameX.Runtime.Utility.File); - _ = typeof(GameFrameX.Runtime.Utility.Hash); - _ = typeof(GameFrameX.Runtime.Utility.Hash.HMACSha256); - _ = typeof(GameFrameX.Runtime.Utility.Hash.MD5); - _ = typeof(GameFrameX.Runtime.Utility.Hash.MurmurHash3); - _ = typeof(GameFrameX.Runtime.Utility.Hash.Sha1); - _ = typeof(GameFrameX.Runtime.Utility.Hash.XXHash); - _ = typeof(GameFrameX.Runtime.Utility.IdGenerator); - _ = typeof(GameFrameX.Runtime.Utility.Json); - _ = typeof(GameFrameX.Runtime.Utility.Json.IJsonHelper); - _ = typeof(GameFrameX.Runtime.Utility.Marshal); - _ = typeof(GameFrameX.Runtime.Utility.Net); - _ = typeof(GameFrameX.Runtime.Utility.Object); - _ = typeof(GameFrameX.Runtime.Utility.Path); - _ = typeof(GameFrameX.Runtime.Utility.RandomUtility); - _ = typeof(GameFrameX.Runtime.Utility.Text); - _ = typeof(GameFrameX.Runtime.Utility.Text.ITextHelper); - _ = typeof(GameFrameX.Runtime.Utility.Verifier); - _ = typeof(GameFrameX.Runtime.Utility.Verifier.Crc64); - _ = typeof(GameFrameX.Runtime.Utility.Verifier.NonCryptographicHashAlgorithm); + _ = typeof(GameFrameX.Runtime.AssemblyUtility); + _ = typeof(GameFrameX.Runtime.AssetPathUtility); + _ = typeof(GameFrameX.Runtime.FileNameSuffix); + _ = typeof(GameFrameX.Runtime.ConverterUtility); + _ = typeof(GameFrameX.Runtime.EncryptionUtility); + _ = typeof(GameFrameX.Runtime.EncryptionUtility.Aes); + _ = typeof(GameFrameX.Runtime.EncryptionUtility.Dsa); + _ = typeof(GameFrameX.Runtime.EncryptionUtility.Rsa); + _ = typeof(GameFrameX.Runtime.FileUtility); + _ = typeof(GameFrameX.Runtime.HashUtility); + _ = typeof(GameFrameX.Runtime.HashUtility.HmacSha256); + _ = typeof(GameFrameX.Runtime.HashUtility.Md5); + _ = typeof(GameFrameX.Runtime.HashUtility.MurmurHash3); + _ = typeof(GameFrameX.Runtime.HashUtility.Sha1); + _ = typeof(GameFrameX.Runtime.HashUtility.XxHash); + _ = typeof(GameFrameX.Runtime.IdGeneratorUtility); + _ = typeof(GameFrameX.Runtime.MarshalUtility); + _ = typeof(GameFrameX.Runtime.NetworkUtility); + _ = typeof(GameFrameX.Runtime.ObjectUtility); + _ = typeof(GameFrameX.Runtime.PathUtility); + _ = typeof(GameFrameX.Runtime.RandomUtility); + _ = typeof(GameFrameX.Runtime.VerifierUtility); + _ = typeof(GameFrameX.Runtime.VerifierUtility.Crc64); + _ = typeof(GameFrameX.Runtime.VerifierUtility.NonCryptographicHashAlgorithm); _ = typeof(GameFrameX.Runtime.VarBoolean); _ = typeof(GameFrameX.Runtime.VarByte); _ = typeof(GameFrameX.Runtime.VarByteArray); @@ -150,7 +139,7 @@ private void Start() _ = typeof(GameFrameX.Runtime.VarVector4); _ = typeof(GameFrameX.Runtime.GameVersion); _ = typeof(GameFrameX.Runtime.GameVersion.IVersionHelper); - _ = typeof(GameFrameX.Runtime.ZipHelper); + _ = typeof(GameFrameX.Runtime.ZipUtility); _ = typeof(ObjectExtension); _ = typeof(SpanExtension); _ = typeof(StringExtension); @@ -159,7 +148,9 @@ private void Start() _ = typeof(GameFrameX.Runtime.DateTimeExtensions); _ = typeof(GameFrameX.Runtime.ThreadLocalRandom); _ = typeof(GameFrameX.Runtime.TypeExtensions); + _ = typeof(GameFrameX.Runtime.UnityEngineCameraExtension); _ = typeof(GameFrameX.Runtime.UnityEngineGameObjectExtension); + _ = typeof(GameFrameX.Runtime.UnityEngineRendererExtension); _ = typeof(GameFrameX.Runtime.UnityEngineTransformExtension); _ = typeof(GameFrameX.Runtime.UnityEngineVector2Extension); _ = typeof(GameFrameX.Runtime.UnityEngineVector3Extension); diff --git a/Runtime/Helper/Compression.meta b/Runtime/Helper/Compression.meta new file mode 100644 index 0000000..d6b0f43 --- /dev/null +++ b/Runtime/Helper/Compression.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8cc67da3ca234c2b80148f93f3ff822c +timeCreated: 1787476976 \ No newline at end of file diff --git a/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs b/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs new file mode 100644 index 0000000..1098cc4 --- /dev/null +++ b/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs @@ -0,0 +1,79 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System.IO; + +namespace GameFrameX.Runtime +{ + public static partial class GameFrameworkCompression + { + public interface ICompressionHelper + { + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 要压缩的数据的二进制流的偏移。 + /// 要压缩的数据的二进制流的长度。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + bool Compress(byte[] bytes, int offset, int length, Stream compressedStream); + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + bool Compress(Stream stream, Stream compressedStream); + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 要解压缩的数据的二进制流的偏移。 + /// 要解压缩的数据的二进制流的长度。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + bool Decompress(byte[] bytes, int offset, int length, Stream decompressedStream); + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + bool Decompress(Stream stream, Stream decompressedStream); + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs.meta b/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs.meta new file mode 100644 index 0000000..0555e23 --- /dev/null +++ b/Runtime/Helper/Compression/GameFrameworkCompression.ICompressionHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 96c1892063864cd9bca92bd00994dad9 +timeCreated: 1787478525 \ No newline at end of file diff --git a/Runtime/Helper/Compression/GameFrameworkCompression.cs b/Runtime/Helper/Compression/GameFrameworkCompression.cs new file mode 100644 index 0000000..dcb8f0e --- /dev/null +++ b/Runtime/Helper/Compression/GameFrameworkCompression.cs @@ -0,0 +1,378 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.IO; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + public static partial class GameFrameworkCompression + { + private static ICompressionHelper s_CompressionHelper = null; + + /// + /// 设置压缩解压缩辅助器。 + /// + /// 要设置的压缩解压缩辅助器。 + [Preserve] + public static void SetCompressionHelper(ICompressionHelper compressionHelper) + { + s_CompressionHelper = compressionHelper; + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + [Preserve] + public static byte[] Compress(byte[] bytes) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + return Compress(bytes, 0, bytes.Length); + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + [Preserve] + public static bool Compress(byte[] bytes, Stream compressedStream) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + return Compress(bytes, 0, bytes.Length, compressedStream); + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 要压缩的数据的二进制流的偏移。 + /// 要压缩的数据的二进制流的长度。 + /// 压缩后的数据的二进制流。 + [Preserve] + public static byte[] Compress(byte[] bytes, int offset, int length) + { + using (MemoryStream compressedStream = new MemoryStream()) + { + if (Compress(bytes, offset, length, compressedStream)) + { + return compressedStream.ToArray(); + } + else + { + return null; + } + } + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 要压缩的数据的二进制流的偏移。 + /// 要压缩的数据的二进制流的长度。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + [Preserve] + public static bool Compress(byte[] bytes, int offset, int length, Stream compressedStream) + { + if (s_CompressionHelper == null) + { + throw new GameFrameworkException("Compressed helper is invalid."); + } + + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + if (offset < 0 || length < 0 || offset + length > bytes.Length) + { + throw new GameFrameworkException("Offset or length is invalid."); + } + + if (compressedStream == null) + { + throw new GameFrameworkException("Compressed stream is invalid."); + } + + try + { + return s_CompressionHelper.Compress(bytes, offset, length, compressedStream); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not compress with exception '{0}'.", exception), exception); + } + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + [Preserve] + public static byte[] Compress(Stream stream) + { + using (MemoryStream compressedStream = new MemoryStream()) + { + if (Compress(stream, compressedStream)) + { + return compressedStream.ToArray(); + } + else + { + return null; + } + } + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + [Preserve] + public static bool Compress(Stream stream, Stream compressedStream) + { + if (s_CompressionHelper == null) + { + throw new GameFrameworkException("Compressed helper is invalid."); + } + + if (stream == null) + { + throw new GameFrameworkException("Stream is invalid."); + } + + if (compressedStream == null) + { + throw new GameFrameworkException("Compressed stream is invalid."); + } + + try + { + return s_CompressionHelper.Compress(stream, compressedStream); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not compress with exception '{0}'.", exception), exception); + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 解压缩后的数据的二进制流。 + [Preserve] + public static byte[] Decompress(byte[] bytes) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + return Decompress(bytes, 0, bytes.Length); + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + [Preserve] + public static bool Decompress(byte[] bytes, Stream decompressedStream) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + return Decompress(bytes, 0, bytes.Length, decompressedStream); + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 要解压缩的数据的二进制流的偏移。 + /// 要解压缩的数据的二进制流的长度。 + /// 解压缩后的数据的二进制流。 + [Preserve] + public static byte[] Decompress(byte[] bytes, int offset, int length) + { + using (MemoryStream decompressedStream = new MemoryStream()) + { + if (Decompress(bytes, offset, length, decompressedStream)) + { + return decompressedStream.ToArray(); + } + else + { + return null; + } + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 要解压缩的数据的二进制流的偏移。 + /// 要解压缩的数据的二进制流的长度。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + [Preserve] + public static bool Decompress(byte[] bytes, int offset, int length, Stream decompressedStream) + { + if (s_CompressionHelper == null) + { + throw new GameFrameworkException("Compressed helper is invalid."); + } + + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + if (offset < 0 || length < 0 || offset + length > bytes.Length) + { + throw new GameFrameworkException("Offset or length is invalid."); + } + + if (decompressedStream == null) + { + throw new GameFrameworkException("Decompressed stream is invalid."); + } + + try + { + return s_CompressionHelper.Decompress(bytes, offset, length, decompressedStream); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not decompress with exception '{0}'.", exception), exception); + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 是否解压缩数据成功。 + [Preserve] + public static byte[] Decompress(Stream stream) + { + using (MemoryStream decompressedStream = new MemoryStream()) + { + if (Decompress(stream, decompressedStream)) + { + return decompressedStream.ToArray(); + } + else + { + return null; + } + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + [Preserve] + public static bool Decompress(Stream stream, Stream decompressedStream) + { + if (s_CompressionHelper == null) + { + throw new GameFrameworkException("Compressed helper is invalid."); + } + + if (stream == null) + { + throw new GameFrameworkException("Stream is invalid."); + } + + if (decompressedStream == null) + { + throw new GameFrameworkException("Decompressed stream is invalid."); + } + + try + { + return s_CompressionHelper.Decompress(stream, decompressedStream); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not decompress with exception '{0}'.", exception), exception); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/Compression/GameFrameworkCompression.cs.meta b/Runtime/Helper/Compression/GameFrameworkCompression.cs.meta new file mode 100644 index 0000000..9452478 --- /dev/null +++ b/Runtime/Helper/Compression/GameFrameworkCompression.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 18c1eb7468b6415f835c49c6c5e6cf40 +timeCreated: 1787478485 \ No newline at end of file diff --git a/Runtime/Helper/DefaultCompressionHelper.cs b/Runtime/Helper/DefaultCompressionHelper.cs index e96ecab..fa8447c 100644 --- a/Runtime/Helper/DefaultCompressionHelper.cs +++ b/Runtime/Helper/DefaultCompressionHelper.cs @@ -41,7 +41,7 @@ namespace GameFrameX.Runtime /// 默认压缩解压缩辅助器。 /// [UnityEngine.Scripting.Preserve] - public class DefaultCompressionHelper : Utility.Compression.ICompressionHelper + public class DefaultCompressionHelper : GameFrameworkCompression.ICompressionHelper { private const int CachedBytesLength = 0x1000; private readonly byte[] _cachedBytes = new byte[CachedBytesLength]; diff --git a/Runtime/Helper/DefaultTextHelper.cs b/Runtime/Helper/DefaultTextHelper.cs index 832c240..71b7109 100644 --- a/Runtime/Helper/DefaultTextHelper.cs +++ b/Runtime/Helper/DefaultTextHelper.cs @@ -41,7 +41,7 @@ namespace GameFrameX.Runtime /// 默认字符辅助器。 /// [UnityEngine.Scripting.Preserve] - public class DefaultTextHelper : Utility.Text.ITextHelper + public class DefaultTextHelper : GameFrameworkText.ITextHelper { private const int StringBuilderCapacity = 1024; diff --git a/Runtime/Helper/DistinctHelper.cs b/Runtime/Helper/DistinctHelper.cs deleted file mode 100644 index 6334184..0000000 --- a/Runtime/Helper/DistinctHelper.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace GameFrameX.Runtime -{ - /// - /// 去重帮助类。 - /// - /// - /// Distinct helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class DistinctHelper - { - /// - /// 根据指定键选择器对集合进行去重。 - /// - /// - /// Returns distinct elements from a collection based on a key selector. - /// - /// 源集合元素类型 / Source collection element type - /// 键选择器返回的键类型 / Key type returned by the key selector - /// 要去重的源集合 / Source collection to deduplicate - /// 用于选择比较键的函数 / Function to select the comparison key - /// 去重后的集合 / Deduplicated collection - [UnityEngine.Scripting.Preserve] - public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) - { - var identifiedKeys = new HashSet(); - - foreach (var item in source) - { - if (identifiedKeys.Add(keySelector(item))) - { - yield return item; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Helper/GameObjectHelper.cs b/Runtime/Helper/GameObjectHelper.cs deleted file mode 100644 index 32940a4..0000000 --- a/Runtime/Helper/GameObjectHelper.cs +++ /dev/null @@ -1,214 +0,0 @@ -using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.SceneManagement; - -namespace GameFrameX.Runtime -{ - /// - /// 游戏对象帮助类。 - /// - /// - /// Game object helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class GameObjectHelper - { - /// - /// 销毁子物体。 - /// - /// - /// Destroys all child objects of the specified game object. - /// - /// 父物体 / Parent game object - [UnityEngine.Scripting.Preserve] - public static void RemoveChildren(GameObject go) - { - for (var i = go.transform.childCount - 1; i >= 0; i--) - { - Destroy(go.transform.GetChild(i).gameObject); - } - } - - /// - /// 销毁游戏物体 - /// - /// - [UnityEngine.Scripting.Preserve] - public static void DestroyObject(this GameObject gameObject) - { - if (!ReferenceEquals(gameObject, null)) - { - if (Application.isEditor && !Application.isPlaying) - { - Object.DestroyImmediate(gameObject); - return; - } - - Object.Destroy(gameObject); - } - } - - /// - /// 销毁游戏物体 - /// - /// - [UnityEngine.Scripting.Preserve] - public static void Destroy(GameObject gameObject) - { - gameObject.DestroyObject(); - } - - /// - /// 销毁游戏组件 - /// - /// - [UnityEngine.Scripting.Preserve] - public static void DestroyComponent(Component component) - { - if (!ReferenceEquals(component, null)) - { - if (Application.isEditor && !Application.isPlaying) - { - Object.DestroyImmediate(component); - return; - } - - Object.Destroy(component); - } - } - - /// - /// 在指定场景中查找特定名称的节点。 - /// - /// 场景名称。 - /// 节点名称。 - /// 找到的节点的GameObject实例,如果没有找到返回null。 - [UnityEngine.Scripting.Preserve] - public static GameObject FindChildGamObjectByName(string nodeName, string sceneName = null) - { - Scene scene; - if (sceneName.IsNullOrWhiteSpace()) - { - scene = SceneManager.GetActiveScene(); - } - else - { - scene = SceneManager.GetSceneByName(sceneName); - if (!scene.isLoaded) - { - return null; - } - } - - var rootObjects = scene.GetRootGameObjects(); - foreach (var rootObject in rootObjects) - { - var result = FindChildGamObjectByName(rootObject, nodeName); - if (result.IsNotNull()) - { - return result; - } - } - - return null; - } - - /// - /// 根据游戏对象名称查询子对象 - /// - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static GameObject FindChildGamObjectByName(GameObject gameObject, string name) - { - var transform = gameObject.transform.FindChildName(name); - if (transform.IsNotNull()) - { - return transform.gameObject; - } - - return null; - } - - /// - /// 创建游戏对象 - /// - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static GameObject Create(Transform parent, string name) - { - Debug.Assert(!ReferenceEquals(parent, null), nameof(parent) + " == null"); - var gameObject = new GameObject(name); - gameObject.transform.SetParent(parent); - return gameObject; - } - - /// - /// 创建游戏对象 - /// - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static GameObject Create(GameObject parent, string name) - { - Debug.Assert(!ReferenceEquals(parent, null), nameof(parent) + " == null"); - return Create(parent.transform, name); - } - - /// - /// 重置游戏对象的变换数据 - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static void ResetTransform(GameObject gameObject) - { - gameObject.transform.localScale = Vector3.one; - gameObject.transform.localPosition = Vector3.zero; - gameObject.transform.localRotation = Quaternion.identity; - } - - /// - /// 设置对象的显示排序层 - /// - /// 游戏对象 - /// 显示层 - [UnityEngine.Scripting.Preserve] - public static void SetSortingGroupLayer(GameObject gameObject, string sortingLayer) - { - SortingGroup[] sortingGroups = gameObject.GetComponentsInChildren(); - foreach (SortingGroup sg in sortingGroups) - { - sg.sortingLayerName = sortingLayer; - } - } - - /// - /// 设置对象的层 - /// - /// 游戏对象 - /// 层 - /// 是否设置子物体 - [UnityEngine.Scripting.Preserve] - public static void SetLayer(GameObject gameObject, int layer, bool children = true) - { - if (gameObject.layer != layer) - { - gameObject.layer = layer; - } - - if (children) - { - Transform[] transforms = gameObject.GetComponentsInChildren(); - foreach (var sg in transforms) - { - sg.gameObject.layer = layer; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Base/GameVersion.meta b/Runtime/Helper/GameVersion.meta similarity index 100% rename from Runtime/Base/GameVersion.meta rename to Runtime/Helper/GameVersion.meta diff --git a/Runtime/Base/GameVersion/GameVersion.IVersionHelper.cs b/Runtime/Helper/GameVersion/GameVersion.IVersionHelper.cs similarity index 100% rename from Runtime/Base/GameVersion/GameVersion.IVersionHelper.cs rename to Runtime/Helper/GameVersion/GameVersion.IVersionHelper.cs diff --git a/Runtime/Base/GameVersion/GameVersion.IVersionHelper.cs.meta b/Runtime/Helper/GameVersion/GameVersion.IVersionHelper.cs.meta similarity index 100% rename from Runtime/Base/GameVersion/GameVersion.IVersionHelper.cs.meta rename to Runtime/Helper/GameVersion/GameVersion.IVersionHelper.cs.meta diff --git a/Runtime/Base/GameVersion/GameVersion.cs b/Runtime/Helper/GameVersion/GameVersion.cs similarity index 100% rename from Runtime/Base/GameVersion/GameVersion.cs rename to Runtime/Helper/GameVersion/GameVersion.cs diff --git a/Runtime/Base/GameVersion/GameVersion.cs.meta b/Runtime/Helper/GameVersion/GameVersion.cs.meta similarity index 100% rename from Runtime/Base/GameVersion/GameVersion.cs.meta rename to Runtime/Helper/GameVersion/GameVersion.cs.meta diff --git a/Runtime/Helper/Helper.cs b/Runtime/Helper/Helper.cs index abf234a..3c17e2e 100644 --- a/Runtime/Helper/Helper.cs +++ b/Runtime/Helper/Helper.cs @@ -75,7 +75,7 @@ public static T CreateHelper(string helperTypeName, T customHelper, int index T helper = null; if (!string.IsNullOrEmpty(helperTypeName)) { - System.Type helperType = Utility.Assembly.GetType(helperTypeName); + System.Type helperType = AssemblyUtility.GetType(helperTypeName); if (helperType == null) { Log.Warning("Can not find helper type '{0}'.", helperTypeName); @@ -123,7 +123,7 @@ public static T CreateHelper(GameObject target, string helperTypeName, T cust T helper = null; if (!string.IsNullOrEmpty(helperTypeName)) { - System.Type helperType = Utility.Assembly.GetType(helperTypeName); + System.Type helperType = AssemblyUtility.GetType(helperTypeName); if (helperType == null) { Log.Warning("Can not find helper type '{0}'.", helperTypeName); diff --git a/Runtime/Helper/Json.meta b/Runtime/Helper/Json.meta new file mode 100644 index 0000000..775d652 --- /dev/null +++ b/Runtime/Helper/Json.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 87d4e0eb603941849fba15464aa90fb0 +timeCreated: 1787476984 \ No newline at end of file diff --git a/Runtime/Utility/Utility.Json.IJsonHelper.cs b/Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs similarity index 59% rename from Runtime/Utility/Utility.Json.IJsonHelper.cs rename to Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs index 46eb235..b459a71 100644 --- a/Runtime/Utility/Utility.Json.IJsonHelper.cs +++ b/Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs @@ -1,17 +1,17 @@ -// ========================================================================================== +// ========================================================================================== // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 // GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights // 均受中华人民共和国及相关国际法律法规保护。 // are protected by the laws of the People's Republic of China and relevant international regulations. -// +// // 使用本项目须严格遵守相应法律法规及开源许可证之规定。 // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// +// // 本项目采用 Apache License 2.0 许可证分发, // This project is licensed under the Apache License 2.0, // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 // please refer to the LICENSE file in the root directory of the source code for the full license text. -// +// // 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 // It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, // 侵犯他人合法权益等法律法规所禁止的行为! @@ -20,7 +20,7 @@ // Any legal disputes and liabilities arising from secondary development based on this project // 本项目组织与贡献者概不承担。 // shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// +// // GitHub 仓库:https://github.com/GameFrameX // GitHub Repository: https://github.com/GameFrameX // Gitee 仓库:https://gitee.com/GameFrameX @@ -35,41 +35,32 @@ namespace GameFrameX.Runtime { - public static partial class Utility + public static partial class GameFrameworkJson { - public static partial class Json + public interface IJsonHelper { /// - /// JSON 辅助器接口。 + /// 将对象序列化为 JSON 字符串。 /// - /// - /// JSON helper interface. - /// - public interface IJsonHelper - { - /// - /// 将对象序列化为 JSON 字符串。 - /// - /// 要序列化的对象。 - /// 序列化后的 JSON 字符串。 - string ToJson(object obj); + /// 要序列化的对象。 + /// 序列化后的 JSON 字符串。 + string ToJson(object obj); - /// - /// 将 JSON 字符串反序列化为对象。 - /// - /// 对象类型。 - /// 要反序列化的 JSON 字符串。 - /// 反序列化后的对象。 - T ToObject(string json); + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + T ToObject(string json); - /// - /// 将 JSON 字符串反序列化为对象。 - /// - /// 对象类型。 - /// 要反序列化的 JSON 字符串。 - /// 反序列化后的对象。 - object ToObject(Type objectType, string json); - } + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + object ToObject(Type objectType, string json); } } } \ No newline at end of file diff --git a/Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs.meta b/Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs.meta new file mode 100644 index 0000000..7479cbd --- /dev/null +++ b/Runtime/Helper/Json/GameFrameworkJson.IJsonHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e6797df1cb23418ea34ce69145e3faf3 +timeCreated: 1787477570 \ No newline at end of file diff --git a/Runtime/Helper/Json/GameFrameworkJson.cs b/Runtime/Helper/Json/GameFrameworkJson.cs new file mode 100644 index 0000000..c9a4e9e --- /dev/null +++ b/Runtime/Helper/Json/GameFrameworkJson.cs @@ -0,0 +1,147 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + public static partial class GameFrameworkJson + { + private static IJsonHelper s_JsonHelper = null; + + /// + /// 设置 JSON 辅助器。 + /// + /// + /// Sets the JSON helper. + /// + /// 要设置的 JSON 辅助器 / The JSON helper to set + [Preserve] + public static void SetJsonHelper(IJsonHelper jsonHelper) + { + s_JsonHelper = jsonHelper; + } + + /// + /// 将对象序列化为 JSON 字符串。 + /// + /// 要序列化的对象。 + /// 序列化后的 JSON 字符串。 + [Preserve] + public static string ToJson(object obj) + { + if (s_JsonHelper == null) + { + throw new GameFrameworkException("JSON helper is invalid."); + } + + try + { + return s_JsonHelper.ToJson(obj); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not convert to JSON with exception '{0}'.", exception), exception); + } + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + [Preserve] + public static T ToObject(string json) + { + if (s_JsonHelper == null) + { + throw new GameFrameworkException("JSON helper is invalid."); + } + + try + { + return s_JsonHelper.ToObject(json); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not convert to object with exception '{0}'.", exception), exception); + } + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + [Preserve] + public static object ToObject(Type objectType, string json) + { + if (s_JsonHelper == null) + { + throw new GameFrameworkException("JSON helper is invalid."); + } + + if (objectType == null) + { + throw new GameFrameworkException("Object type is invalid."); + } + + try + { + return s_JsonHelper.ToObject(objectType, json); + } + catch (Exception exception) + { + if (exception is GameFrameworkException) + { + throw; + } + + throw new GameFrameworkException(GameFrameworkText.Format("Can not convert to object with exception '{0}'.", exception), exception); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/Json/GameFrameworkJson.cs.meta b/Runtime/Helper/Json/GameFrameworkJson.cs.meta new file mode 100644 index 0000000..f345525 --- /dev/null +++ b/Runtime/Helper/Json/GameFrameworkJson.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0691f04b6ead41f482ae95d804f6a99b +timeCreated: 1787477484 \ No newline at end of file diff --git a/Runtime/Helper/LitJsonHelper.cs b/Runtime/Helper/LitJsonHelper.cs index d082c7d..6d1a8a0 100644 --- a/Runtime/Helper/LitJsonHelper.cs +++ b/Runtime/Helper/LitJsonHelper.cs @@ -43,7 +43,7 @@ namespace GameFrameX.Runtime /// Optional JSON helper using LitJSON. /// [UnityEngine.Scripting.Preserve] - public class LitJsonHelper : Utility.Json.IJsonHelper + public class LitJsonHelper : GameFrameworkJson.IJsonHelper { /// /// 初始化 LitJSON 函数集辅助器的新实例。 @@ -135,4 +135,4 @@ public object ToObject(Type objectType, string json) } } } -} +} \ No newline at end of file diff --git a/Runtime/Base/Log.meta b/Runtime/Helper/Log.meta similarity index 100% rename from Runtime/Base/Log.meta rename to Runtime/Helper/Log.meta diff --git a/Runtime/Base/Log/GameFrameworkLog.ILogHelper.cs b/Runtime/Helper/Log/GameFrameworkLog.ILogHelper.cs similarity index 100% rename from Runtime/Base/Log/GameFrameworkLog.ILogHelper.cs rename to Runtime/Helper/Log/GameFrameworkLog.ILogHelper.cs diff --git a/Runtime/Base/Log/GameFrameworkLog.ILogHelper.cs.meta b/Runtime/Helper/Log/GameFrameworkLog.ILogHelper.cs.meta similarity index 100% rename from Runtime/Base/Log/GameFrameworkLog.ILogHelper.cs.meta rename to Runtime/Helper/Log/GameFrameworkLog.ILogHelper.cs.meta diff --git a/Runtime/Base/Log/GameFrameworkLog.cs b/Runtime/Helper/Log/GameFrameworkLog.cs similarity index 91% rename from Runtime/Base/Log/GameFrameworkLog.cs rename to Runtime/Helper/Log/GameFrameworkLog.cs index 6c52610..d3a7e67 100644 --- a/Runtime/Base/Log/GameFrameworkLog.cs +++ b/Runtime/Helper/Log/GameFrameworkLog.cs @@ -1,2731 +1,2731 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using UnityEngine.Scripting; // 确保引入命名空间 - -namespace GameFrameX.Runtime -{ - /// - /// 游戏框架日志类。 - /// - /// - /// Game framework log class. - /// Provides static methods for logging messages at different severity levels (Debug, Info, Warning, Error, Fatal). - /// Requires an ILogHelper implementation to be set via SetLogHelper before logging can occur. - /// - public static partial class GameFrameworkLog - { - private static ILogHelper _logHelper = null; - - /// - /// 设置游戏框架日志辅助器。 - /// - /// - /// Sets the game framework log helper. - /// The log helper is responsible for the actual log output implementation. - /// - /// 要设置的游戏框架日志辅助器 / The log helper to set. - [Preserve] // 添加 Preserve 标签 - public static void SetLogHelper(ILogHelper logHelper) - { - _logHelper = logHelper; - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志内容 / Log message content. - [Preserve] // 添加 Preserve 标签 - public static void Debug(object message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, message); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志内容 / Log message content. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, message); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数的类型 / The type of the log argument. - /// 日志格式 / Log format string. - /// 日志参数 / Log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T arg) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志参数 6 的类型 / The type of the sixth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - /// 日志参数 6 / The sixth log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// - /// Logs a debug level message, used for recording debugging information. - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志参数 6 的类型 / The type of the sixth log argument. - /// 日志参数 7 的类型 / The type of the seventh log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - /// 日志参数 6 / The sixth log argument. - /// 日志参数 7 / The seventh log argument. - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - [Preserve] // 添加 Preserve 标签 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); - } - - /// - /// 打印调试级别日志,用于记录调试类日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志参数 16 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - /// 日志参数 16。 - public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Debug, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// - /// Logs an info level message, used for recording normal program execution information. - /// - /// 日志内容 / Log message content. - public static void Info(object message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, message); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// - /// Logs an info level message, used for recording normal program execution information. - /// - /// 日志内容 / Log message content. - public static void Info(string message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, message); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// - /// Logs an info level message, used for recording normal program execution information. - /// - /// 日志参数的类型 / The type of the log argument. - /// 日志格式 / Log format string. - /// 日志参数 / Log argument. - public static void Info(string format, T arg) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - public static void Info(string format, T1 arg1, T2 arg2) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志参数 6 的类型 / The type of the sixth log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - /// 日志参数 6 / The sixth log argument. - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型 / The type of the first log argument. - /// 日志参数 2 的类型 / The type of the second log argument. - /// 日志参数 3 的类型 / The type of the third log argument. - /// 日志参数 4 的类型 / The type of the fourth log argument. - /// 日志参数 5 的类型 / The type of the fifth log argument. - /// 日志参数 6 的类型 / The type of the sixth log argument. - /// 日志参数 7 的类型 / The type of the seventh log argument. - /// 日志格式 / Log format string. - /// 日志参数 1 / The first log argument. - /// 日志参数 2 / The second log argument. - /// 日志参数 3 / The third log argument. - /// 日志参数 4 / The fourth log argument. - /// 日志参数 5 / The fifth log argument. - /// 日志参数 6 / The sixth log argument. - /// 日志参数 7 / The seventh log argument. - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); - } - - /// - /// 打印信息级别日志,用于记录程序正常运行日志信息。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志参数 16 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - /// 日志参数 16。 - public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Info, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志内容。 - public static void Warning(object message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, message); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志内容。 - public static void Warning(string message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, message); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数的类型。 - /// 日志格式。 - /// 日志参数。 - public static void Warning(string format, T arg) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - public static void Warning(string format, T1 arg1, T2 arg2) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); - } - - /// - /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志参数 16 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - /// 日志参数 16。 - public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Warning, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志内容。 - public static void Error(object message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, message); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志内容。 - public static void Error(string message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, message); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数的类型。 - /// 日志格式。 - /// 日志参数。 - public static void Error(string format, T arg) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - public static void Error(string format, T1 arg1, T2 arg2) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); - } - - /// - /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志参数 16 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - /// 日志参数 16。 - public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Error, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志内容。 - public static void Fatal(object message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, message); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志内容。 - public static void Fatal(string message) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, message); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数的类型。 - /// 日志格式。 - /// 日志参数。 - public static void Fatal(string format, T arg) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - public static void Fatal(string format, T1 arg1, T2 arg2) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); - } - - /// - /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 - /// - /// 日志参数 1 的类型。 - /// 日志参数 2 的类型。 - /// 日志参数 3 的类型。 - /// 日志参数 4 的类型。 - /// 日志参数 5 的类型。 - /// 日志参数 6 的类型。 - /// 日志参数 7 的类型。 - /// 日志参数 8 的类型。 - /// 日志参数 9 的类型。 - /// 日志参数 10 的类型。 - /// 日志参数 11 的类型。 - /// 日志参数 12 的类型。 - /// 日志参数 13 的类型。 - /// 日志参数 14 的类型。 - /// 日志参数 15 的类型。 - /// 日志参数 16 的类型。 - /// 日志格式。 - /// 日志参数 1。 - /// 日志参数 2。 - /// 日志参数 3。 - /// 日志参数 4。 - /// 日志参数 5。 - /// 日志参数 6。 - /// 日志参数 7。 - /// 日志参数 8。 - /// 日志参数 9。 - /// 日志参数 10。 - /// 日志参数 11。 - /// 日志参数 12。 - /// 日志参数 13。 - /// 日志参数 14。 - /// 日志参数 15。 - /// 日志参数 16。 - public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (_logHelper == null) - { - return; - } - - _logHelper.Log(GameFrameworkLogLevel.Fatal, Utility.Text.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); - } - } +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using UnityEngine.Scripting; // 确保引入命名空间 + +namespace GameFrameX.Runtime +{ + /// + /// 游戏框架日志类。 + /// + /// + /// Game framework log class. + /// Provides static methods for logging messages at different severity levels (Debug, Info, Warning, Error, Fatal). + /// Requires an ILogHelper implementation to be set via SetLogHelper before logging can occur. + /// + public static partial class GameFrameworkLog + { + private static ILogHelper _logHelper = null; + + /// + /// 设置游戏框架日志辅助器。 + /// + /// + /// Sets the game framework log helper. + /// The log helper is responsible for the actual log output implementation. + /// + /// 要设置的游戏框架日志辅助器 / The log helper to set. + [Preserve] // 添加 Preserve 标签 + public static void SetLogHelper(ILogHelper logHelper) + { + _logHelper = logHelper; + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志内容 / Log message content. + [Preserve] // 添加 Preserve 标签 + public static void Debug(object message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, message); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志内容 / Log message content. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, message); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数的类型 / The type of the log argument. + /// 日志格式 / Log format string. + /// 日志参数 / Log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T arg) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志参数 6 的类型 / The type of the sixth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + /// 日志参数 6 / The sixth log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// + /// Logs a debug level message, used for recording debugging information. + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志参数 6 的类型 / The type of the sixth log argument. + /// 日志参数 7 的类型 / The type of the seventh log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + /// 日志参数 6 / The sixth log argument. + /// 日志参数 7 / The seventh log argument. + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + [Preserve] // 添加 Preserve 标签 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); + } + + /// + /// 打印调试级别日志,用于记录调试类日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志参数 16 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + /// 日志参数 16。 + public static void Debug(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Debug, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// + /// Logs an info level message, used for recording normal program execution information. + /// + /// 日志内容 / Log message content. + public static void Info(object message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, message); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// + /// Logs an info level message, used for recording normal program execution information. + /// + /// 日志内容 / Log message content. + public static void Info(string message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, message); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// + /// Logs an info level message, used for recording normal program execution information. + /// + /// 日志参数的类型 / The type of the log argument. + /// 日志格式 / Log format string. + /// 日志参数 / Log argument. + public static void Info(string format, T arg) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + public static void Info(string format, T1 arg1, T2 arg2) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志参数 6 的类型 / The type of the sixth log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + /// 日志参数 6 / The sixth log argument. + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型 / The type of the first log argument. + /// 日志参数 2 的类型 / The type of the second log argument. + /// 日志参数 3 的类型 / The type of the third log argument. + /// 日志参数 4 的类型 / The type of the fourth log argument. + /// 日志参数 5 的类型 / The type of the fifth log argument. + /// 日志参数 6 的类型 / The type of the sixth log argument. + /// 日志参数 7 的类型 / The type of the seventh log argument. + /// 日志格式 / Log format string. + /// 日志参数 1 / The first log argument. + /// 日志参数 2 / The second log argument. + /// 日志参数 3 / The third log argument. + /// 日志参数 4 / The fourth log argument. + /// 日志参数 5 / The fifth log argument. + /// 日志参数 6 / The sixth log argument. + /// 日志参数 7 / The seventh log argument. + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); + } + + /// + /// 打印信息级别日志,用于记录程序正常运行日志信息。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志参数 16 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + /// 日志参数 16。 + public static void Info(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Info, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志内容。 + public static void Warning(object message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, message); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志内容。 + public static void Warning(string message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, message); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数的类型。 + /// 日志格式。 + /// 日志参数。 + public static void Warning(string format, T arg) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + public static void Warning(string format, T1 arg1, T2 arg2) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); + } + + /// + /// 打印警告级别日志,建议在发生局部功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志参数 16 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + /// 日志参数 16。 + public static void Warning(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Warning, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志内容。 + public static void Error(object message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, message); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志内容。 + public static void Error(string message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, message); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数的类型。 + /// 日志格式。 + /// 日志参数。 + public static void Error(string format, T arg) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + public static void Error(string format, T1 arg1, T2 arg2) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); + } + + /// + /// 打印错误级别日志,建议在发生功能逻辑错误,但尚不会导致游戏崩溃或异常时使用。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志参数 16 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + /// 日志参数 16。 + public static void Error(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Error, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志内容。 + public static void Fatal(object message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, message); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志内容。 + public static void Fatal(string message) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, message); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数的类型。 + /// 日志格式。 + /// 日志参数。 + public static void Fatal(string format, T arg) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + public static void Fatal(string format, T1 arg1, T2 arg2) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)); + } + + /// + /// 打印严重错误级别日志,建议在发生严重错误,可能导致游戏崩溃或异常时使用,此时应尝试重启进程或重建游戏框架。 + /// + /// 日志参数 1 的类型。 + /// 日志参数 2 的类型。 + /// 日志参数 3 的类型。 + /// 日志参数 4 的类型。 + /// 日志参数 5 的类型。 + /// 日志参数 6 的类型。 + /// 日志参数 7 的类型。 + /// 日志参数 8 的类型。 + /// 日志参数 9 的类型。 + /// 日志参数 10 的类型。 + /// 日志参数 11 的类型。 + /// 日志参数 12 的类型。 + /// 日志参数 13 的类型。 + /// 日志参数 14 的类型。 + /// 日志参数 15 的类型。 + /// 日志参数 16 的类型。 + /// 日志格式。 + /// 日志参数 1。 + /// 日志参数 2。 + /// 日志参数 3。 + /// 日志参数 4。 + /// 日志参数 5。 + /// 日志参数 6。 + /// 日志参数 7。 + /// 日志参数 8。 + /// 日志参数 9。 + /// 日志参数 10。 + /// 日志参数 11。 + /// 日志参数 12。 + /// 日志参数 13。 + /// 日志参数 14。 + /// 日志参数 15。 + /// 日志参数 16。 + public static void Fatal(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (_logHelper == null) + { + return; + } + + _logHelper.Log(GameFrameworkLogLevel.Fatal, GameFrameworkText.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16)); + } + } } \ No newline at end of file diff --git a/Runtime/Base/Log/GameFrameworkLog.cs.meta b/Runtime/Helper/Log/GameFrameworkLog.cs.meta similarity index 100% rename from Runtime/Base/Log/GameFrameworkLog.cs.meta rename to Runtime/Helper/Log/GameFrameworkLog.cs.meta diff --git a/Runtime/Base/Log/GameFrameworkLogLevel.cs b/Runtime/Helper/Log/GameFrameworkLogLevel.cs similarity index 100% rename from Runtime/Base/Log/GameFrameworkLogLevel.cs rename to Runtime/Helper/Log/GameFrameworkLogLevel.cs diff --git a/Runtime/Base/Log/GameFrameworkLogLevel.cs.meta b/Runtime/Helper/Log/GameFrameworkLogLevel.cs.meta similarity index 100% rename from Runtime/Base/Log/GameFrameworkLogLevel.cs.meta rename to Runtime/Helper/Log/GameFrameworkLogLevel.cs.meta diff --git a/Runtime/Helper/NetworkHelper.cs b/Runtime/Helper/NetworkHelper.cs deleted file mode 100644 index 5a92cf7..0000000 --- a/Runtime/Helper/NetworkHelper.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Collections.Generic; -using System.Net; -using UnityEngine; - -namespace GameFrameX.Runtime -{ - /// - /// 网络帮助类。 - /// - /// - /// Network helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class NetworkHelper - { - /// - /// 获取本地的IP列表。 - /// - /// - /// Gets the local IP address list. - /// - /// 本地IP地址数组 / Array of local IP addresses - [UnityEngine.Scripting.Preserve] - public static string[] GetAddressIPs() - { - //获取本地的IP地址 - var list = Dns.GetHostEntry(Dns.GetHostName()).AddressList; - string[] addressIPs = new string[list.Length]; - for (var index = 0; index < list.Length; index++) - { - IPAddress address = list[index]; - addressIPs[index] = address.ToString(); - } - - return addressIPs; - } - - /// - /// 获取当前是否有网络连接。 - /// - /// - /// Gets whether the device has network connectivity. - /// - /// 如果有网络连接则为 true;否则为 false / true if network is reachable; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool IsReachable() - { - return Application.internetReachability != NetworkReachability.NotReachable; - } - - /// - /// 获取当前是否通过WiFi连接网络。 - /// - /// - /// Gets whether the device is connected via WiFi (local area network). - /// - /// 如果是WiFi连接则为 true;否则为 false / true if on WiFi; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool IsWifi() - { - return Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork; - } - - /// - /// 获取当前是否通过移动数据网络连接。 - /// - /// - /// Gets whether the device is connected via cellular data network. - /// - /// 如果是移动网络则为 true;否则为 false / true if on cellular data; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool IsViaCarrierData() - { - //当用户使用移动网络时 - return Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork; - } - } -} \ No newline at end of file diff --git a/Runtime/Helper/ObjectHelper.cs b/Runtime/Helper/ObjectHelper.cs deleted file mode 100644 index 8480289..0000000 --- a/Runtime/Helper/ObjectHelper.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace GameFrameX.Runtime -{ - /// - /// 对象帮助类。 - /// - /// - /// Object helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class ObjectHelper - { - /// - /// 交换两个变量的值。 - /// - /// - /// Swaps the values of two variables. - /// - /// 变量类型 / Variable type - /// 第一个变量 / First variable - /// 第二个变量 / Second variable - [UnityEngine.Scripting.Preserve] - public static void Swap(ref T t1, ref T t2) - { - (t1, t2) = (t2, t1); - } - } -} \ No newline at end of file diff --git a/Runtime/Helper/PathHelper.cs b/Runtime/Helper/PathHelper.cs deleted file mode 100644 index 90048f9..0000000 --- a/Runtime/Helper/PathHelper.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Text; -using UnityEngine; - -namespace GameFrameX.Runtime -{ - /// - /// 路径帮助类。 - /// - /// - /// Path helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class PathHelper - { - /// - /// 应用程序外部资源路径存放路径(热更新资源路径)。 - /// - /// - /// Application external resource path (hot update resource path). - /// - [UnityEngine.Scripting.Preserve] - public static string AppHotfixResPath - { - get - { - string game = Application.productName; - string path = $"{Application.persistentDataPath}/{game}/"; - return path; - } - } - - /// - /// 应用程序内部资源路径存放路径 - /// - [UnityEngine.Scripting.Preserve] - public static string AppResPath - { - get { return NormalizePath(Application.streamingAssetsPath); } - } - - /// - /// 应用程序内部资源路径存放路径(www/webrequest专用) - /// - [UnityEngine.Scripting.Preserve] - public static string AppResPath4Web - { - get - { -#if UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_EDITOR - return $"file://{Application.streamingAssetsPath}"; -#else - return NormalizePath(Application.streamingAssetsPath); -#endif - } - } - - /// - /// 获取平台名称 - /// - /// - /// 此属性已废弃,请使用 ApplicationHelper.PlatformName 替代 - /// - [UnityEngine.Scripting.Preserve] - [Obsolete("此方法已废弃,请使用 ApplicationHelper.PlatformName 替代")] - public static string GetPlatformName - { - get - { -#if UNITY_ANDROID - return $"Android"; -#elif UNITY_STANDALONE_OSX - return $"MacOs"; -#elif UNITY_IOS || UNITY_IPHONE - return $"iOS"; -#elif UNITY_WEBGL - return $"WebGL"; -#elif UNITY_STANDALONE_WIN - return $"Windows"; -#else - return string.Empty; -#endif - } - } - - /// - /// 规范化路径 - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static string NormalizePath(string path) - { - return path.Replace('\\', '/').Replace("\\", "/"); - } - - - /// - /// 拼接路径 - /// - /// - /// - [UnityEngine.Scripting.Preserve] - public static string Combine(params string[] paths) - { - var sb = new StringBuilder(); - const string separatorA = "/"; - const string separatorB = "\\"; - for (var index = 0; index < paths.Length - 1; index++) - { - var path = paths[index]; - sb.Append(path); - if (path.EndsWithFast(separatorA) || path.EndsWithFast(separatorB)) - { - continue; - } - - if (path.StartsWithFast(separatorA) || path.StartsWithFast(separatorB)) - { - continue; - } - - sb.Append(separatorA); - } - - sb.Append(paths[paths.Length - 1]); - return sb.ToString(); - } - } -} \ No newline at end of file diff --git a/Runtime/Helper/PathHelper.cs.meta b/Runtime/Helper/PathHelper.cs.meta deleted file mode 100644 index d6c97e0..0000000 --- a/Runtime/Helper/PathHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e0a953f351663154fb667b0bea10bf3d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Helper/RandomHelper.cs b/Runtime/Helper/RandomHelper.cs deleted file mode 100644 index 1ab75c4..0000000 --- a/Runtime/Helper/RandomHelper.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; - -namespace GameFrameX.Runtime -{ - /// - /// 随机数帮助类。 - /// - /// - /// Random number helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class RandomHelper - { - /// - /// 设置随机种子。 - /// - /// - /// Sets the random seed for the random number generator. - /// - /// 随机种子值 / Random seed value - [UnityEngine.Scripting.Preserve] - public static void SetSeed(int seed) - { - ThreadLocalRandom.SetSeed(seed); - } - - /// - /// 获取UInt64范围内的随机数。 - /// - /// - /// Gets a random number within the UInt64 range. - /// - /// 返回一个随机的UInt64值 / A random UInt64 value - [UnityEngine.Scripting.Preserve] - public static ulong NextUInt64() - { - return ThreadLocalRandom.NextUInt64(); - } - - /// - /// 获取Int64范围内的随机数。 - /// - /// - /// Gets a random number within the Int64 range. - /// - /// 返回一个随机的Int64值 / A random Int64 value - [UnityEngine.Scripting.Preserve] - public static long NextInt64() - { - return ThreadLocalRandom.NextInt64(); - } - - /// - /// 获取指定范围内的随机整数。 - /// - /// - /// Gets a random integer within the specified range. - /// - /// 下限(包含)/ Lower bound (inclusive) - /// 上限(不包含)/ Upper bound (exclusive) - /// 返回一个在指定范围内的随机整数 / A random integer within the specified range - [UnityEngine.Scripting.Preserve] - public static int Next(int lower, int upper) - { - return ThreadLocalRandom.Current.Next(lower, upper); - } - - /// - /// 获取0与1之间的随机浮点数。 - /// - /// - /// Gets a random float between 0 and 1. - /// - /// 返回一个在0到1之间的随机浮点数 / A random float between 0 and 1 - [UnityEngine.Scripting.Preserve] - public static float Next() - { - return (float)ThreadLocalRandom.Current.NextDouble(); - } - } -} \ No newline at end of file diff --git a/Runtime/Helper/RandomHelper.cs.meta b/Runtime/Helper/RandomHelper.cs.meta deleted file mode 100644 index 6c8902c..0000000 --- a/Runtime/Helper/RandomHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: be03ec635e437ff4493f9acd61a05c90 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Helper/Text.meta b/Runtime/Helper/Text.meta new file mode 100644 index 0000000..954c765 --- /dev/null +++ b/Runtime/Helper/Text.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f43bf2faafc84cb0af256b931ca90f47 +timeCreated: 1787477000 \ No newline at end of file diff --git a/Runtime/Utility/Utility.Text.cs b/Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs similarity index 67% rename from Runtime/Utility/Utility.Text.cs rename to Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs index b7ec116..cf88c07 100644 --- a/Runtime/Utility/Utility.Text.cs +++ b/Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs @@ -1,17 +1,17 @@ -// ========================================================================================== +// ========================================================================================== // GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 // GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights // 均受中华人民共和国及相关国际法律法规保护。 // are protected by the laws of the People's Republic of China and relevant international regulations. -// +// // 使用本项目须严格遵守相应法律法规及开源许可证之规定。 // Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// +// // 本项目采用 Apache License 2.0 许可证分发, // This project is licensed under the Apache License 2.0, // 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 // please refer to the LICENSE file in the root directory of the source code for the full license text. -// +// // 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 // It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, // 侵犯他人合法权益等法律法规所禁止的行为! @@ -20,7 +20,7 @@ // Any legal disputes and liabilities arising from secondary development based on this project // 本项目组织与贡献者概不承担。 // shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// +// // GitHub 仓库:https://github.com/GameFrameX // GitHub Repository: https://github.com/GameFrameX // Gitee 仓库:https://gitee.com/GameFrameX @@ -33,54 +33,17 @@ namespace GameFrameX.Runtime { - public static partial class Utility + public static partial class GameFrameworkText { - /// - /// 字符相关的实用函数。 - /// - /// - /// Text related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static partial class Text + public interface ITextHelper { - private static ITextHelper s_TextHelper = null; - - /// - /// 设置字符辅助器。 - /// - /// - /// Sets the text helper. - /// - /// 要设置的字符辅助器 / The text helper to set - [UnityEngine.Scripting.Preserve] - public static void SetTextHelper(ITextHelper textHelper) - { - s_TextHelper = textHelper; - } - /// /// 获取格式化字符串。 /// - /// 字符串参数的类型。 /// 字符串格式。 /// 参数列表。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, params object[] args) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, args); - } - - return s_TextHelper.Format(format, args); - } + string Format(string format, params object[] args); /// /// 获取格式化字符串。 @@ -89,21 +52,7 @@ public static string Format(string format, params object[] args) /// 字符串格式。 /// 字符串参数。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T arg) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg); - } - - return s_TextHelper.Format(format, arg); - } + string Format(string format, T arg); /// /// 获取格式化字符串。 @@ -114,21 +63,7 @@ public static string Format(string format, T arg) /// 字符串参数 1。 /// 字符串参数 2。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2); - } - - return s_TextHelper.Format(format, arg1, arg2); - } + string Format(string format, T1 arg1, T2 arg2); /// /// 获取格式化字符串。 @@ -141,21 +76,7 @@ public static string Format(string format, T1 arg1, T2 arg2) /// 字符串参数 2。 /// 字符串参数 3。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3); /// /// 获取格式化字符串。 @@ -170,21 +91,7 @@ public static string Format(string format, T1 arg1, T2 arg2, T3 arg3 /// 字符串参数 3。 /// 字符串参数 4。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4); /// /// 获取格式化字符串。 @@ -201,21 +108,7 @@ public static string Format(string format, T1 arg1, T2 arg2, T3 /// 字符串参数 4。 /// 字符串参数 5。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); /// /// 获取格式化字符串。 @@ -234,21 +127,7 @@ public static string Format(string format, T1 arg1, T2 arg2, /// 字符串参数 5。 /// 字符串参数 6。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); /// /// 获取格式化字符串。 @@ -269,21 +148,7 @@ public static string Format(string format, T1 arg1, T2 a /// 字符串参数 6。 /// 字符串参数 7。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); /// /// 获取格式化字符串。 @@ -306,21 +171,7 @@ public static string Format(string format, T1 arg1, /// 字符串参数 7。 /// 字符串参数 8。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); /// /// 获取格式化字符串。 @@ -345,21 +196,7 @@ public static string Format(string format, T1 ar /// 字符串参数 8。 /// 字符串参数 9。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); /// /// 获取格式化字符串。 @@ -386,21 +223,7 @@ public static string Format(string format, T /// 字符串参数 9。 /// 字符串参数 10。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); /// /// 获取格式化字符串。 @@ -429,21 +252,7 @@ public static string Format(string form /// 字符串参数 10。 /// 字符串参数 11。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); /// /// 获取格式化字符串。 @@ -474,21 +283,7 @@ public static string Format(string /// 字符串参数 11。 /// 字符串参数 12。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); /// /// 获取格式化字符串。 @@ -521,21 +316,7 @@ public static string Format(s /// 字符串参数 12。 /// 字符串参数 13。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); /// /// 获取格式化字符串。 @@ -570,21 +351,7 @@ public static string Format字符串参数 13。 /// 字符串参数 14。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); /// /// 获取格式化字符串。 @@ -621,21 +388,7 @@ public static string Format字符串参数 14。 /// 字符串参数 15。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); /// /// 获取格式化字符串。 @@ -674,21 +427,7 @@ public static string Format字符串参数 15。 /// 字符串参数 16。 /// 格式化后的字符串。 - [UnityEngine.Scripting.Preserve] - public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - if (format == null) - { - throw new GameFrameworkException("Format is invalid."); - } - - if (s_TextHelper == null) - { - return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); - } - - return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); - } + string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); } } } \ No newline at end of file diff --git a/Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs.meta b/Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs.meta new file mode 100644 index 0000000..e403264 --- /dev/null +++ b/Runtime/Helper/Text/GameFrameworkText.ITextHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d3acafe5ebba4d5da4efa56c1dd14359 +timeCreated: 1787479017 \ No newline at end of file diff --git a/Runtime/Helper/Text/GameFrameworkText.cs b/Runtime/Helper/Text/GameFrameworkText.cs new file mode 100644 index 0000000..1871775 --- /dev/null +++ b/Runtime/Helper/Text/GameFrameworkText.cs @@ -0,0 +1,684 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +namespace GameFrameX.Runtime +{ + public static partial class GameFrameworkText + { + private static ITextHelper s_TextHelper = null; + + /// + /// 设置字符辅助器。 + /// + /// + /// Sets the text helper. + /// + /// 要设置的字符辅助器 / The text helper to set + [UnityEngine.Scripting.Preserve] + public static void SetTextHelper(ITextHelper textHelper) + { + s_TextHelper = textHelper; + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数的类型。 + /// 字符串格式。 + /// 参数列表。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, params object[] args) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, args); + } + + return s_TextHelper.Format(format, args); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数的类型。 + /// 字符串格式。 + /// 字符串参数。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T arg) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg); + } + + return s_TextHelper.Format(format, arg); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2); + } + + return s_TextHelper.Format(format, arg1, arg2); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串参数 12 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 字符串参数 12。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串参数 12 的类型。 + /// 字符串参数 13 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 字符串参数 12。 + /// 字符串参数 13。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串参数 12 的类型。 + /// 字符串参数 13 的类型。 + /// 字符串参数 14 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 字符串参数 12。 + /// 字符串参数 13。 + /// 字符串参数 14。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串参数 12 的类型。 + /// 字符串参数 13 的类型。 + /// 字符串参数 14 的类型。 + /// 字符串参数 15 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 字符串参数 12。 + /// 字符串参数 13。 + /// 字符串参数 14。 + /// 字符串参数 15。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串参数 12 的类型。 + /// 字符串参数 13 的类型。 + /// 字符串参数 14 的类型。 + /// 字符串参数 15 的类型。 + /// 字符串参数 16 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 字符串参数 12。 + /// 字符串参数 13。 + /// 字符串参数 14。 + /// 字符串参数 15。 + /// 字符串参数 16。 + /// 格式化后的字符串。 + [UnityEngine.Scripting.Preserve] + public static string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + if (s_TextHelper == null) + { + return string.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + return s_TextHelper.Format(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/Text/GameFrameworkText.cs.meta b/Runtime/Helper/Text/GameFrameworkText.cs.meta new file mode 100644 index 0000000..8718c10 --- /dev/null +++ b/Runtime/Helper/Text/GameFrameworkText.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 69f66a0177404027a3a1ebf63ec7b882 +timeCreated: 1787478985 \ No newline at end of file diff --git a/Runtime/ObjectPool/ObjectBase.cs b/Runtime/ObjectPool/ObjectBase.cs index 83d6d96..61b4a9c 100644 --- a/Runtime/ObjectPool/ObjectBase.cs +++ b/Runtime/ObjectPool/ObjectBase.cs @@ -177,7 +177,7 @@ protected void Initialize(string name, object target, bool locked, int priority) { if (target == null) { - throw new GameFrameworkException(Utility.Text.Format("Target '{0}' is invalid.", name)); + throw new GameFrameworkException(GameFrameworkText.Format("Target '{0}' is invalid.", name)); } m_Name = name ?? string.Empty; diff --git a/Runtime/ObjectPool/ObjectPoolManager.Object.cs b/Runtime/ObjectPool/ObjectPoolManager.Object.cs index 76e2080..f947ce4 100644 --- a/Runtime/ObjectPool/ObjectPoolManager.Object.cs +++ b/Runtime/ObjectPool/ObjectPoolManager.Object.cs @@ -240,7 +240,7 @@ public void Unspawn() m_SpawnCount--; if (m_SpawnCount < 0) { - throw new GameFrameworkException(Utility.Text.Format("Object '{0}' spawn count is less than 0.", Name)); + throw new GameFrameworkException(GameFrameworkText.Format("Object '{0}' spawn count is less than 0.", Name)); } } diff --git a/Runtime/ObjectPool/ObjectPoolManager.ObjectPool.cs b/Runtime/ObjectPool/ObjectPoolManager.ObjectPool.cs index 119e03a..76a4911 100644 --- a/Runtime/ObjectPool/ObjectPoolManager.ObjectPool.cs +++ b/Runtime/ObjectPool/ObjectPoolManager.ObjectPool.cs @@ -331,7 +331,7 @@ public void Unspawn(object target) } else { - throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); + throw new GameFrameworkException(GameFrameworkText.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); } } @@ -371,7 +371,7 @@ public void SetLocked(object target, bool locked) } else { - throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); + throw new GameFrameworkException(GameFrameworkText.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); } } @@ -411,7 +411,7 @@ public void SetPriority(object target, int priority) } else { - throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); + throw new GameFrameworkException(GameFrameworkText.Format("Can not find target in object pool '{0}', target type is '{1}', target value is '{2}'.", new TypeNamePair(typeof(T), Name), target.GetType().FullName, target)); } } diff --git a/Runtime/ObjectPool/ObjectPoolManager.cs b/Runtime/ObjectPool/ObjectPoolManager.cs index 50a9115..01bf1d4 100644 --- a/Runtime/ObjectPool/ObjectPoolManager.cs +++ b/Runtime/ObjectPool/ObjectPoolManager.cs @@ -136,7 +136,7 @@ public bool HasObjectPool(Type objectType) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalHasObjectPool(new TypeNamePair(objectType)); @@ -170,7 +170,7 @@ public bool HasObjectPool(Type objectType, string name) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalHasObjectPool(new TypeNamePair(objectType, name)); @@ -226,7 +226,7 @@ public ObjectPoolBase GetObjectPool(Type objectType) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalGetObjectPool(new TypeNamePair(objectType)); @@ -260,7 +260,7 @@ public ObjectPoolBase GetObjectPool(Type objectType, string name) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalGetObjectPool(new TypeNamePair(objectType, name)); @@ -1242,7 +1242,7 @@ public bool DestroyObjectPool(Type objectType) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalDestroyObjectPool(new TypeNamePair(objectType)); @@ -1276,7 +1276,7 @@ public bool DestroyObjectPool(Type objectType, string name) if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } return InternalDestroyObjectPool(new TypeNamePair(objectType, name)); @@ -1362,7 +1362,7 @@ private IObjectPool InternalCreateObjectPool(string name, bool allowMultiS TypeNamePair typeNamePair = new TypeNamePair(typeof(T), name); if (HasObjectPool(name)) { - throw new GameFrameworkException(Utility.Text.Format("Already exist object pool '{0}'.", typeNamePair)); + throw new GameFrameworkException(GameFrameworkText.Format("Already exist object pool '{0}'.", typeNamePair)); } ObjectPool objectPool = new ObjectPool(name, allowMultiSpawn, autoReleaseInterval, capacity, expireTime, priority); @@ -1379,13 +1379,13 @@ private ObjectPoolBase InternalCreateObjectPool(Type objectType, string name, bo if (!typeof(ObjectBase).IsAssignableFrom(objectType)) { - throw new GameFrameworkException(Utility.Text.Format("Object type '{0}' is invalid.", objectType.FullName)); + throw new GameFrameworkException(GameFrameworkText.Format("Object type '{0}' is invalid.", objectType.FullName)); } TypeNamePair typeNamePair = new TypeNamePair(objectType, name); if (HasObjectPool(objectType, name)) { - throw new GameFrameworkException(Utility.Text.Format("Already exist object pool '{0}'.", typeNamePair)); + throw new GameFrameworkException(GameFrameworkText.Format("Already exist object pool '{0}'.", typeNamePair)); } Type objectPoolType = typeof(ObjectPool<>).MakeGenericType(objectType); diff --git a/Runtime/RuntimeHost/GameFrameXRuntimeHost.cs b/Runtime/RuntimeHost/GameFrameXRuntimeHost.cs index 1ee8c73..c45df38 100644 --- a/Runtime/RuntimeHost/GameFrameXRuntimeHost.cs +++ b/Runtime/RuntimeHost/GameFrameXRuntimeHost.cs @@ -104,8 +104,8 @@ public static void EnsureStarted(GameFrameXRuntimeModeResult modeResult) GameFrameXRuntimeManagerResolver.RegisterOverrides(overrideContext.GetManagerOverrides()); s_LastPlan = GameFrameXRuntimePlanner.CreatePlan(scanResult, overrideContext); - s_LastPlan.Diagnostics.Add(Utility.Text.Format("Runtime mode: {0}. Reason: {1}.", s_LastModeResult.Mode, s_LastModeResult.Reason)); - s_LastPlan.Diagnostics.Add(Utility.Text.Format( + s_LastPlan.Diagnostics.Add(GameFrameworkText.Format("Runtime mode: {0}. Reason: {1}.", s_LastModeResult.Mode, s_LastModeResult.Reason)); + s_LastPlan.Diagnostics.Add(GameFrameworkText.Format( "Scan result: {0} component(s), {1} manager implementation(s), {2} manager override(s).", scanResult.ComponentTypes.Count, scanResult.ManagerDescriptors.Count, @@ -121,7 +121,7 @@ public static void EnsureStarted(GameFrameXRuntimeModeResult modeResult) s_Host.SetActive(true); s_Started = true; - s_LastPlan.Diagnostics.Add(Utility.Text.Format("Startup elapsed: {0} ms.", stopwatch.ElapsedMilliseconds)); + s_LastPlan.Diagnostics.Add(GameFrameworkText.Format("Startup elapsed: {0} ms.", stopwatch.ElapsedMilliseconds)); WriteDiagnostics(); } @@ -137,7 +137,7 @@ public static void RecordManualSceneMode(GameFrameXRuntimeModeResult modeResult) string.Empty); s_Started = true; s_LastPlan = new GameFrameXRuntimePlan(); - s_LastPlan.Diagnostics.Add(Utility.Text.Format("Runtime mode: {0}. Reason: {1}. Manual entry: {2}.", + s_LastPlan.Diagnostics.Add(GameFrameworkText.Format("Runtime mode: {0}. Reason: {1}. Manual entry: {2}.", s_LastModeResult.Mode, s_LastModeResult.Reason, string.IsNullOrEmpty(s_LastModeResult.ManualEntryPath) ? "unknown" : s_LastModeResult.ManualEntryPath)); @@ -219,11 +219,11 @@ private static void WriteDiagnostics() } else { - Debug.Log(Utility.Text.Format("GameFrameX auto runtime started. Components: {0}.", s_LastPlan.Components.Count)); + Debug.Log(GameFrameworkText.Format("GameFrameX auto runtime started. Components: {0}.", s_LastPlan.Components.Count)); } foreach (var component in s_LastPlan.Components) { - Debug.Log(Utility.Text.Format( + Debug.Log(GameFrameworkText.Format( "GameFrameX auto runtime enabled component: {0}, node: {1}/{2}, order: {3}.", component.ComponentType.FullName, HostName, @@ -233,8 +233,8 @@ private static void WriteDiagnostics() foreach (var diagnostic in s_LastPlan.Diagnostics) { - Debug.LogWarning(Utility.Text.Format("GameFrameX auto runtime: {0}", diagnostic)); + Debug.LogWarning(GameFrameworkText.Format("GameFrameX auto runtime: {0}", diagnostic)); } } } -} +} \ No newline at end of file diff --git a/Runtime/RuntimeHost/GameFrameXRuntimeManagerResolver.cs b/Runtime/RuntimeHost/GameFrameXRuntimeManagerResolver.cs index 77ceab1..2524b64 100644 --- a/Runtime/RuntimeHost/GameFrameXRuntimeManagerResolver.cs +++ b/Runtime/RuntimeHost/GameFrameXRuntimeManagerResolver.cs @@ -76,7 +76,7 @@ public static void RegisterOverrides(IEnumerable {1}.", interfaceType.FullName, configuredType.FullName)); @@ -134,7 +134,7 @@ public static Type Resolve(Type interfaceType, string configuredTypeName) if (ManagerOverrides.TryGetValue(interfaceType, out var managerOverride)) { - UnityEngine.Debug.Log(Utility.Text.Format( + UnityEngine.Debug.Log(GameFrameworkText.Format( "GameFrameX auto runtime manager selected by runtime override: {0} -> {1}.", interfaceType.FullName, managerOverride.ImplementationType.FullName)); @@ -148,14 +148,14 @@ public static Type Resolve(Type interfaceType, string configuredTypeName) descriptors.Sort(CompareManagerDescriptor); if (descriptors.Count > 1) { - UnityEngine.Debug.LogWarning(Utility.Text.Format( + UnityEngine.Debug.LogWarning(GameFrameworkText.Format( "GameFrameX auto runtime manager conflict for interface '{0}'. Selected '{1}' by priority.", interfaceType.FullName, descriptors[0].ImplementationType.FullName)); } else { - UnityEngine.Debug.Log(Utility.Text.Format( + UnityEngine.Debug.Log(GameFrameworkText.Format( "GameFrameX auto runtime manager selected by scan: {0} -> {1}.", interfaceType.FullName, descriptors[0].ImplementationType.FullName)); @@ -166,11 +166,11 @@ public static Type Resolve(Type interfaceType, string configuredTypeName) if (interfaceType.Name.Length > 1 && interfaceType.Name[0] == 'I') { - string conventionName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); - Type conventionType = Utility.Assembly.GetType(conventionName); + string conventionName = GameFrameworkText.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1)); + Type conventionType = AssemblyUtility.GetType(conventionName); if (conventionType != null && interfaceType.IsAssignableFrom(conventionType)) { - UnityEngine.Debug.Log(Utility.Text.Format( + UnityEngine.Debug.Log(GameFrameworkText.Format( "GameFrameX auto runtime manager selected by naming convention: {0} -> {1}.", interfaceType.FullName, conventionType.FullName)); @@ -178,7 +178,7 @@ public static Type Resolve(Type interfaceType, string configuredTypeName) } } - UnityEngine.Debug.LogWarning(Utility.Text.Format( + UnityEngine.Debug.LogWarning(GameFrameworkText.Format( "GameFrameX auto runtime can not resolve manager for interface '{0}'.", interfaceType.FullName)); return null; @@ -206,4 +206,4 @@ private static int CompareManagerDescriptor(GameFrameXRuntimeManagerDescriptor x return string.Compare(x.ImplementationType.FullName, y.ImplementationType.FullName, StringComparison.Ordinal); } } -} +} \ No newline at end of file diff --git a/Runtime/RuntimeHost/GameFrameXRuntimePlanner.cs b/Runtime/RuntimeHost/GameFrameXRuntimePlanner.cs index 24e86b6..aee87b1 100644 --- a/Runtime/RuntimeHost/GameFrameXRuntimePlanner.cs +++ b/Runtime/RuntimeHost/GameFrameXRuntimePlanner.cs @@ -33,7 +33,7 @@ public static GameFrameXRuntimePlan CreatePlan(GameFrameXRuntimeScanResult scanR if (configs != null && configs.TryGetValue(componentType, out var config)) { ApplyConfig(descriptor, config); - plan.Diagnostics.Add(Utility.Text.Format( + plan.Diagnostics.Add(GameFrameworkText.Format( "Apply runtime override to component '{0}': enabled={1}, order={2}, manager={3}, valueCount={4}.", componentType.FullName, config.Enabled.HasValue ? config.Enabled.Value.ToString() : "default", @@ -44,7 +44,7 @@ public static GameFrameXRuntimePlan CreatePlan(GameFrameXRuntimeScanResult scanR if (!descriptor.Enabled) { - plan.Diagnostics.Add(Utility.Text.Format("Skip component '{0}' by runtime override.", componentType.FullName)); + plan.Diagnostics.Add(GameFrameworkText.Format("Skip component '{0}' by runtime override.", componentType.FullName)); continue; } @@ -199,4 +199,4 @@ private static int CompareComponentDescriptor(GameFrameXRuntimeComponentDescript return string.Compare(x.ComponentType.FullName, y.ComponentType.FullName, StringComparison.Ordinal); } } -} +} \ No newline at end of file diff --git a/Runtime/RuntimeHost/GameFrameXRuntimeScanner.cs b/Runtime/RuntimeHost/GameFrameXRuntimeScanner.cs index 214ebcf..fade02f 100644 --- a/Runtime/RuntimeHost/GameFrameXRuntimeScanner.cs +++ b/Runtime/RuntimeHost/GameFrameXRuntimeScanner.cs @@ -17,7 +17,7 @@ public static class GameFrameXRuntimeScanner public static GameFrameXRuntimeScanResult Scan() { var result = new GameFrameXRuntimeScanResult(); - var assemblies = Utility.Assembly.GetAssemblies(); + var assemblies = AssemblyUtility.GetAssemblies(); foreach (var assembly in assemblies) { if (assembly == null || ShouldSkipAssembly(assembly)) @@ -77,12 +77,12 @@ private static Type[] GetLoadableTypes(Assembly assembly, GameFrameXRuntimeScanR } catch (ReflectionTypeLoadException exception) { - result.Errors.Add(Utility.Text.Format("Assembly '{0}' contains unloaded types: {1}", assembly.FullName, exception.Message)); + result.Errors.Add(GameFrameworkText.Format("Assembly '{0}' contains unloaded types: {1}", assembly.FullName, exception.Message)); return exception.Types; } catch (Exception exception) { - result.Errors.Add(Utility.Text.Format("Can not scan assembly '{0}': {1}", assembly.FullName, exception.Message)); + result.Errors.Add(GameFrameworkText.Format("Can not scan assembly '{0}': {1}", assembly.FullName, exception.Message)); return Array.Empty(); } } @@ -122,4 +122,4 @@ private static bool IsValidManagerInterface(Type interfaceType, Type implementat interfaceType.IsAssignableFrom(implementationType); } } -} +} \ No newline at end of file diff --git a/Runtime/Helper/ApplicationHelper.MiniGame.cs b/Runtime/Utility/ApplicationUtility.MiniGame.cs similarity index 99% rename from Runtime/Helper/ApplicationHelper.MiniGame.cs rename to Runtime/Utility/ApplicationUtility.MiniGame.cs index 53b880f..a287ca7 100644 --- a/Runtime/Helper/ApplicationHelper.MiniGame.cs +++ b/Runtime/Utility/ApplicationUtility.MiniGame.cs @@ -1,6 +1,6 @@ namespace GameFrameX.Runtime { - public static partial class ApplicationHelper + public static partial class ApplicationUtility { /// /// 获取当前是否在WebGL小游戏平台运行。 diff --git a/Runtime/Helper/ApplicationHelper.MiniGame.cs.meta b/Runtime/Utility/ApplicationUtility.MiniGame.cs.meta similarity index 100% rename from Runtime/Helper/ApplicationHelper.MiniGame.cs.meta rename to Runtime/Utility/ApplicationUtility.MiniGame.cs.meta diff --git a/Runtime/Helper/ApplicationHelper.cs b/Runtime/Utility/ApplicationUtility.cs similarity index 99% rename from Runtime/Helper/ApplicationHelper.cs rename to Runtime/Utility/ApplicationUtility.cs index 83cde24..0f59ae9 100644 --- a/Runtime/Helper/ApplicationHelper.cs +++ b/Runtime/Utility/ApplicationUtility.cs @@ -9,7 +9,7 @@ namespace GameFrameX.Runtime /// Application helper class. /// [UnityEngine.Scripting.Preserve] - public static partial class ApplicationHelper + public static partial class ApplicationUtility { /// /// 获取当前是否在Unity编辑器中运行。 @@ -265,8 +265,9 @@ public static bool IsWindows { #if UNITY_STANDALONE_WIN return true; -#endif +#else return Application.platform == RuntimePlatform.WindowsPlayer; +#endif } } @@ -418,10 +419,11 @@ public static void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; - return; -#endif +#else Application.Quit(); +#endif } + #if UNITY_IOS [System.Runtime.InteropServices.DllImport("__Internal")] private static extern void open_url(string url); @@ -438,12 +440,12 @@ public static void OpenURL(string url) { #if UNITY_EDITOR Application.OpenURL(url); - return; -#endif +#else #if UNITY_IOS open_url(url); #else Application.OpenURL(url); +#endif #endif } @@ -490,4 +492,4 @@ public static void OpenRequestTrackingAuthorization() #endif } } -} +} \ No newline at end of file diff --git a/Runtime/Helper/ApplicationHelper.cs.meta b/Runtime/Utility/ApplicationUtility.cs.meta similarity index 100% rename from Runtime/Helper/ApplicationHelper.cs.meta rename to Runtime/Utility/ApplicationUtility.cs.meta diff --git a/Runtime/Utility/AssemblyUtility.cs b/Runtime/Utility/AssemblyUtility.cs new file mode 100644 index 0000000..fb442a2 --- /dev/null +++ b/Runtime/Utility/AssemblyUtility.cs @@ -0,0 +1,184 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.Collections.Generic; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + /// + /// 程序集相关的实用函数。 + /// + /// + /// Assembly related utility functions. + /// + public static class AssemblyUtility + { + private static readonly System.Reflection.Assembly[] Assemblies = null; + private static readonly Dictionary CachedTypes = new Dictionary(StringComparer.Ordinal); + private static readonly object Lock = new object(); + + static AssemblyUtility() + { + Assemblies = AppDomain.CurrentDomain.GetAssemblies(); + } + + /// + /// 获取已加载的程序集。 + /// + /// + /// Gets the loaded assemblies. + /// + /// 已加载的程序集 / The loaded assemblies + [Preserve] + public static System.Reflection.Assembly[] GetAssemblies() + { + return Assemblies; + } + + /// + /// 获取已加载的程序集中的所有类型。 + /// + /// + /// Gets all types in the loaded assemblies. + /// + /// 已加载的程序集中的所有类型 / All types in the loaded assemblies + [Preserve] + public static Type[] GetTypes() + { + var results = new List(256); + foreach (var assembly in Assemblies) + { + results.AddRange(assembly.GetTypes()); + } + + return results.ToArray(); + } + + /// + /// 获取已加载的程序集中的所有类型。 + /// + /// + /// Gets all types in the loaded assemblies. + /// + /// 已加载的程序集中的所有类型 / All types in the loaded assemblies + [Preserve] + public static void GetTypes(List results) + { + if (results == null) + { + throw new GameFrameworkException("Results is invalid."); + } + + results.Clear(); + foreach (var assembly in Assemblies) + { + results.AddRange(assembly.GetTypes()); + } + } + + /// + /// 获取已加载的程序集中的指定类型。 + /// + /// + /// Gets the specified type from the loaded assemblies. + /// + /// 要获取的类型名 / The type name to get + /// 已加载的程序集中的指定类型 / The specified type from the loaded assemblies + [Preserve] + public static Type GetType(string typeName) + { + if (string.IsNullOrEmpty(typeName)) + { + return null; + } + + lock (Lock) + { + if (CachedTypes.TryGetValue(typeName, out var type)) + { + return type; + } + + type = Type.GetType(typeName); + if (type != null) + { + CachedTypes.Add(typeName, type); + return type; + } + + foreach (System.Reflection.Assembly assembly in Assemblies) + { + type = Type.GetType(GameFrameworkText.Format("{0}, {1}", typeName, assembly.FullName)); + if (type != null) + { + CachedTypes.Add(typeName, type); + return type; + } + } + + return null; + } + } + + /// + /// 获取已加载的程序集中的指定类型的子类列表。 + /// + /// + /// Gets the list of subclass names of the specified type from the loaded assemblies. + /// + /// 指定类型 / The specified type + /// 子类全名列表 / The list of subclass full names + [Preserve] + public static List GetRuntimeTypeNames(Type type) + { + var types = GetTypes(); + var results = new List(256); + foreach (var t in types) + { + if (t.IsAbstract || !t.IsClass) + { + continue; + } + + if (t.IsSubclassOf(type) || t.IsImplWithInterface(type)) + { + results.Add(t.FullName); + } + } + + return results; + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Assembly.cs.meta b/Runtime/Utility/AssemblyUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Assembly.cs.meta rename to Runtime/Utility/AssemblyUtility.cs.meta diff --git a/Runtime/Utility/AssetPathUtility.cs b/Runtime/Utility/AssetPathUtility.cs new file mode 100644 index 0000000..e4ccab0 --- /dev/null +++ b/Runtime/Utility/AssetPathUtility.cs @@ -0,0 +1,307 @@ +namespace GameFrameX.Runtime +{ + /// + /// Asset Bundle 实用函数集,主要是路径拼接。 + /// + /// + /// Asset Bundle utility functions, mainly for path concatenation. + /// + [UnityEngine.Scripting.Preserve] + /// + /// 路径常量和方法。 + /// + /// + /// Path constants and methods. + /// + public static class AssetPathUtility + { + /// + /// 打包资源根路径 + /// + public const string BundlesPath = "Assets/Bundles"; + + /// + /// 打包资源文件夹名称 + /// + public const string BundlesDirectoryName = "Bundles"; + + /// + /// 打包资源文件夹Scene名称 + /// + public const string BundlesDirectorySceneName = "Scene"; + + /// + /// 打包资源文件夹Localization名称 + /// + public const string BundlesDirectoryLocalizationName = "Localization"; + + /// + /// 打包资源文件夹Config名称 + /// + public const string BundlesDirectoryConfigName = "Config"; + + /// + /// 打包资源文件夹AOTCode名称 + /// + public const string BundlesDirectoryAOTCodeName = "AOTCode"; + + /// + /// 打包资源文件夹Code名称 + /// + public const string BundlesDirectoryCodeName = "Code"; + + /// + /// 打包资源文件夹Sound名称 + /// + public const string BundlesDirectorySoundName = "Sound"; + + /// + /// 打包资源文件夹Prefab名称 + /// + public const string BundlesDirectoryPrefabName = "Prefabs"; + + /// + /// 打包资源文件夹Video名称 + /// + public const string BundlesDirectoryVideoName = "Video"; + + /// + /// 打包资源文件夹Image名称 + /// + public const string BundlesDirectoryImageName = "Image"; + + /// + /// 打包资源文件夹Fonts名称 + /// + public const string BundlesDirectoryFontsName = "Fonts"; + + /// + /// 打包资源文件夹UI名称 + /// + public const string BundlesDirectoryUIName = "UI"; + + /// + /// 打包资源文件夹Sprite名称 + /// + public const string BundlesDirectorySpriteName = "Sprite"; + + /// + /// 打包资源文件夹Spine名称 + /// + public const string BundlesDirectorySpineName = "Spine"; + + /// + /// 打包资源文件夹Shader名称 + /// + public const string BundlesDirectoryShaderName = "Shader"; + + /// + /// 获取文件路径 + /// + /// 相对于Bundles的路径,不要以/开头 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetFilePath(string filePath) + { + return $"{BundlesPath}/{filePath}"; + } + + /// + /// 获取Spine文件路径 + /// + /// 相对于Bundles/Spine的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetSpinePath(string filePath) + { + return GetCategoryFilePath(BundlesDirectorySpineName, filePath); + } + + /// + /// 获取着色器文件路径 + /// + /// 相对于Bundles/Shader的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetShaderPath(string filePath) + { + return GetCategoryFilePath(BundlesDirectoryShaderName, filePath); + } + + /// + /// 获取字体文件路径 + /// + /// 相对于Bundles/Fonts的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetFontPath(string filePath) + { + return GetCategoryFilePath(BundlesDirectoryFontsName, filePath); + } + + /// + /// 获取图片文件路径 + /// + /// 相对于Bundles/Image的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetImagePath(string filePath) + { + return GetCategoryFilePath(BundlesDirectoryImageName, filePath); + } + + /// + /// 获取视频文件路径 + /// + /// 相对于Bundles/Video的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetVideoPath(string filePath) + { + return GetCategoryFilePath(BundlesDirectoryVideoName, filePath); + } + + /// + /// 获取Sprite文件路径 + /// + /// 相对于Bundles/Sprite的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetSpritePath(string filePath) + { + return GetCategoryFilePath(BundlesDirectorySpriteName, filePath); + } + + /// + /// 获取Prefab文件路径 + /// + /// 相对于Bundles/Prefabs的路径,不要以/开头,需要携带扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetPrefabPath(string filePath) + { + return GetCategoryFilePath(BundlesDirectoryPrefabName, filePath); + } + + /// + /// 获取根据类别文件夹名称和文件路径获得完整文件路径 + /// + /// 相对于Bundles的类别名称 + /// 相对于Bundles的路径,不要以/开头 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetCategoryFilePath(string category, string filePath) + { + return $"{BundlesPath}/{category}/{filePath}"; + } + + /// + /// 获取配置文件路径 + /// + /// 相对于Bundles/Config的路径,不要以/开头,需要携带扩展名 + /// 文件扩展名称 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetConfigPath(string fileName, string extension = ".bytes") + { + return GetCategoryFilePath(BundlesDirectoryConfigName, $"{fileName}{extension}"); + } + + /// + /// 获取AOT元数据代码文件路径 + /// + /// 相对于Bundles/AOTCode的路径,不要以/开头,需要携带扩展名 + /// 文件扩展名称 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetAOTCodePath(string fileName, string extension = ".bytes") + { + return GetCategoryFilePath(BundlesDirectoryAOTCodeName, $"{fileName}{extension}"); + } + + /// + /// 获取代码文件路径 + /// + /// 相对于Bundles/Code的路径,不要以/开头,需要携带扩展名 + /// 文件扩展名称 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetCodePath(string fileName, string extension = ".bytes") + { + return GetCategoryFilePath(BundlesDirectoryCodeName, $"{fileName}{extension}"); + } + + /// + /// 获取UI文件路径 + /// + /// UI包名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetUIPackagePath(string uiPackageName) + { + return GetCategoryFilePath(BundlesDirectoryUIName, $"{uiPackageName}/{uiPackageName}"); + } + + /// + /// 获取UI文件路径 + /// + /// UI路径 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetUIPath(string uiPath) + { + return GetCategoryFilePath(BundlesDirectoryUIName, uiPath); + } + + /// + /// 获取声音文件路径 + /// + /// 路径包含名称 + /// 扩展名称,默认为.mp3 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetSoundPath(string pathName, string extension = ".mp3") + { + if (pathName.IndexOf('.') >= 0) + { + return GetCategoryFilePath(BundlesDirectorySoundName, pathName); + } + + return GetCategoryFilePath(BundlesDirectorySoundName, $"{pathName}{extension}"); + } + + /// + /// 获取场景文件路径 + /// + /// 路径包含名称 + /// 扩展名,默认为.unity + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetScenePath(string pathName, string extension = ".unity") + { + if (pathName.IndexOf('.') >= 0) + { + return GetCategoryFilePath(BundlesDirectorySceneName, pathName); + } + + return GetCategoryFilePath(BundlesDirectorySceneName, $"{pathName}{extension}"); + } + + /// + /// 获取本地化文件路径 + /// + /// 路径包含名称 + /// 文件扩展名 + /// 返回拼接好的路径 + [UnityEngine.Scripting.Preserve] + public static string GetLocalizationPath(string pathName, string extension = ".xml") + { + if (pathName.IndexOf('.') >= 0) + { + return GetCategoryFilePath(BundlesDirectoryLocalizationName, pathName); + } + + return GetCategoryFilePath(BundlesDirectoryLocalizationName, $"{pathName}{extension}"); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Asset.Path.cs.meta b/Runtime/Utility/AssetPathUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Asset.Path.cs.meta rename to Runtime/Utility/AssetPathUtility.cs.meta diff --git a/Runtime/Utility/ConverterUtility.cs b/Runtime/Utility/ConverterUtility.cs new file mode 100644 index 0000000..fe6fcb6 --- /dev/null +++ b/Runtime/Utility/ConverterUtility.cs @@ -0,0 +1,941 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.Text; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + /// + /// 类型转换相关的实用函数。 + /// + /// + /// Type conversion related utility functions. + /// + [Preserve] + public static class ConverterUtility + { + private const float InchesToCentimeters = 2.54f; // 1 inch = 2.54 cm + private const float CentimetersToInches = 1f / InchesToCentimeters; // 1 cm = 0.3937 inches + + /// + /// 获取数据在此计算机结构中存储时的字节顺序。 + /// + /// + /// Gets the byte order of data storage in this computer architecture. + /// + [Preserve] + public static bool IsLittleEndian + { + get { return BitConverter.IsLittleEndian; } + } + + /// + /// 获取或设置屏幕每英寸点数。 + /// + /// + /// Gets or sets the screen dots per inch. + /// + [Preserve] + public static float ScreenDpi { get; set; } + + /// + /// 将像素转换为厘米。 + /// + /// 像素。 + /// 厘米。 + [Preserve] + public static float GetCentimetersFromPixels(float pixels) + { + if (ScreenDpi <= 0) + { + throw new GameFrameworkException("You must set screen DPI first."); + } + + return InchesToCentimeters * pixels / ScreenDpi; + } + + /// + /// 将厘米转换为像素。 + /// + /// 厘米。 + /// 像素。 + [Preserve] + public static float GetPixelsFromCentimeters(float centimeters) + { + if (ScreenDpi <= 0) + { + throw new GameFrameworkException("You must set screen DPI first."); + } + + return CentimetersToInches * centimeters * ScreenDpi; + } + + /// + /// 将像素转换为英寸。 + /// + /// 像素。 + /// 英寸。 + [Preserve] + public static float GetInchesFromPixels(float pixels) + { + if (ScreenDpi <= 0) + { + throw new GameFrameworkException("You must set screen DPI first."); + } + + return pixels / ScreenDpi; + } + + /// + /// 将英寸转换为像素。 + /// + /// 英寸。 + /// 像素。 + [Preserve] + public static float GetPixelsFromInches(float inches) + { + if (ScreenDpi <= 0) + { + throw new GameFrameworkException("You must set screen DPI first."); + } + + return inches * ScreenDpi; + } + + /// + /// 以字节数组的形式获取指定的布尔值。 + /// + /// 要转换的布尔值。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(bool value) + { + byte[] buffer = new byte[1]; + GetBytes(value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的布尔值。 + /// + /// 要转换的布尔值。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(bool value, byte[] buffer) + { + GetBytes(value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的布尔值。 + /// + /// 要转换的布尔值。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static void GetBytes(bool value, byte[] buffer, int startIndex) + { + if (buffer == null) + { + throw new GameFrameworkException("Buffer is invalid."); + } + + if (startIndex < 0 || startIndex + 1 > buffer.Length) + { + throw new GameFrameworkException("Start index is invalid."); + } + + buffer[startIndex] = value ? (byte)1 : (byte)0; + } + + /// + /// 返回由字节数组中首字节转换来的布尔值。 + /// + /// 字节数组。 + /// 如果 value 中的首字节非零,则为 true,否则为 false。 + [Preserve] + public static bool GetBoolean(byte[] value) + { + return BitConverter.ToBoolean(value, 0); + } + + /// + /// 返回由字节数组中指定位置的一个字节转换来的布尔值。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 如果 value 中指定位置的字节非零,则为 true,否则为 false。 + [Preserve] + public static bool GetBoolean(byte[] value, int startIndex) + { + return BitConverter.ToBoolean(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 Unicode 字符值。 + /// + /// 要转换的字符。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(char value) + { + byte[] buffer = new byte[2]; + GetBytes((short)value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 Unicode 字符值。 + /// + /// 要转换的字符。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(char value, byte[] buffer) + { + GetBytes((short)value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 Unicode 字符值。 + /// + /// 要转换的字符。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static void GetBytes(char value, byte[] buffer, int startIndex) + { + GetBytes((short)value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前两个字节转换来的 Unicode 字符。 + /// + /// 字节数组。 + /// 由两个字节构成的字符。 + [Preserve] + public static char GetChar(byte[] value) + { + return BitConverter.ToChar(value, 0); + } + + /// + /// 返回由字节数组中指定位置的两个字节转换来的 Unicode 字符。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由两个字节构成的字符。 + [Preserve] + public static char GetChar(byte[] value, int startIndex) + { + return BitConverter.ToChar(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 16 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(short value) + { + byte[] buffer = new byte[2]; + GetBytes(value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 16 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(short value, byte[] buffer) + { + GetBytes(value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 16 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static unsafe void GetBytes(short value, byte[] buffer, int startIndex) + { + if (buffer == null) + { + throw new GameFrameworkException("Buffer is invalid."); + } + + if (startIndex < 0 || startIndex + 2 > buffer.Length) + { + throw new GameFrameworkException("Start index is invalid."); + } + + fixed (byte* valueRef = buffer) + { + *(short*)(valueRef + startIndex) = value; + } + } + + /// + /// 返回由字节数组中前两个字节转换来的 16 位有符号整数。 + /// + /// 字节数组。 + /// 由两个字节构成的 16 位有符号整数。 + [Preserve] + public static short GetInt16(byte[] value) + { + return BitConverter.ToInt16(value, 0); + } + + /// + /// 返回由字节数组中指定位置的两个字节转换来的 16 位有符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由两个字节构成的 16 位有符号整数。 + [Preserve] + public static short GetInt16(byte[] value, int startIndex) + { + return BitConverter.ToInt16(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 16 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(ushort value) + { + byte[] buffer = new byte[2]; + GetBytes((short)value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 16 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(ushort value, byte[] buffer) + { + GetBytes((short)value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 16 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static void GetBytes(ushort value, byte[] buffer, int startIndex) + { + GetBytes((short)value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前两个字节转换来的 16 位无符号整数。 + /// + /// 字节数组。 + /// 由两个字节构成的 16 位无符号整数。 + [Preserve] + public static ushort GetUInt16(byte[] value) + { + return BitConverter.ToUInt16(value, 0); + } + + /// + /// 返回由字节数组中指定位置的两个字节转换来的 16 位无符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由两个字节构成的 16 位无符号整数。 + [Preserve] + public static ushort GetUInt16(byte[] value, int startIndex) + { + return BitConverter.ToUInt16(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 32 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(int value) + { + byte[] buffer = new byte[4]; + GetBytes(value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 32 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(int value, byte[] buffer) + { + GetBytes(value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 32 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static unsafe void GetBytes(int value, byte[] buffer, int startIndex) + { + if (buffer == null) + { + throw new GameFrameworkException("Buffer is invalid."); + } + + if (startIndex < 0 || startIndex + 4 > buffer.Length) + { + throw new GameFrameworkException("Start index is invalid."); + } + + fixed (byte* valueRef = buffer) + { + *(int*)(valueRef + startIndex) = value; + } + } + + /// + /// 返回由字节数组中前四个字节转换来的 32 位有符号整数。 + /// + /// 字节数组。 + /// 由四个字节构成的 32 位有符号整数。 + [Preserve] + public static int GetInt32(byte[] value) + { + return BitConverter.ToInt32(value, 0); + } + + /// + /// 返回由字节数组中指定位置的四个字节转换来的 32 位有符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由四个字节构成的 32 位有符号整数。 + [Preserve] + public static int GetInt32(byte[] value, int startIndex) + { + return BitConverter.ToInt32(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 32 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(uint value) + { + byte[] buffer = new byte[4]; + GetBytes((int)value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 32 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(uint value, byte[] buffer) + { + GetBytes((int)value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 32 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static void GetBytes(uint value, byte[] buffer, int startIndex) + { + GetBytes((int)value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前四个字节转换来的 32 位无符号整数。 + /// + /// 字节数组。 + /// 由四个字节构成的 32 位无符号整数。 + [Preserve] + public static uint GetUInt32(byte[] value) + { + return BitConverter.ToUInt32(value, 0); + } + + /// + /// 返回由字节数组中指定位置的四个字节转换来的 32 位无符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由四个字节构成的 32 位无符号整数。 + [Preserve] + public static uint GetUInt32(byte[] value, int startIndex) + { + return BitConverter.ToUInt32(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 64 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(long value) + { + byte[] buffer = new byte[8]; + GetBytes(value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 64 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(long value, byte[] buffer) + { + GetBytes(value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 64 位有符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static unsafe void GetBytes(long value, byte[] buffer, int startIndex) + { + if (buffer == null) + { + throw new GameFrameworkException("Buffer is invalid."); + } + + if (startIndex < 0 || startIndex + 8 > buffer.Length) + { + throw new GameFrameworkException("Start index is invalid."); + } + + fixed (byte* valueRef = buffer) + { + *(long*)(valueRef + startIndex) = value; + } + } + + /// + /// 返回由字节数组中前八个字节转换来的 64 位有符号整数。 + /// + /// 字节数组。 + /// 由八个字节构成的 64 位有符号整数。 + [Preserve] + public static long GetInt64(byte[] value) + { + return BitConverter.ToInt64(value, 0); + } + + /// + /// 返回由字节数组中指定位置的八个字节转换来的 64 位有符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由八个字节构成的 64 位有符号整数。 + [Preserve] + public static long GetInt64(byte[] value, int startIndex) + { + return BitConverter.ToInt64(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的 64 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(ulong value) + { + byte[] buffer = new byte[8]; + GetBytes((long)value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的 64 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static void GetBytes(ulong value, byte[] buffer) + { + GetBytes((long)value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的 64 位无符号整数值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static void GetBytes(ulong value, byte[] buffer, int startIndex) + { + GetBytes((long)value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前八个字节转换来的 64 位无符号整数。 + /// + /// 字节数组。 + /// 由八个字节构成的 64 位无符号整数。 + [Preserve] + public static ulong GetUInt64(byte[] value) + { + return BitConverter.ToUInt64(value, 0); + } + + /// + /// 返回由字节数组中指定位置的八个字节转换来的 64 位无符号整数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由八个字节构成的 64 位无符号整数。 + [Preserve] + public static ulong GetUInt64(byte[] value, int startIndex) + { + return BitConverter.ToUInt64(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的单精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static unsafe byte[] GetBytes(float value) + { + byte[] buffer = new byte[4]; + GetBytes(*(int*)&value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的单精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static unsafe void GetBytes(float value, byte[] buffer) + { + GetBytes(*(int*)&value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的单精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static unsafe void GetBytes(float value, byte[] buffer, int startIndex) + { + GetBytes(*(int*)&value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前四个字节转换来的单精度浮点数。 + /// + /// 字节数组。 + /// 由四个字节构成的单精度浮点数。 + [Preserve] + public static float GetSingle(byte[] value) + { + return BitConverter.ToSingle(value, 0); + } + + /// + /// 返回由字节数组中指定位置的四个字节转换来的单精度浮点数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由四个字节构成的单精度浮点数。 + [Preserve] + public static float GetSingle(byte[] value, int startIndex) + { + return BitConverter.ToSingle(value, startIndex); + } + + /// + /// 以字节数组的形式获取指定的双精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static unsafe byte[] GetBytes(double value) + { + byte[] buffer = new byte[8]; + GetBytes(*(long*)&value, buffer, 0); + return buffer; + } + + /// + /// 以字节数组的形式获取指定的双精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + [Preserve] + public static unsafe void GetBytes(double value, byte[] buffer) + { + GetBytes(*(long*)&value, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定的双精度浮点值。 + /// + /// 要转换的数字。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + [Preserve] + public static unsafe void GetBytes(double value, byte[] buffer, int startIndex) + { + GetBytes(*(long*)&value, buffer, startIndex); + } + + /// + /// 返回由字节数组中前八个字节转换来的双精度浮点数。 + /// + /// 字节数组。 + /// 由八个字节构成的双精度浮点数。 + [Preserve] + public static double GetDouble(byte[] value) + { + return BitConverter.ToDouble(value, 0); + } + + /// + /// 返回由字节数组中指定位置的八个字节转换来的双精度浮点数。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 由八个字节构成的双精度浮点数。 + [Preserve] + public static double GetDouble(byte[] value, int startIndex) + { + return BitConverter.ToDouble(value, startIndex); + } + + /// + /// 以字节数组的形式获取 UTF-8 编码的字符串。 + /// + /// 要转换的字符串。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(string value) + { + return GetBytes(value, Encoding.UTF8); + } + + /// + /// 以字节数组的形式获取 UTF-8 编码的字符串。 + /// + /// 要转换的字符串。 + /// 用于存放结果的字节数组。 + /// buffer 内实际填充了多少字节。 + [Preserve] + public static int GetBytes(string value, byte[] buffer) + { + return GetBytes(value, Encoding.UTF8, buffer, 0); + } + + /// + /// 以字节数组的形式获取 UTF-8 编码的字符串。 + /// + /// 要转换的字符串。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + /// buffer 内实际填充了多少字节。 + [Preserve] + public static int GetBytes(string value, byte[] buffer, int startIndex) + { + return GetBytes(value, Encoding.UTF8, buffer, startIndex); + } + + /// + /// 以字节数组的形式获取指定编码的字符串。 + /// + /// 要转换的字符串。 + /// 要使用的编码。 + /// 用于存放结果的字节数组。 + [Preserve] + public static byte[] GetBytes(string value, Encoding encoding) + { + if (value == null) + { + throw new GameFrameworkException("Value is invalid."); + } + + if (encoding == null) + { + throw new GameFrameworkException("Encoding is invalid."); + } + + return encoding.GetBytes(value); + } + + /// + /// 以字节数组的形式获取指定编码的字符串。 + /// + /// 要转换的字符串。 + /// 要使用的编码。 + /// 用于存放结果的字节数组。 + /// buffer 内实际填充了多少字节。 + [Preserve] + public static int GetBytes(string value, Encoding encoding, byte[] buffer) + { + return GetBytes(value, encoding, buffer, 0); + } + + /// + /// 以字节数组的形式获取指定编码的字符串。 + /// + /// 要转换的字符串。 + /// 要使用的编码。 + /// 用于存放结果的字节数组。 + /// buffer 内的起始位置。 + /// buffer 内实际填充了多少字节。 + [Preserve] + public static int GetBytes(string value, Encoding encoding, byte[] buffer, int startIndex) + { + if (value == null) + { + throw new GameFrameworkException("Value is invalid."); + } + + if (encoding == null) + { + throw new GameFrameworkException("Encoding is invalid."); + } + + return encoding.GetBytes(value, 0, value.Length, buffer, startIndex); + } + + /// + /// 返回由字节数组使用 UTF-8 编码转换成的字符串。 + /// + /// 字节数组。 + /// 转换后的字符串。 + [Preserve] + public static string GetString(byte[] value) + { + return GetString(value, Encoding.UTF8); + } + + /// + /// 返回由字节数组使用指定编码转换成的字符串。 + /// + /// 字节数组。 + /// 要使用的编码。 + /// 转换后的字符串。 + [Preserve] + public static string GetString(byte[] value, Encoding encoding) + { + if (value == null) + { + throw new GameFrameworkException("Value is invalid."); + } + + if (encoding == null) + { + throw new GameFrameworkException("Encoding is invalid."); + } + + return encoding.GetString(value); + } + + /// + /// 返回由字节数组使用 UTF-8 编码转换成的字符串。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 长度。 + /// 转换后的字符串。 + [Preserve] + public static string GetString(byte[] value, int startIndex, int length) + { + return GetString(value, startIndex, length, Encoding.UTF8); + } + + /// + /// 返回由字节数组使用指定编码转换成的字符串。 + /// + /// 字节数组。 + /// value 内的起始位置。 + /// 长度。 + /// 要使用的编码。 + /// 转换后的字符串。 + [Preserve] + public static string GetString(byte[] value, int startIndex, int length, Encoding encoding) + { + if (value == null) + { + throw new GameFrameworkException("Value is invalid."); + } + + if (encoding == null) + { + throw new GameFrameworkException("Encoding is invalid."); + } + + return encoding.GetString(value, startIndex, length); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Converter.cs.meta b/Runtime/Utility/ConverterUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Converter.cs.meta rename to Runtime/Utility/ConverterUtility.cs.meta diff --git a/Runtime/Utility/DirectoryUtility.cs b/Runtime/Utility/DirectoryUtility.cs new file mode 100644 index 0000000..379cae6 --- /dev/null +++ b/Runtime/Utility/DirectoryUtility.cs @@ -0,0 +1,113 @@ +using System; +using UnityEngine; + +namespace GameFrameX.Runtime +{ + [UnityEngine.Scripting.Preserve] + public static partial class DirectoryUtility + { + /// + /// 移除空文件夹。 + /// + /// + /// Removes empty directories. + /// + /// 要处理的文件夹名称 / The directory name to process + /// 是否移除空文件夹成功 / Whether the empty directory was removed successfully + [UnityEngine.Scripting.Preserve] + public static bool RemoveEmptyDirectory(string directoryName) + { + if (string.IsNullOrEmpty(directoryName)) + { + throw new GameFrameworkException("Directory name is invalid."); + } + + try + { + if (!System.IO.Directory.Exists(directoryName)) + { + return false; + } + + // 不使用 SearchOption.AllDirectories,以便于在可能产生异常的环境下删除尽可能多的目录 + string[] subDirectoryNames = System.IO.Directory.GetDirectories(directoryName, "*"); + int subDirectoryCount = subDirectoryNames.Length; + foreach (string subDirectoryName in subDirectoryNames) + { + if (RemoveEmptyDirectory(subDirectoryName)) + { + subDirectoryCount--; + } + } + + if (subDirectoryCount > 0) + { + return false; + } + + if (System.IO.Directory.GetFiles(directoryName, "*").Length > 0) + { + return false; + } + + System.IO.Directory.Delete(directoryName); + return true; + } + catch + { + return false; + } + } + + [UnityEngine.Scripting.Preserve] + public static void CreateIfNotExists(string path) + { + if (!System.IO.Directory.Exists(path) && !string.IsNullOrEmpty(path)) + { + System.IO.Directory.CreateDirectory(path); + } + } + + [UnityEngine.Scripting.Preserve] + public static void DeleteIfExists(string path, bool recursive = true) + { + if (!System.IO.Directory.Exists(path)) + { + return; + } + + try + { + ClearFiles(path); + System.IO.Directory.Delete(path, recursive); + } + catch (Exception e) + { + Log.Error(e.ToString()); + } + } + + [UnityEngine.Scripting.Preserve] + public static void ClearFiles(string path) + { + if (!System.IO.Directory.Exists(path)) + { + return; + } + + var dirInfo = new System.IO.DirectoryInfo(path); + + var files = dirInfo.GetFiles(); + foreach (var file in files) + { + System.IO.File.Delete(file.FullName); + } + + var subDirs = dirInfo.GetDirectories(); + foreach (var subDir in subDirs) + { + ClearFiles(subDir.FullName); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/DirectoryUtility.cs.meta b/Runtime/Utility/DirectoryUtility.cs.meta new file mode 100644 index 0000000..e16c2a4 --- /dev/null +++ b/Runtime/Utility/DirectoryUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ca250c5a0b554e45a074bab0bbdec5cc +timeCreated: 1786544380 \ No newline at end of file diff --git a/Runtime/Helper/DoTweenHelper.cs b/Runtime/Utility/DoTweenUtility.cs similarity index 99% rename from Runtime/Helper/DoTweenHelper.cs rename to Runtime/Utility/DoTweenUtility.cs index a071a36..2a1c0cb 100644 --- a/Runtime/Helper/DoTweenHelper.cs +++ b/Runtime/Utility/DoTweenUtility.cs @@ -12,7 +12,7 @@ namespace GameFrameX.Runtime /// DOTween animation helper class. /// [UnityEngine.Scripting.Preserve] - public static class DoTweenHelper + public static class DoTweenUtility { /// /// 关闭对象上的全部动画。 diff --git a/Runtime/Helper/DoTweenHelper.cs.meta b/Runtime/Utility/DoTweenUtility.cs.meta similarity index 100% rename from Runtime/Helper/DoTweenHelper.cs.meta rename to Runtime/Utility/DoTweenUtility.cs.meta diff --git a/Runtime/Utility/EncryptionUtility.Aes.cs b/Runtime/Utility/EncryptionUtility.Aes.cs new file mode 100644 index 0000000..d9aa70a --- /dev/null +++ b/Runtime/Utility/EncryptionUtility.Aes.cs @@ -0,0 +1,322 @@ +using System; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace GameFrameX.Runtime +{ + /// + /// 加密解密相关的实用函数。 + /// + /// + /// Encryption and decryption related utility functions. + /// + public static partial class EncryptionUtility + { + /// + /// AES 加密算法的实现。 + /// + /// + /// AES encryption algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public static class Aes + { + #region 加密 + + #region 加密字符串 + + /// + /// AES 加密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 + /// + /// + /// AES encryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). + /// + /// 待加密密文 / The plaintext to encrypt + /// 加密密钥 / The encryption key + /// 加密后的 Base64 字符串 / The Base64 encrypted string + [Obsolete("AESEncrypt uses hardcoded IV/Salt. Use AESEncryptSecure instead.")] + [UnityEngine.Scripting.Preserve] + public static string AESEncrypt(string EncryptString, string EncryptKey) + { + return AESEncryptSecure(EncryptString, EncryptKey); + } + + #endregion + + #region 加密字节数组 + + /// + /// AES 加密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 + /// + /// + /// AES encryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). + /// + /// 待加密的字节数组 / The byte array to encrypt + /// 加密密钥 / The encryption key + /// 加密后的字节数组 / The encrypted byte array + [Obsolete("AESEncrypt uses hardcoded IV/Salt. Use AESEncryptSecure instead.")] + [UnityEngine.Scripting.Preserve] + public static byte[] AESEncrypt(byte[] EncryptByte, string EncryptKey) + { + return AESEncryptSecure(EncryptByte, EncryptKey); + } + + #endregion + + #endregion + + #region 解密 + + #region 解密字符串 + + /// + /// AES 解密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 + /// + /// + /// AES decryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). + /// + /// 待解密密文 / The ciphertext to decrypt + /// 解密密钥 / The decryption key + /// 解密后的字符串 / The decrypted string + [Obsolete("AESDecrypt uses hardcoded IV/Salt. Use AESDecryptSecure instead.")] + [UnityEngine.Scripting.Preserve] + public static string AESDecrypt(string DecryptString, string DecryptKey) + { + return AESDecryptSecure(DecryptString, DecryptKey); + } + + #endregion + + #region 解密字节数组 + + /// + /// AES 解密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 + /// + /// + /// AES decryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). + /// + /// 待解密的字节数组 / The byte array to decrypt + /// 解密密钥 / The decryption key + /// 解密后的字节数组 / The decrypted byte array + [Obsolete("AESDecrypt uses hardcoded IV/Salt. Use AESDecryptSecure instead.")] + [UnityEngine.Scripting.Preserve] + public static byte[] AESDecrypt(byte[] DecryptByte, string DecryptKey) + { + return AESDecryptSecure(DecryptByte, DecryptKey); + } + + #endregion + + #endregion + + #region 安全加密 + + #region 安全加密字符串 + + /// + /// AES 安全加密(使用随机 IV 和 Salt,相同明文产生不同密文)。 + /// + /// + /// AES secure encryption (uses random IV and Salt, same plaintext produces different ciphertext). + /// + /// 待加密明文 / The plaintext to encrypt + /// 加密密钥 / The encryption key + /// 加密后的 Base64 字符串 / The Base64 encrypted string + [UnityEngine.Scripting.Preserve] + public static string AESEncryptSecure(string EncryptString, string EncryptKey) + { + return Convert.ToBase64String(AESEncryptSecure(Encoding.UTF8.GetBytes(EncryptString), EncryptKey)); + } + + #endregion + + #region 安全加密字节数组 + + /// + /// AES 安全加密(使用随机 IV 和 Salt,相同明文产生不同密文)。 + /// 密文格式:[IV(16字节)][Salt(16字节)][加密数据]。 + /// + /// + /// AES secure encryption (uses random IV and Salt, same plaintext produces different ciphertext). + /// Ciphertext format: [IV(16 bytes)][Salt(16 bytes)][Encrypted data]. + /// + /// 待加密的字节数组 / The byte array to encrypt + /// 加密密钥 / The encryption key + /// 加密后的字节数组 / The encrypted byte array + [UnityEngine.Scripting.Preserve] + public static byte[] AESEncryptSecure(byte[] EncryptByte, string EncryptKey) + { + if (EncryptByte == null) + { + throw new ArgumentNullException("EncryptByte"); + } + + if (EncryptByte.Length == 0) + { + throw (new Exception("明文不得为空")); + } + + if (string.IsNullOrEmpty(EncryptKey)) + { + throw (new Exception("密钥不得为空")); + } + + byte[] m_strEncrypt; + byte[] m_btIV = new byte[16]; + byte[] m_salt = new byte[16]; + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) + { + rng.GetBytes(m_btIV); + rng.GetBytes(m_salt); + } + + Rijndael m_AESProvider = Rijndael.Create(); + try + { + MemoryStream m_stream = new MemoryStream(); + m_stream.Write(m_btIV, 0, m_btIV.Length); + m_stream.Write(m_salt, 0, m_salt.Length); + PasswordDeriveBytes pdb = new PasswordDeriveBytes(EncryptKey, m_salt); + ICryptoTransform transform = m_AESProvider.CreateEncryptor(pdb.GetBytes(32), m_btIV); + CryptoStream m_csstream = new CryptoStream(m_stream, transform, CryptoStreamMode.Write); + m_csstream.Write(EncryptByte, 0, EncryptByte.Length); + m_csstream.FlushFinalBlock(); + m_strEncrypt = m_stream.ToArray(); + m_stream.Close(); + m_stream.Dispose(); + m_csstream.Close(); + m_csstream.Dispose(); + } + catch (IOException ex) + { + throw ex; + } + catch (CryptographicException ex) + { + throw ex; + } + catch (ArgumentException ex) + { + throw ex; + } + catch (Exception ex) + { + throw ex; + } + finally + { + m_AESProvider.Clear(); + } + + return m_strEncrypt; + } + + #endregion + + #endregion + + #region 安全解密 + + #region 安全解密字符串 + + /// + /// AES 安全解密(配合 AESEncryptSecure 使用,从密文头部提取随机 IV 和 Salt)。 + /// + /// + /// AES secure decryption (used with AESEncryptSecure, extracts random IV and Salt from ciphertext header). + /// + /// 待解密密文 / The ciphertext to decrypt + /// 解密密钥 / The decryption key + /// 解密后的字符串 / The decrypted string + [UnityEngine.Scripting.Preserve] + public static string AESDecryptSecure(string DecryptString, string DecryptKey) + { + return Encoding.UTF8.GetString(AESDecryptSecure(Convert.FromBase64String(DecryptString), DecryptKey)); + } + + #endregion + + #region 安全解密字节数组 + + /// + /// AES 安全解密(配合 AESEncryptSecure 使用,从密文头部提取随机 IV 和 Salt)。 + /// 密文格式:[IV(16字节)][Salt(16字节)][加密数据]。 + /// + /// + /// AES secure decryption (used with AESEncryptSecure, extracts random IV and Salt from ciphertext header). + /// Ciphertext format: [IV(16 bytes)][Salt(16 bytes)][Encrypted data]. + /// + /// 待解密的字节数组 / The byte array to decrypt + /// 解密密钥 / The decryption key + /// 解密后的字节数组 / The decrypted byte array + [UnityEngine.Scripting.Preserve] + public static byte[] AESDecryptSecure(byte[] DecryptByte, string DecryptKey) + { + if (DecryptByte == null) + { + throw new ArgumentNullException("DecryptByte"); + } + + if (DecryptByte.Length <= 32) + { + throw (new Exception("密文不得为空")); + } + + if (string.IsNullOrEmpty(DecryptKey)) + { + throw (new Exception("密钥不得为空")); + } + + byte[] m_strDecrypt; + byte[] m_btIV = new byte[16]; + byte[] m_salt = new byte[16]; + byte[] m_EncryptData = new byte[DecryptByte.Length - 32]; + Buffer.BlockCopy(DecryptByte, 0, m_btIV, 0, 16); + Buffer.BlockCopy(DecryptByte, 16, m_salt, 0, 16); + Buffer.BlockCopy(DecryptByte, 32, m_EncryptData, 0, m_EncryptData.Length); + Rijndael m_AESProvider = Rijndael.Create(); + try + { + MemoryStream m_stream = new MemoryStream(); + PasswordDeriveBytes pdb = new PasswordDeriveBytes(DecryptKey, m_salt); + ICryptoTransform transform = m_AESProvider.CreateDecryptor(pdb.GetBytes(32), m_btIV); + CryptoStream m_csstream = new CryptoStream(m_stream, transform, CryptoStreamMode.Write); + m_csstream.Write(m_EncryptData, 0, m_EncryptData.Length); + m_csstream.FlushFinalBlock(); + m_strDecrypt = m_stream.ToArray(); + m_stream.Close(); + m_stream.Dispose(); + m_csstream.Close(); + m_csstream.Dispose(); + } + catch (IOException ex) + { + throw ex; + } + catch (CryptographicException ex) + { + throw ex; + } + catch (ArgumentException ex) + { + throw ex; + } + catch (Exception ex) + { + throw ex; + } + finally + { + m_AESProvider.Clear(); + } + + return m_strDecrypt; + } + + #endregion + + #endregion + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Aes.cs.meta b/Runtime/Utility/EncryptionUtility.Aes.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Encryption.Aes.cs.meta rename to Runtime/Utility/EncryptionUtility.Aes.cs.meta diff --git a/Runtime/Utility/EncryptionUtility.Dsa.cs b/Runtime/Utility/EncryptionUtility.Dsa.cs new file mode 100644 index 0000000..95a5432 --- /dev/null +++ b/Runtime/Utility/EncryptionUtility.Dsa.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Security.Cryptography; +using System.Text; + +namespace GameFrameX.Runtime +{ + /// + /// 加密解密相关的实用函数。 + /// + public static partial class EncryptionUtility + { + /// + /// DSA 加密算法的实现。 + /// + /// + /// DSA encryption algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public sealed class Dsa + { + private readonly DSACryptoServiceProvider _dsa = null; + + /// + /// Dsa 构造函数,使用提供的 DSACryptoServiceProvider 实例初始化。 + /// + /// + /// Dsa constructor, initializes with the provided DSACryptoServiceProvider instance. + /// + /// DSACryptoServiceProvider 实例 / The DSACryptoServiceProvider instance + [UnityEngine.Scripting.Preserve] + public Dsa(DSACryptoServiceProvider dsa) + { + _dsa = dsa; + } + + /// + /// Dsa 构造函数,使用提供的密钥字符串初始化。 + /// + /// + /// Dsa constructor, initializes with the provided key string. + /// + /// 密钥字符串 / The key string + [UnityEngine.Scripting.Preserve] + public Dsa(string key) + { + DSACryptoServiceProvider rsa = new DSACryptoServiceProvider(); + rsa.FromXmlString(key); + this._dsa = rsa; + } + + /// + /// 创建 DSA 密钥对。 + /// + /// + /// Creates a DSA key pair. + /// + /// 包含私钥和公钥的字典 / A dictionary containing the private key and public key + [UnityEngine.Scripting.Preserve] + public static Dictionary Make() + { + Dictionary dic = new Dictionary(); + DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); + dic["privatekey"] = dsa.ToXmlString(true); + dic["publickey"] = dsa.ToXmlString(false); + return dic; + } + + /// + /// 使用私钥对数据进行签名。 + /// + /// + /// Signs data using the private key. + /// + /// 要签名的数据 / The data to sign + /// 私钥字符串 / The private key string + /// 签名后的字节数组 / The signed byte array + [UnityEngine.Scripting.Preserve] + public static byte[] DSASignData(byte[] dataToSign, string privateKey) + { + try + { + DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); + dsa.FromXmlString(privateKey); + return dsa.SignData(dataToSign); + } + catch (Exception ex) + { + throw new GameFrameworkException("DSA sign data failed.", ex); + } + } + + /// + /// 使用私钥对字符串数据进行签名。 + /// + /// + /// Signs string data using the private key. + /// + /// 要签名的字符串数据 / The string data to sign + /// 私钥字符串 / The private key string + /// 签名后的 Base64 字符串 / The Base64 signed string + [UnityEngine.Scripting.Preserve] + public static string DSASignData(string dataToSign, string privateKey) + { + byte[] res = DSASignData(Encoding.UTF8.GetBytes(dataToSign), privateKey); + return Convert.ToBase64String(res); + } + + /// + /// 使用 DSA 对数据进行签名。 + /// + /// + /// Signs data using DSA. + /// + /// 要签名的数据 / The data to sign + /// 签名后的字节数组 / The signed byte array + [UnityEngine.Scripting.Preserve] + public byte[] SignData(byte[] dataToSign) + { + try + { + return _dsa.SignData(dataToSign); + } + catch (Exception ex) + { + throw new GameFrameworkException("DSA sign data failed.", ex); + } + } + + /// + /// 使用 DSA 对字符串数据进行签名。 + /// + /// + /// Signs string data using DSA. + /// + /// 要签名的字符串数据 / The string data to sign + /// 签名后的 Base64 字符串 / The Base64 signed string + [UnityEngine.Scripting.Preserve] + public string SignData(string dataToSign) + { + byte[] res = SignData(Encoding.UTF8.GetBytes(dataToSign)); + return Convert.ToBase64String(res); + } + + /// + /// 验证签名。 + /// + /// + /// Verifies the signature. + /// + /// 要验证的数据 / The data to verify + /// 签名数据 / The signed data + /// 私钥字符串 / The private key string + /// 验证结果 / The verification result + [UnityEngine.Scripting.Preserve] + public static bool DSAVerifyData(byte[] dataToVerify, byte[] signedData, string privateKey) + { + try + { + DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); + dsa.FromXmlString(privateKey); + return dsa.VerifyData(dataToVerify, signedData); + } + catch (Exception ex) + { + throw new GameFrameworkException("DSA verify data failed.", ex); + } + } + + /// + /// 验证签名。 + /// + /// + /// Verifies the signature. + /// + /// 要验证的字符串数据 / The string data to verify + /// 签名的 Base64 字符串 / The Base64 signed string + /// 私钥字符串 / The private key string + /// 验证结果 / The verification result + [UnityEngine.Scripting.Preserve] + public static bool DSAVerifyData(string dataToVerify, string signedData, string privateKey) + { + return DSAVerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData), + privateKey); + } + + /// + /// 使用 DSA 验证签名。 + /// + /// + /// Verifies the signature using DSA. + /// + /// 要验证的数据 / The data to verify + /// 签名数据 / The signed data + /// 验证结果 / The verification result + [UnityEngine.Scripting.Preserve] + public bool VerifyData(byte[] dataToVerify, byte[] signedData) + { + try + { + return _dsa.VerifyData(dataToVerify, signedData); + } + catch (Exception ex) + { + throw new GameFrameworkException("DSA verify data failed.", ex); + } + } + + /// + /// 使用 DSA 验证签名。 + /// + /// + /// Verifies the signature using DSA. + /// + /// 要验证的字符串数据 / The string data to verify + /// 签名的 Base64 字符串 / The Base64 signed string + /// 验证结果 / The verification result + [UnityEngine.Scripting.Preserve] + public bool VerifyData(string dataToVerify, string signedData) + { + try + { + return VerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData)); + } + catch (Exception ex) + { + throw new GameFrameworkException("DSA verify data failed.", ex); + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Dsa.cs.meta b/Runtime/Utility/EncryptionUtility.Dsa.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Encryption.Dsa.cs.meta rename to Runtime/Utility/EncryptionUtility.Dsa.cs.meta diff --git a/Runtime/Utility/EncryptionUtility.Rsa.cs b/Runtime/Utility/EncryptionUtility.Rsa.cs new file mode 100644 index 0000000..957e995 --- /dev/null +++ b/Runtime/Utility/EncryptionUtility.Rsa.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Security.Cryptography; +using System.Text; + +namespace GameFrameX.Runtime +{ + /// + /// 加密解密相关的实用函数。 + /// + public static partial class EncryptionUtility + { + /// + /// RSA 加密算法的实现。 + /// + /// + /// RSA encryption algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public sealed class Rsa + { + private readonly RSACryptoServiceProvider _rsa = null; + + /// + /// 使用提供的 RSACryptoServiceProvider 实例初始化 Rsa 类。 + /// + /// + /// Initializes the Rsa class with the provided RSACryptoServiceProvider instance. + /// + /// RSACryptoServiceProvider 实例 / The RSACryptoServiceProvider instance + [UnityEngine.Scripting.Preserve] + public Rsa(RSACryptoServiceProvider rsa) + { + _rsa = rsa; + } + + /// + /// 使用提供的密钥字符串初始化 Rsa 类。 + /// + /// + /// Initializes the Rsa class with the provided key string. + /// + /// 密钥字符串 / The key string + [UnityEngine.Scripting.Preserve] + public Rsa(string key) + { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + rsa.FromXmlString(key); + this._rsa = rsa; + } + + /// + /// 创建 RSA 密钥对。 + /// + /// + /// Creates an RSA key pair. + /// + /// 包含私钥和公钥的字典 / A dictionary containing the private key and public key + [UnityEngine.Scripting.Preserve] + public static Dictionary Make() + { + Dictionary dic = new Dictionary(); + RSACryptoServiceProvider dsa = new RSACryptoServiceProvider(); + dic["privateKey"] = dsa.ToXmlString(true); + dic["publicKey"] = dsa.ToXmlString(false); + return dic; + } + + /// + /// 使用公钥加密内容。 + /// + /// + /// Encrypts content using the public key. + /// + /// 公钥 / The public key + /// 要加密的内容 / The content to encrypt + /// 加密后的 Base64 字符串 / The Base64 encrypted string + [UnityEngine.Scripting.Preserve] + public static string RSAEncrypt(string publicKey, string content) + { + byte[] res = RSAEncrypt(publicKey, Encoding.UTF8.GetBytes(content)); + return Convert.ToBase64String(res); + } + + [UnityEngine.Scripting.Preserve] + public string Encrypt(string content) + { + byte[] res = Encrypt(Encoding.UTF8.GetBytes(content)); + return Convert.ToBase64String(res); + } + + [UnityEngine.Scripting.Preserve] + public static byte[] RSAEncrypt(string publicKey, byte[] content) + { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + rsa.FromXmlString(publicKey); + byte[] cipherBytes = rsa.Encrypt(content, false); + return cipherBytes; + } + + [UnityEngine.Scripting.Preserve] + public byte[] Encrypt(byte[] content) + { + byte[] cipherBytes = _rsa.Encrypt(content, false); + return cipherBytes; + } + + /// + /// 使用私钥解密内容。 + /// + /// + /// Decrypts content using the private key. + /// + /// 私钥 / The private key + /// 加密后的内容 / The encrypted content + /// 解密后的内容 / The decrypted content + [UnityEngine.Scripting.Preserve] + public static string RSADecrypt(string privateKey, string content) + { + byte[] res = RSADecrypt(privateKey, Convert.FromBase64String(content)); + return Encoding.UTF8.GetString(res); + } + + [UnityEngine.Scripting.Preserve] + public static byte[] RSADecrypt(string privateKey, byte[] content) + { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + rsa.FromXmlString(privateKey); + byte[] cipherBytes = rsa.Decrypt(content, false); + return cipherBytes; + } + + [UnityEngine.Scripting.Preserve] + public string Decrypt(string content) + { + byte[] res = Decrypt(Convert.FromBase64String(content)); + return Encoding.UTF8.GetString(res); + } + + [UnityEngine.Scripting.Preserve] + public byte[] Decrypt(byte[] content) + { + byte[] bytes = _rsa.Decrypt(content, false); + return bytes; + } + + /// + /// 使用私钥对数据进行签名。 + /// + /// + /// Signs data using the private key. + /// + /// 要签名的数据 / The data to sign + /// 私钥字符串 / The private key string + /// 签名后的字节数组 / The signed byte array + [UnityEngine.Scripting.Preserve] + public static byte[] RSASignData(byte[] dataToSign, string privateKey) + { + try + { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + rsa.FromXmlString(privateKey); + return rsa.SignData(dataToSign, new SHA1CryptoServiceProvider()); + } + catch (Exception ex) + { + throw new GameFrameworkException("RSA sign data failed.", ex); + } + } + + [UnityEngine.Scripting.Preserve] + public static string RSASignData(string dataToSign, string privateKey) + { + byte[] res = RSASignData(Encoding.UTF8.GetBytes(dataToSign), privateKey); + return Convert.ToBase64String(res); + } + + [UnityEngine.Scripting.Preserve] + public byte[] SignData(byte[] dataToSign) + { + try + { + return _rsa.SignData(dataToSign, new SHA1CryptoServiceProvider()); + } + catch (Exception ex) + { + throw new GameFrameworkException("RSA sign data failed.", ex); + } + } + + [UnityEngine.Scripting.Preserve] + public string SignData(string dataToSign) + { + byte[] res = SignData(Encoding.UTF8.GetBytes(dataToSign)); + return Convert.ToBase64String(res); + } + + /// + /// 验证签名。 + /// + /// + /// Verifies the signature. + /// + /// 要验证的数据 / The data to verify + /// 签名数据 / The signed data + /// 公钥字符串 / The public key string + /// 验证结果 / The verification result + [UnityEngine.Scripting.Preserve] + public static bool RSAVerifyData(byte[] dataToVerify, byte[] signedData, string publicKey) + { + try + { + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + rsa.FromXmlString(publicKey); + return rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signedData); + } + catch (Exception ex) + { + throw new GameFrameworkException("RSA verify data failed.", ex); + } + } + + [UnityEngine.Scripting.Preserve] + public static bool RSAVerifyData(string dataToVerify, string signedData, string publicKey) + { + return RSAVerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData), + publicKey); + } + + [UnityEngine.Scripting.Preserve] + public bool VerifyData(byte[] dataToVerify, byte[] signedData) + { + try + { + return _rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signedData); + } + catch (Exception ex) + { + throw new GameFrameworkException("RSA verify data failed.", ex); + } + } + + [UnityEngine.Scripting.Preserve] + public bool VerifyData(string dataToVerify, string signedData) + { + try + { + return VerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData)); + } + catch (Exception ex) + { + throw new GameFrameworkException("RSA verify data failed.", ex); + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Rsa.cs.meta b/Runtime/Utility/EncryptionUtility.Rsa.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Encryption.Rsa.cs.meta rename to Runtime/Utility/EncryptionUtility.Rsa.cs.meta diff --git a/Runtime/Utility/EncryptionUtility.cs b/Runtime/Utility/EncryptionUtility.cs new file mode 100644 index 0000000..a8798ef --- /dev/null +++ b/Runtime/Utility/EncryptionUtility.cs @@ -0,0 +1,167 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; + +namespace GameFrameX.Runtime +{ + /// + /// 加密解密相关的实用函数。 + /// + /// + /// Encryption and decryption related utility functions. + /// + [UnityEngine.Scripting.Preserve] + public static partial class EncryptionUtility + { + private const int QuickEncryptLength = 220; + + /// + /// 将 bytes 使用 code 做异或运算的快速版本。 + /// + /// 原始二进制流。 + /// 异或二进制流。 + /// 异或后的二进制流。 + [UnityEngine.Scripting.Preserve] + public static byte[] GetQuickXorBytes(byte[] bytes, byte[] code) + { + return GetXorBytes(bytes, 0, QuickEncryptLength, code); + } + + /// + /// 将 bytes 使用 code 做异或运算的快速版本。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 + /// + /// 原始及异或后的二进制流。 + /// 异或二进制流。 + [UnityEngine.Scripting.Preserve] + public static void GetQuickSelfXorBytes(byte[] bytes, byte[] code) + { + GetSelfXorBytes(bytes, 0, QuickEncryptLength, code); + } + + /// + /// 将 bytes 使用 code 做异或运算。 + /// + /// 原始二进制流。 + /// 异或二进制流。 + /// 异或后的二进制流。 + [UnityEngine.Scripting.Preserve] + public static byte[] GetXorBytes(byte[] bytes, byte[] code) + { + if (bytes == null) + { + return null; + } + + return GetXorBytes(bytes, 0, bytes.Length, code); + } + + /// + /// 将 bytes 使用 code 做异或运算。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 + /// + /// 原始及异或后的二进制流。 + /// 异或二进制流。 + [UnityEngine.Scripting.Preserve] + public static void GetSelfXorBytes(byte[] bytes, byte[] code) + { + if (bytes == null) + { + return; + } + + GetSelfXorBytes(bytes, 0, bytes.Length, code); + } + + /// + /// 将 bytes 使用 code 做异或运算。 + /// + /// 原始二进制流。 + /// 异或计算的开始位置。 + /// 异或计算长度,若小于 0,则计算整个二进制流。 + /// 异或二进制流。 + /// 异或后的二进制流。 + [UnityEngine.Scripting.Preserve] + public static byte[] GetXorBytes(byte[] bytes, int startIndex, int length, byte[] code) + { + if (bytes == null) + { + return null; + } + + int bytesLength = bytes.Length; + byte[] results = new byte[bytesLength]; + Array.Copy(bytes, 0, results, 0, bytesLength); + GetSelfXorBytes(results, startIndex, length, code); + return results; + } + + /// + /// 将 bytes 使用 code 做异或运算。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 + /// + /// 原始及异或后的二进制流。 + /// 异或计算的开始位置。 + /// 异或计算长度。 + /// 异或二进制流。 + [UnityEngine.Scripting.Preserve] + public static void GetSelfXorBytes(byte[] bytes, int startIndex, int length, byte[] code) + { + if (bytes == null) + { + return; + } + + if (code == null) + { + throw new GameFrameworkException("Code is invalid."); + } + + int codeLength = code.Length; + if (codeLength <= 0) + { + throw new GameFrameworkException("Code length is invalid."); + } + + if (startIndex < 0 || length < 0 || startIndex + length > bytes.Length) + { + throw new GameFrameworkException("Start index or length is invalid."); + } + + int codeIndex = startIndex % codeLength; + for (int i = startIndex; i < startIndex + length; i++) + { + bytes[i] ^= code[codeIndex++]; + codeIndex %= codeLength; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.cs.meta b/Runtime/Utility/EncryptionUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Encryption.cs.meta rename to Runtime/Utility/EncryptionUtility.cs.meta diff --git a/Runtime/Helper/FileHelper.cs b/Runtime/Utility/FileUtility.cs similarity index 88% rename from Runtime/Helper/FileHelper.cs rename to Runtime/Utility/FileUtility.cs index 9a4e374..3f37ee0 100644 --- a/Runtime/Helper/FileHelper.cs +++ b/Runtime/Utility/FileUtility.cs @@ -2,20 +2,61 @@ using System.Collections.Generic; using System.IO; using System.Text; -using UnityEngine; using GameFrameX.ReadAssets.Runtime; +using UnityEngine; namespace GameFrameX.Runtime { /// - /// 文件帮助类。 + /// 文件相关的实用函数。 /// /// - /// File helper class. + /// File related utility functions. /// [UnityEngine.Scripting.Preserve] - public static class FileHelper + public static class FileUtility { + private static readonly string[] UnitList = new[] { "B", "KB", "MB", "GB", "TB", "PB" }; + + /// + /// 获取字节大小的可读字符串表示。 + /// + /// + /// Gets a human-readable string representation of byte size. + /// + /// 字节大小 / The byte size + /// 格式化后的字节大小字符串 / The formatted byte size string + [UnityEngine.Scripting.Preserve] + public static string GetBytesSize(long size) + { + double dSize = size; + int unitIndex = 0; + + while (dSize >= 1024 && unitIndex < UnitList.Length - 1) + { + dSize /= 1024; + unitIndex++; + } + + if (unitIndex == 0) + { + return dSize + UnitList[unitIndex]; + } + + // 格式化为保留两位小数,但去除尾部不必要的零 + string formattedSize = dSize.ToString("F2").TrimEnd('0').TrimEnd('.'); + return formattedSize + UnitList[unitIndex]; + } + + [UnityEngine.Scripting.Preserve] + public static void DeleteIfExists(string path) + { + if (System.IO.File.Exists(path)) + { + System.IO.File.Delete(path); + } + } + /// /// 获取目录下的所有文件。 /// @@ -174,9 +215,9 @@ private static bool IsAndroidReadOnlyPath(string path, out string readPath) { if (Application.platform == RuntimePlatform.Android) { - if (PathHelper.NormalizePath(path).Contains(PathHelper.AppResPath)) + if (PathUtility.GetRegularPath(path).Contains(PathUtility.AppResPath)) { - readPath = path.Substring(PathHelper.AppResPath.Length); + readPath = path.Substring(PathUtility.AppResPath.Length); return true; } } diff --git a/Runtime/Utility/Utility.File.cs.meta b/Runtime/Utility/FileUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.File.cs.meta rename to Runtime/Utility/FileUtility.cs.meta diff --git a/Runtime/Utility/GameObjectUtility.cs b/Runtime/Utility/GameObjectUtility.cs new file mode 100644 index 0000000..1ee0e31 --- /dev/null +++ b/Runtime/Utility/GameObjectUtility.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace GameFrameX.Runtime +{ + /// + /// 游戏对象帮助类。 + /// + /// + /// Game object helper class. + /// + [UnityEngine.Scripting.Preserve] + public static class GameObjectUtility + { + /// + /// 在指定场景中查找特定名称的节点。 + /// + /// 场景名称。 + /// 节点名称。 + /// 找到的节点的GameObject实例,如果没有找到返回null。 + [UnityEngine.Scripting.Preserve] + public static GameObject FindChildGamObjectByName(string nodeName, string sceneName = null) + { + return UnityEngineGameObjectExtension.FindChildGamObjectByName(nodeName, sceneName); + } + } +} \ No newline at end of file diff --git a/Runtime/Helper/GameObjectHelper.cs.meta b/Runtime/Utility/GameObjectUtility.cs.meta similarity index 100% rename from Runtime/Helper/GameObjectHelper.cs.meta rename to Runtime/Utility/GameObjectUtility.cs.meta diff --git a/Runtime/Utility/HashUtility.HmacSha256.cs b/Runtime/Utility/HashUtility.HmacSha256.cs new file mode 100644 index 0000000..ca35a7a --- /dev/null +++ b/Runtime/Utility/HashUtility.HmacSha256.cs @@ -0,0 +1,41 @@ +using System; +using System.Security.Cryptography; +using System.Text; + +namespace GameFrameX.Runtime +{ + public static partial class HashUtility + { + /// + /// HMACSHA256 哈希算法的实现。 + /// + /// + /// HMACSHA256 hash algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public static class HmacSha256 + { + /// + /// 使用提供的密钥对指定消息进行 HMACSHA256 哈希计算。 + /// + /// + /// Computes the HMACSHA256 hash of the specified message using the provided key. + /// + /// 要进行哈希计算的消息 / The message to hash + /// 用于哈希计算的密钥 / The key for hash calculation + /// Base64 编码的哈希值 / The Base64 encoded hash value + [UnityEngine.Scripting.Preserve] + public static string Hash(string message, string key) + { + byte[] keyBytes = Encoding.UTF8.GetBytes(key); + byte[] messageBytes = Encoding.UTF8.GetBytes(message); + + using (var hmac = new HMACSHA256(keyBytes)) + { + byte[] hashBytes = hmac.ComputeHash(messageBytes); + return Convert.ToBase64String(hashBytes); + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.HMACSha256.cs.meta b/Runtime/Utility/HashUtility.HmacSha256.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Hash.HMACSha256.cs.meta rename to Runtime/Utility/HashUtility.HmacSha256.cs.meta diff --git a/Runtime/Utility/HashUtility.Md5.cs b/Runtime/Utility/HashUtility.Md5.cs new file mode 100644 index 0000000..2c9687d --- /dev/null +++ b/Runtime/Utility/HashUtility.Md5.cs @@ -0,0 +1,100 @@ +using System; +using System.IO; +using System.Text; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + public static partial class HashUtility + { + /// + /// MD5 哈希算法的实现。 + /// + /// + /// MD5 hash algorithm implementation. + /// + [Preserve] + public static class Md5 + { + /// + /// 获取字符串的 MD5 哈希值。 + /// + /// + /// Gets the MD5 hash value of the string. + /// + /// 要计算哈希的字符串 / The string to hash + /// MD5 哈希值 / The MD5 hash value + [Preserve] + public static string Hash(string input) + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + var data = md5.ComputeHash(Encoding.UTF8.GetBytes(input)); + return ToHash(data); + } + } + + /// + /// 获取流的 MD5 哈希值。 + /// + /// + /// Gets the MD5 hash value of the stream. + /// + /// 要计算哈希的流 / The stream to hash + /// MD5 哈希值 / The MD5 hash value + [Preserve] + public static string Hash(Stream input) + { + using (var md5 = System.Security.Cryptography.MD5.Create()) + { + var data = md5.ComputeHash(input); + return ToHash(data); + } + } + + /// + /// 验证 MD5 哈希值是否一致。 + /// + /// + /// Verifies if the MD5 hash values match. + /// + /// 要验证的哈希值 / The hash value to verify + /// 目标哈希值 / The target hash value + /// 如果一致则返回 true,否则返回 false / Returns true if they match, otherwise false + [Preserve] + public static bool IsVerify(string input, string hash) + { + var comparer = StringComparer.OrdinalIgnoreCase; + return 0 == comparer.Compare(input, hash); + } + + static string ToHash(byte[] data) + { + var sb = new StringBuilder(); + foreach (var t in data) + { + sb.Append(t.ToString("x2")); + } + + return sb.ToString(); + } + + /// + /// 获取指定文件路径的 MD5 哈希值。 + /// + /// + /// Gets the MD5 hash value of the file at the specified path. + /// + /// 文件路径 / The file path + /// MD5 哈希值 / The MD5 hash value + [Preserve] + public static string FileHash(string filePath) + { + using (var file = new FileStream(filePath, FileMode.Open)) + { + return Hash(file); + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.Md5.cs.meta b/Runtime/Utility/HashUtility.Md5.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Hash.Md5.cs.meta rename to Runtime/Utility/HashUtility.Md5.cs.meta diff --git a/Runtime/Utility/HashUtility.MurmurHash3.cs b/Runtime/Utility/HashUtility.MurmurHash3.cs new file mode 100644 index 0000000..766abf4 --- /dev/null +++ b/Runtime/Utility/HashUtility.MurmurHash3.cs @@ -0,0 +1,110 @@ +using System; + +namespace GameFrameX.Runtime +{ + public static partial class HashUtility + { + /// + /// MurmurHash3 哈希算法的实现。 + /// + /// + /// MurmurHash3 hash algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public static class MurmurHash3 + { + /// + /// 计算给定字符串的 MurmurHash3 哈希值。 + /// + /// + /// Computes the MurmurHash3 hash value of the given string. + /// + /// 要哈希的字符串 / The string to hash + /// 哈希种子,默认为 27 / The hash seed, default is 27 + /// 计算得到的哈希值 / The computed hash value + [UnityEngine.Scripting.Preserve] + public static uint Hash(string str, uint seed = 27) + { + var data = System.Text.Encoding.UTF8.GetBytes(str); + return Hash(data, (uint)data.Length, seed); + } + + private static uint Hash(byte[] data, uint length, uint seed) + { + uint nBlocks = length >> 2; + + uint h1 = seed; + + const uint c1 = 0xcc9e2d51; + const uint c2 = 0x1b873593; + + //---------- + // body + + int i = 0; + + for (uint j = nBlocks; j > 0; --j) + { + uint k1L = BitConverter.ToUInt32(data, i); + + k1L *= c1; + k1L = Rotl32(k1L, 15); + k1L *= c2; + + h1 ^= k1L; + h1 = Rotl32(h1, 13); + h1 = h1 * 5 + 0xe6546b64; + + i += 4; + } + + //---------- + // tail + + nBlocks <<= 2; + + uint k1 = 0; + + uint tailLength = length & 3; + + if (tailLength == 3) + k1 ^= (uint)data[2 + nBlocks] << 16; + if (tailLength >= 2) + k1 ^= (uint)data[1 + nBlocks] << 8; + if (tailLength >= 1) + { + k1 ^= data[nBlocks]; + k1 *= c1; + k1 = Rotl32(k1, 15); + k1 *= c2; + h1 ^= k1; + } + + //---------- + // finalization + + h1 ^= length; + + h1 = Fmix32(h1); + + return h1; + } + + static uint Fmix32(uint h) + { + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + + return h; + } + + static uint Rotl32(uint x, byte r) + { + return x << r | x >> 32 - r; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.MurmurHash3.cs.meta b/Runtime/Utility/HashUtility.MurmurHash3.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Hash.MurmurHash3.cs.meta rename to Runtime/Utility/HashUtility.MurmurHash3.cs.meta diff --git a/Runtime/Utility/HashUtility.Sha1.cs b/Runtime/Utility/HashUtility.Sha1.cs new file mode 100644 index 0000000..ffb4345 --- /dev/null +++ b/Runtime/Utility/HashUtility.Sha1.cs @@ -0,0 +1,57 @@ +using System; +using System.Text; + +namespace GameFrameX.Runtime +{ + public static partial class HashUtility + { + /// + /// SHA1 哈希算法的实现。 + /// + /// + /// SHA1 hash algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public static class Sha1 + { + + /// + /// 计算给定内容的 SHA1 哈希值,使用 UTF-8 编码。 + /// + /// + /// Computes the SHA1 hash value of the given content using UTF-8 encoding. + /// + /// 要计算哈希值的内容 / The content to hash + /// 返回计算得到的 SHA1 哈希值 / The computed SHA1 hash value + [UnityEngine.Scripting.Preserve] + public static string Hash(string content) + { + return Hash(content, Encoding.UTF8); + } + + /// + /// 使用指定编码计算 SHA1 哈希值。 + /// + /// + /// Computes the SHA1 hash value using the specified encoding. + /// + /// 要计算哈希值的内容 / The content to hash + /// 用于编码的 Encoding 对象 / The encoding to use + /// 返回计算得到的 SHA1 哈希值 / The computed SHA1 hash value + [UnityEngine.Scripting.Preserve] + public static string Hash(string content, Encoding encode) + { + //创建SHA1对象 + using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider()) + { + //将待加密字符串转为byte类型 + var bytesIn = encode.GetBytes(content); + var bytesOut = sha1.ComputeHash(bytesIn); + var result = BitConverter.ToString(bytesOut); //将运算结果转为string类型 + result = result.Replace("-", string.Empty).ToLower(); + return result; + } + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.Sha1.cs.meta b/Runtime/Utility/HashUtility.Sha1.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Hash.Sha1.cs.meta rename to Runtime/Utility/HashUtility.Sha1.cs.meta diff --git a/Runtime/Utility/HashUtility.XxHash.cs b/Runtime/Utility/HashUtility.XxHash.cs new file mode 100644 index 0000000..4b3b976 --- /dev/null +++ b/Runtime/Utility/HashUtility.XxHash.cs @@ -0,0 +1,366 @@ +using System; +using System.Runtime.CompilerServices; +using System.Text; + +namespace GameFrameX.Runtime +{ + public static partial class HashUtility + { + /// + /// XXHash 哈希算法的实现。 + /// + /// + /// XXHash hash algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + public static class XxHash + { + /// + /// 计算给定字节数组的32位哈希值。 + /// + /// 要计算哈希值的字节数组。 + /// 返回计算得到的32位哈希值。 + [UnityEngine.Scripting.Preserve] + public static uint Hash32(byte[] buffer) + { + return XxHashHelper.Hash32(buffer); + } + + /// + /// 计算给定字符串的32位哈希值。 + /// + /// 要计算哈希值的字符串。 + /// 返回计算得到的32位哈希值。 + [UnityEngine.Scripting.Preserve] + public static uint Hash32(string text) + { + return XxHashHelper.Hash32(text); + } + + /// + /// 计算给定类型的32位哈希值。 + /// + /// 要计算哈希值的类型。 + /// 返回计算得到的32位哈希值。 + [UnityEngine.Scripting.Preserve] + public static uint Hash32(Type type) + { + return XxHashHelper.Hash32(type); + } + + /// + /// 计算给定泛型类型的32位哈希值。 + /// + /// 要计算哈希值的泛型类型。 + /// 返回计算得到的32位哈希值。 + [UnityEngine.Scripting.Preserve] + public static uint Hash32() + { + return XxHashHelper.Hash32(); + } + + /// + /// 计算给定字节数组的64位哈希值。 + /// + /// 要计算哈希值的字节数组。 + /// 返回计算得到的64位哈希值。 + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(byte[] buffer) + { + return XxHashHelper.Hash64(buffer); + } + + /// + /// 计算给定字符串的64位哈希值。 + /// + /// 要计算哈希值的字符串。 + /// 返回计算得到的64位哈希值。 + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(string text) + { + return XxHashHelper.Hash64(text); + } + + /// + /// 计算给定类型的64位哈希值。 + /// + /// 要计算哈希值的类型。 + /// 返回计算得到的64位哈希值。 + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(Type type) + { + return XxHashHelper.Hash64(type); + } + + /// + /// 计算给定泛型类型的64位哈希值。 + /// + /// 要计算哈希值的泛型类型。 + /// 返回计算得到的64位哈希值。 + [UnityEngine.Scripting.Preserve] + public static ulong Hash64() + { + return XxHashHelper.Hash64(); + } + } + + /// + /// XXHash 计算帮助类。 + /// + /// + /// XXHash calculation helper class. + /// + static class XxHashHelper + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static unsafe uint Hash32(byte* input, int length, uint seed = 0) + { + unchecked + { + const uint prime1 = 2654435761u; + const uint prime2 = 2246822519u; + const uint prime3 = 3266489917u; + const uint prime4 = 0668265263u; + const uint prime5 = 0374761393u; + + uint hash = seed + prime5; + + if (length >= 16) + { + uint val0 = seed + prime1 + prime2; + uint val1 = seed + prime2; + uint val2 = seed + 0; + uint val3 = seed - prime1; + + int count = length >> 4; + for (int i = 0; i < count; i++) + { + var pos0 = *(uint*)(input + 0); + var pos1 = *(uint*)(input + 4); + var pos2 = *(uint*)(input + 8); + var pos3 = *(uint*)(input + 12); + + val0 += pos0 * prime2; + val0 = (val0 << 13) | (val0 >> (32 - 13)); + val0 *= prime1; + + val1 += pos1 * prime2; + val1 = (val1 << 13) | (val1 >> (32 - 13)); + val1 *= prime1; + + val2 += pos2 * prime2; + val2 = (val2 << 13) | (val2 >> (32 - 13)); + val2 *= prime1; + + val3 += pos3 * prime2; + val3 = (val3 << 13) | (val3 >> (32 - 13)); + val3 *= prime1; + + input += 16; + } + + hash = ((val0 << 01) | (val0 >> (32 - 01))) + + ((val1 << 07) | (val1 >> (32 - 07))) + + ((val2 << 12) | (val2 >> (32 - 12))) + + ((val3 << 18) | (val3 >> (32 - 18))); + } + + hash += (uint)length; + + length &= 15; + while (length >= 4) + { + hash += *(uint*)input * prime3; + hash = ((hash << 17) | (hash >> (32 - 17))) * prime4; + input += 4; + length -= 4; + } + + while (length > 0) + { + hash += *input * prime5; + hash = ((hash << 11) | (hash >> (32 - 11))) * prime1; + ++input; + --length; + } + + hash ^= hash >> 15; + hash *= prime2; + hash ^= hash >> 13; + hash *= prime3; + hash ^= hash >> 16; + + return hash; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static unsafe ulong Hash64(byte* input, int length, uint seed = 0) + { + unchecked + { + const ulong prime1 = 11400714785074694791ul; + const ulong prime2 = 14029467366897019727ul; + const ulong prime3 = 01609587929392839161ul; + const ulong prime4 = 09650029242287828579ul; + const ulong prime5 = 02870177450012600261ul; + + ulong hash = seed + prime5; + + if (length >= 32) + { + ulong val0 = seed + prime1 + prime2; + ulong val1 = seed + prime2; + ulong val2 = seed + 0; + ulong val3 = seed - prime1; + + int count = length >> 5; + for (int i = 0; i < count; i++) + { + var pos0 = *(ulong*)(input + 0); + var pos1 = *(ulong*)(input + 8); + var pos2 = *(ulong*)(input + 16); + var pos3 = *(ulong*)(input + 24); + + val0 += pos0 * prime2; + val0 = (val0 << 31) | (val0 >> (64 - 31)); + val0 *= prime1; + + val1 += pos1 * prime2; + val1 = (val1 << 31) | (val1 >> (64 - 31)); + val1 *= prime1; + + val2 += pos2 * prime2; + val2 = (val2 << 31) | (val2 >> (64 - 31)); + val2 *= prime1; + + val3 += pos3 * prime2; + val3 = (val3 << 31) | (val3 >> (64 - 31)); + val3 *= prime1; + + input += 32; + } + + hash = ((val0 << 01) | (val0 >> (64 - 01))) + + ((val1 << 07) | (val1 >> (64 - 07))) + + ((val2 << 12) | (val2 >> (64 - 12))) + + ((val3 << 18) | (val3 >> (64 - 18))); + + val0 *= prime2; + val0 = (val0 << 31) | (val0 >> (64 - 31)); + val0 *= prime1; + hash ^= val0; + hash = hash * prime1 + prime4; + + val1 *= prime2; + val1 = (val1 << 31) | (val1 >> (64 - 31)); + val1 *= prime1; + hash ^= val1; + hash = hash * prime1 + prime4; + + val2 *= prime2; + val2 = (val2 << 31) | (val2 >> (64 - 31)); + val2 *= prime1; + hash ^= val2; + hash = hash * prime1 + prime4; + + val3 *= prime2; + val3 = (val3 << 31) | (val3 >> (64 - 31)); + val3 *= prime1; + hash ^= val3; + hash = hash * prime1 + prime4; + } + + hash += (ulong)length; + + length &= 31; + while (length >= 8) + { + ulong lane = *(ulong*)input * prime2; + lane = ((lane << 31) | (lane >> (64 - 31))) * prime1; + hash ^= lane; + hash = ((hash << 27) | (hash >> (64 - 27))) * prime1 + prime4; + input += 8; + length -= 8; + } + + if (length >= 4) + { + hash ^= *(uint*)input * prime1; + hash = ((hash << 23) | (hash >> (64 - 23))) * prime2 + prime3; + input += 4; + length -= 4; + } + + while (length > 0) + { + hash ^= *input * prime5; + hash = ((hash << 11) | (hash >> (64 - 11))) * prime1; + ++input; + --length; + } + + hash ^= hash >> 33; + hash *= prime2; + hash ^= hash >> 29; + hash *= prime3; + hash ^= hash >> 32; + + return hash; + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static uint Hash32(byte[] buffer) + { + int length = buffer.Length; + unsafe + { + fixed (byte* pointer = buffer) + { + return Hash32(pointer, length); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static uint Hash32(string text) => Hash32(Encoding.UTF8.GetBytes(text)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static uint Hash32(Type type) => Hash32(type.FullName); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static uint Hash32() => Hash32(typeof(T)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(byte[] buffer) + { + int length = buffer.Length; + unsafe + { + fixed (byte* pointer = buffer) + { + return Hash64(pointer, length); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(string text) => Hash64(Encoding.UTF8.GetBytes(text)); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static ulong Hash64(Type type) => Hash64(type.FullName); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnityEngine.Scripting.Preserve] + public static ulong Hash64() => Hash64(typeof(T)); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.XxHash.cs.meta b/Runtime/Utility/HashUtility.XxHash.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Hash.XxHash.cs.meta rename to Runtime/Utility/HashUtility.XxHash.cs.meta diff --git a/Runtime/Utility/IdGeneratorUtility.cs b/Runtime/Utility/IdGeneratorUtility.cs new file mode 100644 index 0000000..8942413 --- /dev/null +++ b/Runtime/Utility/IdGeneratorUtility.cs @@ -0,0 +1,62 @@ +using System; +using System.Threading; + +namespace GameFrameX.Runtime +{ + /// + /// ID 生成器相关的实用函数。 + /// + /// + /// ID generator related utility functions. + /// + /// + /// ID 生成器相关的实用函数。 + /// + /// + /// ID generator related utility functions. + /// + [UnityEngine.Scripting.Preserve] + public static class IdGeneratorUtility + { + /// + /// 全局UTC起始时间,用作计数器的基准时间点。 + /// 设置为2020年1月1日0时0分0秒(UTC)。 + /// + /// + /// Global UTC start time, used as the reference point for the counter. + /// Set to January 1, 2020, 00:00:00 (UTC). + /// + public static readonly DateTime UtcTimeStart = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + // 共享计数器 + private static long _counter = (long)(DateTime.UtcNow - UtcTimeStart).TotalSeconds; + private static int _intCounter = (int)(DateTime.UtcNow - UtcTimeStart).TotalSeconds; + + /// + /// 使用 Interlocked.Increment 生成唯一的长整型ID。 + /// + /// + /// Generates a unique long integer ID using Interlocked.Increment. + /// + /// 返回一个唯一的长整型ID / A unique long integer ID + [UnityEngine.Scripting.Preserve] + public static long GetNextUniqueId() + { + // 原子性地递增值 + return Interlocked.Increment(ref _counter); + } + + /// + /// 使用 Interlocked.Increment 生成唯一的整型ID。 + /// + /// + /// Generates a unique integer ID using Interlocked.Increment. + /// + /// 返回一个唯一的整型ID / A unique integer ID + [UnityEngine.Scripting.Preserve] + public static int GetNextUniqueIntId() + { + return Interlocked.Increment(ref _intCounter); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.IdGenerator.cs.meta b/Runtime/Utility/IdGeneratorUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.IdGenerator.cs.meta rename to Runtime/Utility/IdGeneratorUtility.cs.meta diff --git a/Runtime/Utility/Log.cs b/Runtime/Utility/Log.cs index 4eca854..dd6a59b 100644 --- a/Runtime/Utility/Log.cs +++ b/Runtime/Utility/Log.cs @@ -31,7 +31,6 @@ // Official Documentation: https://gameframex.doc.alianblank.com/ // ========================================================================================== -using GameFrameX; using System.Diagnostics; namespace GameFrameX.Runtime diff --git a/Runtime/Utility/MarshalUtility.cs b/Runtime/Utility/MarshalUtility.cs new file mode 100644 index 0000000..c4cea35 --- /dev/null +++ b/Runtime/Utility/MarshalUtility.cs @@ -0,0 +1,294 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; + +namespace GameFrameX.Runtime +{ + /// + /// Marshal 相关的实用函数。 + /// + /// + /// Marshal related utility functions. + /// + [UnityEngine.Scripting.Preserve] + public static class MarshalUtility + { + private const int BlockSize = 1024 * 4; + private static IntPtr _cachedHGlobalPtr = IntPtr.Zero; + private static int _cachedHGlobalSize; + private static readonly object Lock = new object(); + + /// + /// 获取缓存的从进程的非托管内存中分配的内存的大小。 + /// + [UnityEngine.Scripting.Preserve] + public static int CachedHGlobalSize + { + get { return _cachedHGlobalSize; } + } + + /// + /// 确保从进程的非托管内存中分配足够大小的内存并缓存。 + /// + /// 要确保从进程的非托管内存中分配内存的大小。 + [UnityEngine.Scripting.Preserve] + public static void EnsureCachedHGlobalSize(int ensureSize) + { + if (ensureSize < 0) + { + throw new GameFrameworkException("Ensure size is invalid."); + } + + lock (Lock) + { + if (_cachedHGlobalPtr == IntPtr.Zero || _cachedHGlobalSize < ensureSize) + { + FreeCachedHGlobal(); + var size = (ensureSize - 1 + BlockSize) / BlockSize * BlockSize; + _cachedHGlobalPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(size); + _cachedHGlobalSize = size; + } + } + } + + /// + /// 释放缓存的从进程的非托管内存中分配的内存。 + /// + [UnityEngine.Scripting.Preserve] + public static void FreeCachedHGlobal() + { + lock (Lock) + { + if (_cachedHGlobalPtr != IntPtr.Zero) + { + System.Runtime.InteropServices.Marshal.FreeHGlobal(_cachedHGlobalPtr); + _cachedHGlobalPtr = IntPtr.Zero; + _cachedHGlobalSize = 0; + } + } + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 存储转换结果的二进制流。 + [UnityEngine.Scripting.Preserve] + public static byte[] StructureToBytes(T structure) + { + return StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T))); + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 要转换的对象的大小。 + /// 存储转换结果的二进制流。 + [UnityEngine.Scripting.Preserve] + internal static byte[] StructureToBytes(T structure, int structureSize) + { + if (structureSize < 0) + { + throw new GameFrameworkException("Structure size is invalid."); + } + + var result = new byte[structureSize]; + lock (Lock) + { + EnsureCachedHGlobalSize(structureSize); + System.Runtime.InteropServices.Marshal.StructureToPtr(structure, _cachedHGlobalPtr, true); + System.Runtime.InteropServices.Marshal.Copy(_cachedHGlobalPtr, result, 0, structureSize); + } + + return result; + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 存储转换结果的二进制流。 + [UnityEngine.Scripting.Preserve] + public static void StructureToBytes(T structure, byte[] result) + { + StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), result, 0); + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 要转换的对象的大小。 + /// 存储转换结果的二进制流。 + [UnityEngine.Scripting.Preserve] + internal static void StructureToBytes(T structure, int structureSize, byte[] result) + { + StructureToBytes(structure, structureSize, result, 0); + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 存储转换结果的二进制流。 + /// 写入存储转换结果的二进制流的起始位置。 + [UnityEngine.Scripting.Preserve] + public static void StructureToBytes(T structure, byte[] result, int startIndex) + { + StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), result, startIndex); + } + + /// + /// 将数据从对象转换为二进制流。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象。 + /// 要转换的对象的大小。 + /// 存储转换结果的二进制流。 + /// 写入存储转换结果的二进制流的起始位置。 + [UnityEngine.Scripting.Preserve] + internal static void StructureToBytes(T structure, int structureSize, byte[] result, int startIndex) + { + if (structureSize < 0) + { + throw new GameFrameworkException("Structure size is invalid."); + } + + if (result == null) + { + throw new GameFrameworkException("Result is invalid."); + } + + if (startIndex < 0) + { + throw new GameFrameworkException("Start index is invalid."); + } + + if (startIndex + structureSize > result.Length) + { + throw new GameFrameworkException("Result length is not enough."); + } + + lock (Lock) + { + EnsureCachedHGlobalSize(structureSize); + System.Runtime.InteropServices.Marshal.StructureToPtr(structure, _cachedHGlobalPtr, true); + System.Runtime.InteropServices.Marshal.Copy(_cachedHGlobalPtr, result, startIndex, structureSize); + } + } + + /// + /// 将数据从二进制流转换为对象。 + /// + /// 要转换的对象的类型。 + /// 要转换的二进制流。 + /// 存储转换结果的对象。 + [UnityEngine.Scripting.Preserve] + public static T BytesToStructure(byte[] buffer) + { + return BytesToStructure(System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), buffer, 0); + } + + /// + /// 将数据从二进制流转换为对象。 + /// + /// 要转换的对象的类型。 + /// 要转换的二进制流。 + /// 读取要转换的二进制流的起始位置。 + /// 存储转换结果的对象。 + [UnityEngine.Scripting.Preserve] + public static T BytesToStructure(byte[] buffer, int startIndex) + { + return BytesToStructure(System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), buffer, startIndex); + } + + /// + /// 将数据从二进制流转换为对象。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象的大小。 + /// 要转换的二进制流。 + /// 存储转换结果的对象。 + [UnityEngine.Scripting.Preserve] + internal static T BytesToStructure(int structureSize, byte[] buffer) + { + return BytesToStructure(structureSize, buffer, 0); + } + + /// + /// 将数据从二进制流转换为对象。 + /// + /// 要转换的对象的类型。 + /// 要转换的对象的大小。 + /// 要转换的二进制流。 + /// 读取要转换的二进制流的起始位置。 + /// 存储转换结果的对象。 + [UnityEngine.Scripting.Preserve] + internal static T BytesToStructure(int structureSize, byte[] buffer, int startIndex) + { + if (structureSize < 0) + { + throw new GameFrameworkException("Structure size is invalid."); + } + + if (buffer == null) + { + throw new GameFrameworkException("Buffer is invalid."); + } + + if (startIndex < 0) + { + throw new GameFrameworkException("Start index is invalid."); + } + + if (startIndex + structureSize > buffer.Length) + { + throw new GameFrameworkException("Buffer length is not enough."); + } + + lock (Lock) + { + EnsureCachedHGlobalSize(structureSize); + System.Runtime.InteropServices.Marshal.Copy(buffer, startIndex, _cachedHGlobalPtr, structureSize); + return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(_cachedHGlobalPtr, typeof(T)); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Marshal.cs.meta b/Runtime/Utility/MarshalUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Marshal.cs.meta rename to Runtime/Utility/MarshalUtility.cs.meta diff --git a/Runtime/Helper/MathHelper.cs b/Runtime/Utility/MathUtility.cs similarity index 99% rename from Runtime/Helper/MathHelper.cs rename to Runtime/Utility/MathUtility.cs index 0517e24..b6e45e2 100644 --- a/Runtime/Helper/MathHelper.cs +++ b/Runtime/Utility/MathUtility.cs @@ -10,7 +10,7 @@ namespace GameFrameX.Runtime /// Math helper class. /// [UnityEngine.Scripting.Preserve] - public static class MathHelper + public static class MathUtility { /// /// 检查两个矩形是否相交。 diff --git a/Runtime/Helper/MathHelper.cs.meta b/Runtime/Utility/MathUtility.cs.meta similarity index 100% rename from Runtime/Helper/MathHelper.cs.meta rename to Runtime/Utility/MathUtility.cs.meta diff --git a/Runtime/Utility/NetworkUtility.cs b/Runtime/Utility/NetworkUtility.cs new file mode 100644 index 0000000..2983b05 --- /dev/null +++ b/Runtime/Utility/NetworkUtility.cs @@ -0,0 +1,239 @@ +using System.Collections.Generic; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using UnityEngine; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + /// + /// 网络相关的实用函数。 + /// + /// + /// Network related utility functions. + /// + [Preserve] + public static class NetworkUtility + { + /// + /// 获取第一个可用的端口号 + /// + /// 起始端口号 + /// 结束端口号 + /// 返回第一个可用的端口号,如果没有可用端口则返回-1 + [Preserve] + public static int GetFirstAvailablePort(int startPort = 667, int maxPort = 65535) + { + for (int i = startPort; i < maxPort; i++) + { + if (PortIsAvailable(i)) return i; + } + + return -1; + } + + /// + /// 获取操作系统已用的端口号 + /// + /// 返回一个包含所有已用端口号的列表 + [Preserve] + public static List PortIsUsed() + { + //获取本地计算机的网络连接和通信统计数据的信息 + var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); + + //返回本地计算机上的所有Tcp监听程序 + var ipsTcp = ipGlobalProperties.GetActiveTcpListeners(); + + //返回本地计算机上的所有UDP监听程序 + var ipsUDP = ipGlobalProperties.GetActiveUdpListeners(); + + //返回本地计算机上的Internet协议版本4(IPV4 传输控制协议(TCP)连接的信息。 + var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); + + var allPorts = new List(); + foreach (var ep in ipsTcp) + { + allPorts.Add(ep.Port); + } + + foreach (var ep in ipsUDP) + { + allPorts.Add(ep.Port); + } + + foreach (var conn in tcpConnInfoArray) + { + allPorts.Add(conn.LocalEndPoint.Port); + } + + return allPorts; + } + + /// + /// 检查指定端口是否已用 + /// + /// 要检查的端口号 + /// 如果端口可用则返回true,否则返回false + [Preserve] + public static bool PortIsAvailable(int port) + { + var isAvailable = true; + + var portUsed = PortIsUsed(); + + foreach (int p in portUsed) + { + if (p == port) + { + isAvailable = false; + break; + } + } + + return isAvailable; + } + + /// + /// 获取域名的IpV4 地址 + /// + /// 域名 + /// 返回域名的IPv4地址,如果没有则返回空字符串 + [Preserve] + public static string GetHostIPv4(string domainName) + { + var iPHostEntry = Dns.GetHostEntry(domainName); + foreach (var address in iPHostEntry.AddressList) + { + if (address.AddressFamily == AddressFamily.InterNetwork) + { + return address.ToString(); + } + } + + return string.Empty; + } + + /// + /// 获取域名的IpV6 地址 + /// + /// 域名 + /// 返回域名的IPv4地址,如果没有则返回空字符串 + [Preserve] + public static string GetHostIPv6(string domainName) + { + var iPHostEntry = Dns.GetHostEntry(domainName); + foreach (var address in iPHostEntry.AddressList) + { + if (address.AddressFamily == AddressFamily.InterNetworkV6) + { + return address.ToString(); + } + } + + return string.Empty; + } + + /// + /// 获取本机ip地址 + /// + /// 返回本机的IPv4地址,如果没有则返回空字符串 + [Preserve] + public static string GetIP() + { + var hostName = Dns.GetHostName(); + var iPHostEntry = Dns.GetHostEntry(hostName); + foreach (var address in iPHostEntry.AddressList) + { + if (address.AddressFamily == AddressFamily.InterNetwork) + { + return address.ToString(); + } + } + + return string.Empty; + } + + /// + /// 获取本机的IP地址列表 + /// + /// 返回本机所有IP地址的数组 / Array of all local IP addresses + [Preserve] + public static string[] GetAddressIPs() + { + var list = Dns.GetHostEntry(Dns.GetHostName()).AddressList; + string[] addressIPs = new string[list.Length]; + for (var index = 0; index < list.Length; index++) + { + addressIPs[index] = list[index].ToString(); + } + + return addressIPs; + } + + [Preserve] + public static (AddressFamily, string) GetIPv6Address(string host) + { + var addresses = Dns.GetHostAddresses(host); + + foreach (var ipAddress in addresses) + { + if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) + { + return (AddressFamily.InterNetworkV6, ipAddress.ToString()); + } + } + + foreach (var ipAddress in addresses) + { + if (ipAddress.AddressFamily == AddressFamily.InterNetwork) + { + return (AddressFamily.InterNetwork, ipAddress.ToString()); + } + } + + return (AddressFamily.InterNetwork, host); + } + + /// + /// 获取当前是否有网络连接。 + /// + /// + /// Gets whether the device has network connectivity. + /// + /// 如果有网络连接则为 true;否则为 false / true if network is reachable; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool IsReachable() + { + return Application.internetReachability != NetworkReachability.NotReachable; + } + + /// + /// 获取当前是否通过WiFi连接网络。 + /// + /// + /// Gets whether the device is connected via WiFi (local area network). + /// + /// 如果是WiFi连接则为 true;否则为 false / true if on WiFi; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool IsWifi() + { + return Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork; + } + + /// + /// 获取当前是否通过移动数据网络连接。 + /// + /// + /// Gets whether the device is connected via cellular data network. + /// + /// 如果是移动网络则为 true;否则为 false / true if on cellular data; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool IsViaCarrierData() + { + //当用户使用移动网络时 + return Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork; + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Net.cs.meta b/Runtime/Utility/NetworkUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Net.cs.meta rename to Runtime/Utility/NetworkUtility.cs.meta diff --git a/Runtime/Utility/ObjectUtility.cs b/Runtime/Utility/ObjectUtility.cs new file mode 100644 index 0000000..b12ed53 --- /dev/null +++ b/Runtime/Utility/ObjectUtility.cs @@ -0,0 +1,27 @@ +namespace GameFrameX.Runtime +{ + /// + /// Object 对象工具类。 + /// + /// + /// Object utility class. + /// + [UnityEngine.Scripting.Preserve] + public static class ObjectUtility + { + /// + /// 交换两个对象的值。 + /// + /// + /// Swaps the values of two objects. + /// + /// 第一个对象的引用 / Reference to the first object + /// 第二个对象的引用 / Reference to the second object + /// 对象的类型 / The type of the objects + [UnityEngine.Scripting.Preserve] + public static void Swap(ref T t1, ref T t2) + { + (t1, t2) = (t2, t1); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Object.cs.meta b/Runtime/Utility/ObjectUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Object.cs.meta rename to Runtime/Utility/ObjectUtility.cs.meta diff --git a/Runtime/Utility/PathUtility.cs b/Runtime/Utility/PathUtility.cs new file mode 100644 index 0000000..5a11836 --- /dev/null +++ b/Runtime/Utility/PathUtility.cs @@ -0,0 +1,221 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.Text; +using UnityEngine; + +namespace GameFrameX.Runtime +{ + /// + /// 路径相关的实用函数。 + /// + /// + /// Path related utility functions. + /// + [UnityEngine.Scripting.Preserve] + public static class PathUtility + { + /// + /// 获取规范的路径。 + /// + /// + /// Gets the regularized path. + /// + /// 要规范的路径 / The path to regularize + /// 规范的路径 / The regularized path + [UnityEngine.Scripting.Preserve] + public static string GetRegularPath(string path) + { + if (path == null) + { + return null; + } + + return path.Replace('\\', '/'); + } + + /// + /// 获取远程格式的路径(带有file:// 或 http:// 前缀)。 + /// + /// + /// Gets the remote format path (with file:// or http:// prefix). + /// + /// 原始路径 / The original path + /// 远程格式路径 / The remote format path + [UnityEngine.Scripting.Preserve] + public static string GetRemotePath(string path) + { + string regularPath = GetRegularPath(path); + if (regularPath == null) + { + return null; + } + + return regularPath.Contains("://") ? regularPath : ("file:///" + regularPath).Replace("file:////", "file:///"); + } + + [UnityEngine.Scripting.Preserve] + public static void CheckPath(string path, bool isFilePath = true, bool forceMode = false) + { + if (string.IsNullOrEmpty(path)) + { + return; + } + + string finalDir; + { + if (isFilePath) + { + finalDir = System.IO.Path.GetDirectoryName(path); + if (forceMode) + { + FileUtility.DeleteIfExists(path); + } + } + else + { + finalDir = path; + if (forceMode) + { + DirectoryUtility.DeleteIfExists(path); + } + } + } + + DirectoryUtility.CreateIfNotExists(finalDir); + } + + /// + /// 应用程序外部资源路径存放路径(热更新资源路径)。 + /// + /// + /// Application external resource path (hot update resource path). + /// + [UnityEngine.Scripting.Preserve] + public static string AppHotfixResPath + { + get + { + string game = Application.productName; + string path = $"{Application.persistentDataPath}/{game}/"; + return path; + } + } + + /// + /// 应用程序内部资源路径存放路径 + /// + [UnityEngine.Scripting.Preserve] + public static string AppResPath + { + get { return PathUtility.GetRegularPath(Application.streamingAssetsPath); } + } + + /// + /// 应用程序内部资源路径存放路径(www/webrequest专用) + /// + [UnityEngine.Scripting.Preserve] + public static string AppResPath4Web + { + get + { +#if UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_EDITOR + return $"file://{Application.streamingAssetsPath}"; +#else + return PathUtility.GetRegularPath(Application.streamingAssetsPath); +#endif + } + } + + /// + /// 获取平台名称 + /// + /// + /// 此属性已废弃,请使用 ApplicationUtility.PlatformName 替代 + /// + [UnityEngine.Scripting.Preserve] + [Obsolete("此方法已废弃,请使用 ApplicationUtility.PlatformName 替代")] + public static string GetPlatformName + { + get + { +#if UNITY_ANDROID + return $"Android"; +#elif UNITY_STANDALONE_OSX + return $"MacOs"; +#elif UNITY_IOS || UNITY_IPHONE + return $"iOS"; +#elif UNITY_WEBGL + return $"WebGL"; +#elif UNITY_STANDALONE_WIN + return $"Windows"; +#else + return string.Empty; +#endif + } + } + + /// + /// 拼接路径 + /// + /// + /// + [UnityEngine.Scripting.Preserve] + public static string Combine(params string[] paths) + { + var sb = new StringBuilder(); + const string separatorA = "/"; + const string separatorB = "\\"; + for (var index = 0; index < paths.Length - 1; index++) + { + var path = paths[index]; + sb.Append(path); + if (path.EndsWithFast(separatorA) || path.EndsWithFast(separatorB)) + { + continue; + } + + if (path.StartsWithFast(separatorA) || path.StartsWithFast(separatorB)) + { + continue; + } + + sb.Append(separatorA); + } + + sb.Append(paths[paths.Length - 1]); + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Path.cs.meta b/Runtime/Utility/PathUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Path.cs.meta rename to Runtime/Utility/PathUtility.cs.meta diff --git a/Runtime/Helper/PositionHelper.cs b/Runtime/Utility/PositionUtility.cs similarity index 99% rename from Runtime/Helper/PositionHelper.cs rename to Runtime/Utility/PositionUtility.cs index 07e0658..d05061e 100644 --- a/Runtime/Helper/PositionHelper.cs +++ b/Runtime/Utility/PositionUtility.cs @@ -10,7 +10,7 @@ namespace GameFrameX.Runtime /// Position helper class for coordinate transformations. /// [UnityEngine.Scripting.Preserve] - public static class PositionHelper + public static class PositionUtility { /// /// 将二维坐标转换为三维坐标,Y轴设为0。 diff --git a/Runtime/Helper/PositionHelper.cs.meta b/Runtime/Utility/PositionUtility.cs.meta similarity index 100% rename from Runtime/Helper/PositionHelper.cs.meta rename to Runtime/Utility/PositionUtility.cs.meta diff --git a/Runtime/Utility/RandomUtility.cs b/Runtime/Utility/RandomUtility.cs new file mode 100644 index 0000000..ea928b2 --- /dev/null +++ b/Runtime/Utility/RandomUtility.cs @@ -0,0 +1,179 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.Threading; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + /// + /// 随机相关的实用函数。 + /// + /// + /// Random related utility functions. + /// + [Preserve] + public static class RandomUtility + { + private static int s_Seed = (int)DateTime.UtcNow.Ticks; + private static ThreadLocal s_Random = new ThreadLocal(() => new System.Random(Interlocked.Increment(ref s_Seed))); + + /// + /// 设置随机数种子。 + /// + /// + /// Sets the random seed. + /// + /// 随机数种子 / The random seed + [Preserve] + public static void SetSeed(int seed) + { + s_Seed = seed; + var oldRandom = s_Random; + s_Random = new ThreadLocal(() => new System.Random(Interlocked.Increment(ref s_Seed))); + oldRandom.Dispose(); + } + + /// + /// 返回非负随机数。 + /// + /// + /// Returns a non-negative random number. + /// + /// 返回一个大于等于零且小于 System.Int32.MaxValue 的 32 位带符号整数 / A 32-bit signed integer that is greater than or equal to 0 and less than System.Int32.MaxValue + [Preserve] + public static int GetRandom() + { + return s_Random.Value.Next(); + } + + /// + /// 返回一个小于所指定最大值的非负随机数。 + /// + /// + /// Returns a non-negative random number that is less than the specified maximum. + /// + /// 要生成的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于零 / The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero + /// 返回一个大于等于零且小于 maxValue 的 32 位带符号整数。如果 maxValue 等于零,则返回 maxValue / A 32-bit signed integer that is greater than or equal to 0 and less than maxValue. If maxValue equals 0, maxValue is returned + [Preserve] + public static int GetRandom(int maxValue) + { + return s_Random.Value.Next(maxValue); + } + + /// + /// 返回一个指定范围内的随机数。 + /// + /// + /// Returns a random number within a specified range. + /// + /// 返回的随机数的下界(随机数可取该下界值) / The inclusive lower bound of the random number returned + /// 返回的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于 minValue / The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue + /// 返回一个大于等于 minValue 且小于 maxValue 的 32 位带符号整数。如果 minValue 等于 maxValue,则返回 minValue / A 32-bit signed integer greater than or equal to minValue and less than maxValue. If minValue equals maxValue, minValue is returned + [Preserve] + public static int GetRandom(int minValue, int maxValue) + { + return s_Random.Value.Next(minValue, maxValue); + } + + /// + /// 返回一个介于 0.0 和 1.0 之间的随机数。 + /// + /// + /// Returns a random number between 0.0 and 1.0. + /// + /// 返回一个大于等于 0.0 并且小于 1.0 的双精度浮点数 / A double-precision floating point number that is greater than or equal to 0.0 and less than 1.0 + [Preserve] + public static double GetRandomDouble() + { + return s_Random.Value.NextDouble(); + } + + /// + /// 用随机数填充指定字节数组的元素。 + /// + /// + /// Fills the elements of a specified array of bytes with random numbers. + /// + /// 包含随机数的字节数组 / The byte array to contain random numbers + [Preserve] + public static void GetRandomBytes(byte[] buffer) + { + s_Random.Value.NextBytes(buffer); + } + + /// + /// 返回一个介于 0.0 和 1.0 之间的单精度随机数。 + /// + /// + /// Returns a single-precision random number between 0.0 and 1.0. + /// + /// 返回一个大于等于 0.0 并且小于 1.0 的单精度浮点数 / A single-precision floating point number that is greater than or equal to 0.0 and less than 1.0 + [Preserve] + public static float GetRandomFloat() + { + return (float)s_Random.Value.NextDouble(); + } + + /// + /// 返回一个 Int64 范围内的随机数。 + /// + /// + /// Returns a random number within the Int64 range. + /// + /// 返回一个随机的 Int64 值 / A random Int64 value + [Preserve] + public static long GetRandomInt64() + { + var bytes = new byte[8]; + s_Random.Value.NextBytes(bytes); + return BitConverter.ToInt64(bytes, 0); + } + + /// + /// 返回一个 UInt64 范围内的随机数。 + /// + /// + /// Returns a random number within the UInt64 range. + /// + /// 返回一个随机的 UInt64 值 / A random UInt64 value + [Preserve] + public static ulong GetRandomUInt64() + { + var bytes = new byte[8]; + s_Random.Value.NextBytes(bytes); + return BitConverter.ToUInt64(bytes, 0); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.RandomUtility.cs.meta b/Runtime/Utility/RandomUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.RandomUtility.cs.meta rename to Runtime/Utility/RandomUtility.cs.meta diff --git a/Runtime/Utility/Utility.Assembly.cs b/Runtime/Utility/Utility.Assembly.cs deleted file mode 100644 index ba6e8ef..0000000 --- a/Runtime/Utility/Utility.Assembly.cs +++ /dev/null @@ -1,187 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.Collections.Generic; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 程序集相关的实用函数。 - /// - /// - /// Assembly related utility functions. - /// - public static class Assembly - { - private static readonly System.Reflection.Assembly[] Assemblies = null; - private static readonly Dictionary CachedTypes = new Dictionary(StringComparer.Ordinal); - private static readonly object Lock = new object(); - - static Assembly() - { - Assemblies = AppDomain.CurrentDomain.GetAssemblies(); - } - - /// - /// 获取已加载的程序集。 - /// - /// - /// Gets the loaded assemblies. - /// - /// 已加载的程序集 / The loaded assemblies - [Preserve] - public static System.Reflection.Assembly[] GetAssemblies() - { - return Assemblies; - } - - /// - /// 获取已加载的程序集中的所有类型。 - /// - /// - /// Gets all types in the loaded assemblies. - /// - /// 已加载的程序集中的所有类型 / All types in the loaded assemblies - [Preserve] - public static Type[] GetTypes() - { - var results = new List(256); - foreach (var assembly in Assemblies) - { - results.AddRange(assembly.GetTypes()); - } - - return results.ToArray(); - } - - /// - /// 获取已加载的程序集中的所有类型。 - /// - /// - /// Gets all types in the loaded assemblies. - /// - /// 已加载的程序集中的所有类型 / All types in the loaded assemblies - [Preserve] - public static void GetTypes(List results) - { - if (results == null) - { - throw new GameFrameworkException("Results is invalid."); - } - - results.Clear(); - foreach (var assembly in Assemblies) - { - results.AddRange(assembly.GetTypes()); - } - } - - /// - /// 获取已加载的程序集中的指定类型。 - /// - /// - /// Gets the specified type from the loaded assemblies. - /// - /// 要获取的类型名 / The type name to get - /// 已加载的程序集中的指定类型 / The specified type from the loaded assemblies - [Preserve] - public static Type GetType(string typeName) - { - if (string.IsNullOrEmpty(typeName)) - { - return null; - } - - lock (Lock) - { - if (CachedTypes.TryGetValue(typeName, out var type)) - { - return type; - } - - type = Type.GetType(typeName); - if (type != null) - { - CachedTypes.Add(typeName, type); - return type; - } - - foreach (System.Reflection.Assembly assembly in Assemblies) - { - type = Type.GetType(Text.Format("{0}, {1}", typeName, assembly.FullName)); - if (type != null) - { - CachedTypes.Add(typeName, type); - return type; - } - } - - return null; - } - } - - /// - /// 获取已加载的程序集中的指定类型的子类列表。 - /// - /// - /// Gets the list of subclass names of the specified type from the loaded assemblies. - /// - /// 指定类型 / The specified type - /// 子类全名列表 / The list of subclass full names - [Preserve] - public static List GetRuntimeTypeNames(Type type) - { - var types = GetTypes(); - var results = new List(256); - foreach (var t in types) - { - if (t.IsAbstract || !t.IsClass) - { - continue; - } - - if (t.IsSubclassOf(type) || t.IsImplWithInterface(type)) - { - results.Add(t.FullName); - } - } - - return results; - } - } - } -} diff --git a/Runtime/Utility/Utility.Asset.Path.cs b/Runtime/Utility/Utility.Asset.Path.cs deleted file mode 100644 index 3d73159..0000000 --- a/Runtime/Utility/Utility.Asset.Path.cs +++ /dev/null @@ -1,313 +0,0 @@ -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// Asset Bundle 实用函数集,主要是路径拼接。 - /// - /// - /// Asset Bundle utility functions, mainly for path concatenation. - /// - [UnityEngine.Scripting.Preserve] - public static class Asset - { - /// - /// 路径常量和方法。 - /// - /// - /// Path constants and methods. - /// - public static class Path - { - /// - /// 打包资源根路径 - /// - public const string BundlesPath = "Assets/Bundles"; - - /// - /// 打包资源文件夹名称 - /// - public const string BundlesDirectoryName = "Bundles"; - - /// - /// 打包资源文件夹Scene名称 - /// - public const string BundlesDirectorySceneName = "Scene"; - - /// - /// 打包资源文件夹Localization名称 - /// - public const string BundlesDirectoryLocalizationName = "Localization"; - - /// - /// 打包资源文件夹Config名称 - /// - public const string BundlesDirectoryConfigName = "Config"; - - /// - /// 打包资源文件夹AOTCode名称 - /// - public const string BundlesDirectoryAOTCodeName = "AOTCode"; - - /// - /// 打包资源文件夹Code名称 - /// - public const string BundlesDirectoryCodeName = "Code"; - - /// - /// 打包资源文件夹Sound名称 - /// - public const string BundlesDirectorySoundName = "Sound"; - - /// - /// 打包资源文件夹Prefab名称 - /// - public const string BundlesDirectoryPrefabName = "Prefabs"; - - /// - /// 打包资源文件夹Video名称 - /// - public const string BundlesDirectoryVideoName = "Video"; - - /// - /// 打包资源文件夹Image名称 - /// - public const string BundlesDirectoryImageName = "Image"; - - /// - /// 打包资源文件夹Fonts名称 - /// - public const string BundlesDirectoryFontsName = "Fonts"; - - /// - /// 打包资源文件夹UI名称 - /// - public const string BundlesDirectoryUIName = "UI"; - - /// - /// 打包资源文件夹Sprite名称 - /// - public const string BundlesDirectorySpriteName = "Sprite"; - - /// - /// 打包资源文件夹Spine名称 - /// - public const string BundlesDirectorySpineName = "Spine"; - - /// - /// 打包资源文件夹Shader名称 - /// - public const string BundlesDirectoryShaderName = "Shader"; - - /// - /// 获取文件路径 - /// - /// 相对于Bundles的路径,不要以/开头 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetFilePath(string filePath) - { - return $"{BundlesPath}/{filePath}"; - } - - /// - /// 获取Spine文件路径 - /// - /// 相对于Bundles/Spine的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetSpinePath(string filePath) - { - return GetCategoryFilePath(BundlesDirectorySpineName, filePath); - } - - /// - /// 获取着色器文件路径 - /// - /// 相对于Bundles/Shader的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetShaderPath(string filePath) - { - return GetCategoryFilePath(BundlesDirectoryShaderName, filePath); - } - - /// - /// 获取字体文件路径 - /// - /// 相对于Bundles/Fonts的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetFontPath(string filePath) - { - return GetCategoryFilePath(BundlesDirectoryFontsName, filePath); - } - - /// - /// 获取图片文件路径 - /// - /// 相对于Bundles/Image的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetImagePath(string filePath) - { - return GetCategoryFilePath(BundlesDirectoryImageName, filePath); - } - - /// - /// 获取视频文件路径 - /// - /// 相对于Bundles/Video的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetVideoPath(string filePath) - { - return GetCategoryFilePath(BundlesDirectoryVideoName, filePath); - } - - /// - /// 获取Sprite文件路径 - /// - /// 相对于Bundles/Sprite的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetSpritePath(string filePath) - { - return GetCategoryFilePath(BundlesDirectorySpriteName, filePath); - } - - /// - /// 获取Prefab文件路径 - /// - /// 相对于Bundles/Prefabs的路径,不要以/开头,需要携带扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetPrefabPath(string filePath) - { - return GetCategoryFilePath(BundlesDirectoryPrefabName, filePath); - } - - /// - /// 获取根据类别文件夹名称和文件路径获得完整文件路径 - /// - /// 相对于Bundles的类别名称 - /// 相对于Bundles的路径,不要以/开头 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetCategoryFilePath(string category, string filePath) - { - return $"{BundlesPath}/{category}/{filePath}"; - } - - /// - /// 获取配置文件路径 - /// - /// 相对于Bundles/Config的路径,不要以/开头,需要携带扩展名 - /// 文件扩展名称 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetConfigPath(string fileName, string extension = ".bytes") - { - return GetCategoryFilePath(BundlesDirectoryConfigName, $"{fileName}{extension}"); - } - - /// - /// 获取AOT元数据代码文件路径 - /// - /// 相对于Bundles/AOTCode的路径,不要以/开头,需要携带扩展名 - /// 文件扩展名称 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetAOTCodePath(string fileName, string extension = ".bytes") - { - return GetCategoryFilePath(BundlesDirectoryAOTCodeName, $"{fileName}{extension}"); - } - - /// - /// 获取代码文件路径 - /// - /// 相对于Bundles/Code的路径,不要以/开头,需要携带扩展名 - /// 文件扩展名称 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetCodePath(string fileName, string extension = ".bytes") - { - return GetCategoryFilePath(BundlesDirectoryCodeName, $"{fileName}{extension}"); - } - - /// - /// 获取UI文件路径 - /// - /// UI包名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetUIPackagePath(string uiPackageName) - { - return GetCategoryFilePath(BundlesDirectoryUIName, $"{uiPackageName}/{uiPackageName}"); - } - - /// - /// 获取UI文件路径 - /// - /// UI路径 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetUIPath(string uiPath) - { - return GetCategoryFilePath(BundlesDirectoryUIName, uiPath); - } - - /// - /// 获取声音文件路径 - /// - /// 路径包含名称 - /// 扩展名称,默认为.mp3 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetSoundPath(string pathName, string extension = ".mp3") - { - if (pathName.IndexOf('.') >= 0) - { - return GetCategoryFilePath(BundlesDirectorySoundName, pathName); - } - - return GetCategoryFilePath(BundlesDirectorySoundName, $"{pathName}{extension}"); - } - - /// - /// 获取场景文件路径 - /// - /// 路径包含名称 - /// 扩展名,默认为.unity - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetScenePath(string pathName, string extension = ".unity") - { - if (pathName.IndexOf('.') >= 0) - { - return GetCategoryFilePath(BundlesDirectorySceneName, pathName); - } - - return GetCategoryFilePath(BundlesDirectorySceneName, $"{pathName}{extension}"); - } - - /// - /// 获取本地化文件路径 - /// - /// 路径包含名称 - /// 文件扩展名 - /// 返回拼接好的路径 - [UnityEngine.Scripting.Preserve] - public static string GetLocalizationPath(string pathName, string extension = ".xml") - { - if (pathName.IndexOf('.') >= 0) - { - return GetCategoryFilePath(BundlesDirectoryLocalizationName, pathName); - } - - return GetCategoryFilePath(BundlesDirectoryLocalizationName, $"{pathName}{extension}"); - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Compression.ICompressionHelper.cs b/Runtime/Utility/Utility.Compression.ICompressionHelper.cs deleted file mode 100644 index 9825001..0000000 --- a/Runtime/Utility/Utility.Compression.ICompressionHelper.cs +++ /dev/null @@ -1,88 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System.IO; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - public static partial class Compression - { - /// - /// 压缩解压缩辅助器接口。 - /// - /// - /// Compression helper interface. - /// - public interface ICompressionHelper - { - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 要压缩的数据的二进制流的偏移。 - /// 要压缩的数据的二进制流的长度。 - /// 压缩后的数据的二进制流。 - /// 是否压缩数据成功。 - bool Compress(byte[] bytes, int offset, int length, Stream compressedStream); - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 压缩后的数据的二进制流。 - /// 是否压缩数据成功。 - bool Compress(Stream stream, Stream compressedStream); - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 要解压缩的数据的二进制流的偏移。 - /// 要解压缩的数据的二进制流的长度。 - /// 解压缩后的数据的二进制流。 - /// 是否解压缩数据成功。 - bool Decompress(byte[] bytes, int offset, int length, Stream decompressedStream); - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 解压缩后的数据的二进制流。 - /// 是否解压缩数据成功。 - bool Decompress(Stream stream, Stream decompressedStream); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Compression.ICompressionHelper.cs.meta b/Runtime/Utility/Utility.Compression.ICompressionHelper.cs.meta deleted file mode 100644 index 12d6e93..0000000 --- a/Runtime/Utility/Utility.Compression.ICompressionHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 380ab98afbe8c3c46a91492c3f9b147d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Compression.cs b/Runtime/Utility/Utility.Compression.cs deleted file mode 100644 index 4ff1c7a..0000000 --- a/Runtime/Utility/Utility.Compression.cs +++ /dev/null @@ -1,388 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.IO; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 压缩解压缩相关的实用函数。 - /// - /// - /// Compression and decompression related utility functions. - /// - [Preserve] - public static partial class Compression - { - private static ICompressionHelper s_CompressionHelper = null; - - /// - /// 设置压缩解压缩辅助器。 - /// - /// 要设置的压缩解压缩辅助器。 - [Preserve] - public static void SetCompressionHelper(ICompressionHelper compressionHelper) - { - s_CompressionHelper = compressionHelper; - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 压缩后的数据的二进制流。 - [Preserve] - public static byte[] Compress(byte[] bytes) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - return Compress(bytes, 0, bytes.Length); - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 压缩后的数据的二进制流。 - /// 是否压缩数据成功。 - [Preserve] - public static bool Compress(byte[] bytes, Stream compressedStream) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - return Compress(bytes, 0, bytes.Length, compressedStream); - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 要压缩的数据的二进制流的偏移。 - /// 要压缩的数据的二进制流的长度。 - /// 压缩后的数据的二进制流。 - [Preserve] - public static byte[] Compress(byte[] bytes, int offset, int length) - { - using (MemoryStream compressedStream = new MemoryStream()) - { - if (Compress(bytes, offset, length, compressedStream)) - { - return compressedStream.ToArray(); - } - else - { - return null; - } - } - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 要压缩的数据的二进制流的偏移。 - /// 要压缩的数据的二进制流的长度。 - /// 压缩后的数据的二进制流。 - /// 是否压缩数据成功。 - [Preserve] - public static bool Compress(byte[] bytes, int offset, int length, Stream compressedStream) - { - if (s_CompressionHelper == null) - { - throw new GameFrameworkException("Compressed helper is invalid."); - } - - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - if (offset < 0 || length < 0 || offset + length > bytes.Length) - { - throw new GameFrameworkException("Offset or length is invalid."); - } - - if (compressedStream == null) - { - throw new GameFrameworkException("Compressed stream is invalid."); - } - - try - { - return s_CompressionHelper.Compress(bytes, offset, length, compressedStream); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not compress with exception '{0}'.", exception), exception); - } - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 压缩后的数据的二进制流。 - [Preserve] - public static byte[] Compress(Stream stream) - { - using (MemoryStream compressedStream = new MemoryStream()) - { - if (Compress(stream, compressedStream)) - { - return compressedStream.ToArray(); - } - else - { - return null; - } - } - } - - /// - /// 压缩数据。 - /// - /// 要压缩的数据的二进制流。 - /// 压缩后的数据的二进制流。 - /// 是否压缩数据成功。 - [Preserve] - public static bool Compress(Stream stream, Stream compressedStream) - { - if (s_CompressionHelper == null) - { - throw new GameFrameworkException("Compressed helper is invalid."); - } - - if (stream == null) - { - throw new GameFrameworkException("Stream is invalid."); - } - - if (compressedStream == null) - { - throw new GameFrameworkException("Compressed stream is invalid."); - } - - try - { - return s_CompressionHelper.Compress(stream, compressedStream); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not compress with exception '{0}'.", exception), exception); - } - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 解压缩后的数据的二进制流。 - [Preserve] - public static byte[] Decompress(byte[] bytes) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - return Decompress(bytes, 0, bytes.Length); - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 解压缩后的数据的二进制流。 - /// 是否解压缩数据成功。 - [Preserve] - public static bool Decompress(byte[] bytes, Stream decompressedStream) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - return Decompress(bytes, 0, bytes.Length, decompressedStream); - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 要解压缩的数据的二进制流的偏移。 - /// 要解压缩的数据的二进制流的长度。 - /// 解压缩后的数据的二进制流。 - [Preserve] - public static byte[] Decompress(byte[] bytes, int offset, int length) - { - using (MemoryStream decompressedStream = new MemoryStream()) - { - if (Decompress(bytes, offset, length, decompressedStream)) - { - return decompressedStream.ToArray(); - } - else - { - return null; - } - } - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 要解压缩的数据的二进制流的偏移。 - /// 要解压缩的数据的二进制流的长度。 - /// 解压缩后的数据的二进制流。 - /// 是否解压缩数据成功。 - [Preserve] - public static bool Decompress(byte[] bytes, int offset, int length, Stream decompressedStream) - { - if (s_CompressionHelper == null) - { - throw new GameFrameworkException("Compressed helper is invalid."); - } - - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - if (offset < 0 || length < 0 || offset + length > bytes.Length) - { - throw new GameFrameworkException("Offset or length is invalid."); - } - - if (decompressedStream == null) - { - throw new GameFrameworkException("Decompressed stream is invalid."); - } - - try - { - return s_CompressionHelper.Decompress(bytes, offset, length, decompressedStream); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not decompress with exception '{0}'.", exception), exception); - } - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 是否解压缩数据成功。 - [Preserve] - public static byte[] Decompress(Stream stream) - { - using (MemoryStream decompressedStream = new MemoryStream()) - { - if (Decompress(stream, decompressedStream)) - { - return decompressedStream.ToArray(); - } - else - { - return null; - } - } - } - - /// - /// 解压缩数据。 - /// - /// 要解压缩的数据的二进制流。 - /// 解压缩后的数据的二进制流。 - /// 是否解压缩数据成功。 - [Preserve] - public static bool Decompress(Stream stream, Stream decompressedStream) - { - if (s_CompressionHelper == null) - { - throw new GameFrameworkException("Compressed helper is invalid."); - } - - if (stream == null) - { - throw new GameFrameworkException("Stream is invalid."); - } - - if (decompressedStream == null) - { - throw new GameFrameworkException("Decompressed stream is invalid."); - } - - try - { - return s_CompressionHelper.Decompress(stream, decompressedStream); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not decompress with exception '{0}'.", exception), exception); - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Compression.cs.meta b/Runtime/Utility/Utility.Compression.cs.meta deleted file mode 100644 index 6898662..0000000 --- a/Runtime/Utility/Utility.Compression.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e2741b86967782d4292e71e9519e7ec7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Const.FileNameSuffix.cs b/Runtime/Utility/Utility.Const.FileNameSuffix.cs deleted file mode 100644 index d06fdd8..0000000 --- a/Runtime/Utility/Utility.Const.FileNameSuffix.cs +++ /dev/null @@ -1,131 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 常量相关的实用函数。 - /// - /// - /// Constant related utility functions. - /// - public static partial class Const - { - /// - /// 文件名后缀常量。 - /// - /// - /// File name suffix constants. - /// - public static partial class FileNameSuffix - { - /// - /// Json 文件 - /// - public const string Json = ".json"; - - /// - /// Wav 文件 - /// - public const string Wav = ".wav"; - - /// - /// Mp3 文件 - /// - public const string Mp3 = ".mp3"; - - /// - /// Xml 文件 - /// - public const string Xml = ".xml"; - - /// - /// 文本文件 - /// - public const string Txt = ".txt"; - - /// - /// 日志文件 - /// - public const string Log = ".log"; - - /// - /// CSharp 文件 - /// - public const string CSharp = ".cs"; - - /// - /// Zip 压缩文件 - /// - public const string Zip = ".zip"; - - /// - /// 图片PNG - /// - public const string PNG = ".png"; - - /// - /// 图片JPG - /// - public const string JPG = ".jpg"; - - /// - /// 二进制文件 - /// - public const string Binary = ".bytes"; - - /// - /// 配置文件 - /// - public const string Config = ".config"; - - /// - /// DLL 文件 - /// - public const string DLL = ".dll"; - - /// - /// PDB 调试文件 - /// - public const string PDB = ".pdb"; - - /// - /// Asset 文件 - /// - public const string Asset = ".asset"; - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Converter.cs b/Runtime/Utility/Utility.Converter.cs deleted file mode 100644 index 4ef89cc..0000000 --- a/Runtime/Utility/Utility.Converter.cs +++ /dev/null @@ -1,944 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.Text; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 类型转换相关的实用函数。 - /// - /// - /// Type conversion related utility functions. - /// - [Preserve] - public static class Converter - { - private const float InchesToCentimeters = 2.54f; // 1 inch = 2.54 cm - private const float CentimetersToInches = 1f / InchesToCentimeters; // 1 cm = 0.3937 inches - - /// - /// 获取数据在此计算机结构中存储时的字节顺序。 - /// - /// - /// Gets the byte order of data storage in this computer architecture. - /// - [Preserve] - public static bool IsLittleEndian - { - get { return BitConverter.IsLittleEndian; } - } - - /// - /// 获取或设置屏幕每英寸点数。 - /// - /// - /// Gets or sets the screen dots per inch. - /// - [Preserve] - public static float ScreenDpi { get; set; } - - /// - /// 将像素转换为厘米。 - /// - /// 像素。 - /// 厘米。 - [Preserve] - public static float GetCentimetersFromPixels(float pixels) - { - if (ScreenDpi <= 0) - { - throw new GameFrameworkException("You must set screen DPI first."); - } - - return InchesToCentimeters * pixels / ScreenDpi; - } - - /// - /// 将厘米转换为像素。 - /// - /// 厘米。 - /// 像素。 - [Preserve] - public static float GetPixelsFromCentimeters(float centimeters) - { - if (ScreenDpi <= 0) - { - throw new GameFrameworkException("You must set screen DPI first."); - } - - return CentimetersToInches * centimeters * ScreenDpi; - } - - /// - /// 将像素转换为英寸。 - /// - /// 像素。 - /// 英寸。 - [Preserve] - public static float GetInchesFromPixels(float pixels) - { - if (ScreenDpi <= 0) - { - throw new GameFrameworkException("You must set screen DPI first."); - } - - return pixels / ScreenDpi; - } - - /// - /// 将英寸转换为像素。 - /// - /// 英寸。 - /// 像素。 - [Preserve] - public static float GetPixelsFromInches(float inches) - { - if (ScreenDpi <= 0) - { - throw new GameFrameworkException("You must set screen DPI first."); - } - - return inches * ScreenDpi; - } - - /// - /// 以字节数组的形式获取指定的布尔值。 - /// - /// 要转换的布尔值。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(bool value) - { - byte[] buffer = new byte[1]; - GetBytes(value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的布尔值。 - /// - /// 要转换的布尔值。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(bool value, byte[] buffer) - { - GetBytes(value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的布尔值。 - /// - /// 要转换的布尔值。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static void GetBytes(bool value, byte[] buffer, int startIndex) - { - if (buffer == null) - { - throw new GameFrameworkException("Buffer is invalid."); - } - - if (startIndex < 0 || startIndex + 1 > buffer.Length) - { - throw new GameFrameworkException("Start index is invalid."); - } - - buffer[startIndex] = value ? (byte)1 : (byte)0; - } - - /// - /// 返回由字节数组中首字节转换来的布尔值。 - /// - /// 字节数组。 - /// 如果 value 中的首字节非零,则为 true,否则为 false。 - [Preserve] - public static bool GetBoolean(byte[] value) - { - return BitConverter.ToBoolean(value, 0); - } - - /// - /// 返回由字节数组中指定位置的一个字节转换来的布尔值。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 如果 value 中指定位置的字节非零,则为 true,否则为 false。 - [Preserve] - public static bool GetBoolean(byte[] value, int startIndex) - { - return BitConverter.ToBoolean(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 Unicode 字符值。 - /// - /// 要转换的字符。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(char value) - { - byte[] buffer = new byte[2]; - GetBytes((short)value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 Unicode 字符值。 - /// - /// 要转换的字符。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(char value, byte[] buffer) - { - GetBytes((short)value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 Unicode 字符值。 - /// - /// 要转换的字符。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static void GetBytes(char value, byte[] buffer, int startIndex) - { - GetBytes((short)value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前两个字节转换来的 Unicode 字符。 - /// - /// 字节数组。 - /// 由两个字节构成的字符。 - [Preserve] - public static char GetChar(byte[] value) - { - return BitConverter.ToChar(value, 0); - } - - /// - /// 返回由字节数组中指定位置的两个字节转换来的 Unicode 字符。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由两个字节构成的字符。 - [Preserve] - public static char GetChar(byte[] value, int startIndex) - { - return BitConverter.ToChar(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 16 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(short value) - { - byte[] buffer = new byte[2]; - GetBytes(value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 16 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(short value, byte[] buffer) - { - GetBytes(value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 16 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static unsafe void GetBytes(short value, byte[] buffer, int startIndex) - { - if (buffer == null) - { - throw new GameFrameworkException("Buffer is invalid."); - } - - if (startIndex < 0 || startIndex + 2 > buffer.Length) - { - throw new GameFrameworkException("Start index is invalid."); - } - - fixed (byte* valueRef = buffer) - { - *(short*)(valueRef + startIndex) = value; - } - } - - /// - /// 返回由字节数组中前两个字节转换来的 16 位有符号整数。 - /// - /// 字节数组。 - /// 由两个字节构成的 16 位有符号整数。 - [Preserve] - public static short GetInt16(byte[] value) - { - return BitConverter.ToInt16(value, 0); - } - - /// - /// 返回由字节数组中指定位置的两个字节转换来的 16 位有符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由两个字节构成的 16 位有符号整数。 - [Preserve] - public static short GetInt16(byte[] value, int startIndex) - { - return BitConverter.ToInt16(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 16 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(ushort value) - { - byte[] buffer = new byte[2]; - GetBytes((short)value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 16 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(ushort value, byte[] buffer) - { - GetBytes((short)value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 16 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static void GetBytes(ushort value, byte[] buffer, int startIndex) - { - GetBytes((short)value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前两个字节转换来的 16 位无符号整数。 - /// - /// 字节数组。 - /// 由两个字节构成的 16 位无符号整数。 - [Preserve] - public static ushort GetUInt16(byte[] value) - { - return BitConverter.ToUInt16(value, 0); - } - - /// - /// 返回由字节数组中指定位置的两个字节转换来的 16 位无符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由两个字节构成的 16 位无符号整数。 - [Preserve] - public static ushort GetUInt16(byte[] value, int startIndex) - { - return BitConverter.ToUInt16(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 32 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(int value) - { - byte[] buffer = new byte[4]; - GetBytes(value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 32 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(int value, byte[] buffer) - { - GetBytes(value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 32 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static unsafe void GetBytes(int value, byte[] buffer, int startIndex) - { - if (buffer == null) - { - throw new GameFrameworkException("Buffer is invalid."); - } - - if (startIndex < 0 || startIndex + 4 > buffer.Length) - { - throw new GameFrameworkException("Start index is invalid."); - } - - fixed (byte* valueRef = buffer) - { - *(int*)(valueRef + startIndex) = value; - } - } - - /// - /// 返回由字节数组中前四个字节转换来的 32 位有符号整数。 - /// - /// 字节数组。 - /// 由四个字节构成的 32 位有符号整数。 - [Preserve] - public static int GetInt32(byte[] value) - { - return BitConverter.ToInt32(value, 0); - } - - /// - /// 返回由字节数组中指定位置的四个字节转换来的 32 位有符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由四个字节构成的 32 位有符号整数。 - [Preserve] - public static int GetInt32(byte[] value, int startIndex) - { - return BitConverter.ToInt32(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 32 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(uint value) - { - byte[] buffer = new byte[4]; - GetBytes((int)value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 32 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(uint value, byte[] buffer) - { - GetBytes((int)value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 32 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static void GetBytes(uint value, byte[] buffer, int startIndex) - { - GetBytes((int)value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前四个字节转换来的 32 位无符号整数。 - /// - /// 字节数组。 - /// 由四个字节构成的 32 位无符号整数。 - [Preserve] - public static uint GetUInt32(byte[] value) - { - return BitConverter.ToUInt32(value, 0); - } - - /// - /// 返回由字节数组中指定位置的四个字节转换来的 32 位无符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由四个字节构成的 32 位无符号整数。 - [Preserve] - public static uint GetUInt32(byte[] value, int startIndex) - { - return BitConverter.ToUInt32(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 64 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(long value) - { - byte[] buffer = new byte[8]; - GetBytes(value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 64 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(long value, byte[] buffer) - { - GetBytes(value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 64 位有符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static unsafe void GetBytes(long value, byte[] buffer, int startIndex) - { - if (buffer == null) - { - throw new GameFrameworkException("Buffer is invalid."); - } - - if (startIndex < 0 || startIndex + 8 > buffer.Length) - { - throw new GameFrameworkException("Start index is invalid."); - } - - fixed (byte* valueRef = buffer) - { - *(long*)(valueRef + startIndex) = value; - } - } - - /// - /// 返回由字节数组中前八个字节转换来的 64 位有符号整数。 - /// - /// 字节数组。 - /// 由八个字节构成的 64 位有符号整数。 - [Preserve] - public static long GetInt64(byte[] value) - { - return BitConverter.ToInt64(value, 0); - } - - /// - /// 返回由字节数组中指定位置的八个字节转换来的 64 位有符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由八个字节构成的 64 位有符号整数。 - [Preserve] - public static long GetInt64(byte[] value, int startIndex) - { - return BitConverter.ToInt64(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的 64 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(ulong value) - { - byte[] buffer = new byte[8]; - GetBytes((long)value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的 64 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static void GetBytes(ulong value, byte[] buffer) - { - GetBytes((long)value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的 64 位无符号整数值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static void GetBytes(ulong value, byte[] buffer, int startIndex) - { - GetBytes((long)value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前八个字节转换来的 64 位无符号整数。 - /// - /// 字节数组。 - /// 由八个字节构成的 64 位无符号整数。 - [Preserve] - public static ulong GetUInt64(byte[] value) - { - return BitConverter.ToUInt64(value, 0); - } - - /// - /// 返回由字节数组中指定位置的八个字节转换来的 64 位无符号整数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由八个字节构成的 64 位无符号整数。 - [Preserve] - public static ulong GetUInt64(byte[] value, int startIndex) - { - return BitConverter.ToUInt64(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的单精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static unsafe byte[] GetBytes(float value) - { - byte[] buffer = new byte[4]; - GetBytes(*(int*)&value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的单精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static unsafe void GetBytes(float value, byte[] buffer) - { - GetBytes(*(int*)&value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的单精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static unsafe void GetBytes(float value, byte[] buffer, int startIndex) - { - GetBytes(*(int*)&value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前四个字节转换来的单精度浮点数。 - /// - /// 字节数组。 - /// 由四个字节构成的单精度浮点数。 - [Preserve] - public static float GetSingle(byte[] value) - { - return BitConverter.ToSingle(value, 0); - } - - /// - /// 返回由字节数组中指定位置的四个字节转换来的单精度浮点数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由四个字节构成的单精度浮点数。 - [Preserve] - public static float GetSingle(byte[] value, int startIndex) - { - return BitConverter.ToSingle(value, startIndex); - } - - /// - /// 以字节数组的形式获取指定的双精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static unsafe byte[] GetBytes(double value) - { - byte[] buffer = new byte[8]; - GetBytes(*(long*)&value, buffer, 0); - return buffer; - } - - /// - /// 以字节数组的形式获取指定的双精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - [Preserve] - public static unsafe void GetBytes(double value, byte[] buffer) - { - GetBytes(*(long*)&value, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定的双精度浮点值。 - /// - /// 要转换的数字。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - [Preserve] - public static unsafe void GetBytes(double value, byte[] buffer, int startIndex) - { - GetBytes(*(long*)&value, buffer, startIndex); - } - - /// - /// 返回由字节数组中前八个字节转换来的双精度浮点数。 - /// - /// 字节数组。 - /// 由八个字节构成的双精度浮点数。 - [Preserve] - public static double GetDouble(byte[] value) - { - return BitConverter.ToDouble(value, 0); - } - - /// - /// 返回由字节数组中指定位置的八个字节转换来的双精度浮点数。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 由八个字节构成的双精度浮点数。 - [Preserve] - public static double GetDouble(byte[] value, int startIndex) - { - return BitConverter.ToDouble(value, startIndex); - } - - /// - /// 以字节数组的形式获取 UTF-8 编码的字符串。 - /// - /// 要转换的字符串。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(string value) - { - return GetBytes(value, Encoding.UTF8); - } - - /// - /// 以字节数组的形式获取 UTF-8 编码的字符串。 - /// - /// 要转换的字符串。 - /// 用于存放结果的字节数组。 - /// buffer 内实际填充了多少字节。 - [Preserve] - public static int GetBytes(string value, byte[] buffer) - { - return GetBytes(value, Encoding.UTF8, buffer, 0); - } - - /// - /// 以字节数组的形式获取 UTF-8 编码的字符串。 - /// - /// 要转换的字符串。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - /// buffer 内实际填充了多少字节。 - [Preserve] - public static int GetBytes(string value, byte[] buffer, int startIndex) - { - return GetBytes(value, Encoding.UTF8, buffer, startIndex); - } - - /// - /// 以字节数组的形式获取指定编码的字符串。 - /// - /// 要转换的字符串。 - /// 要使用的编码。 - /// 用于存放结果的字节数组。 - [Preserve] - public static byte[] GetBytes(string value, Encoding encoding) - { - if (value == null) - { - throw new GameFrameworkException("Value is invalid."); - } - - if (encoding == null) - { - throw new GameFrameworkException("Encoding is invalid."); - } - - return encoding.GetBytes(value); - } - - /// - /// 以字节数组的形式获取指定编码的字符串。 - /// - /// 要转换的字符串。 - /// 要使用的编码。 - /// 用于存放结果的字节数组。 - /// buffer 内实际填充了多少字节。 - [Preserve] - public static int GetBytes(string value, Encoding encoding, byte[] buffer) - { - return GetBytes(value, encoding, buffer, 0); - } - - /// - /// 以字节数组的形式获取指定编码的字符串。 - /// - /// 要转换的字符串。 - /// 要使用的编码。 - /// 用于存放结果的字节数组。 - /// buffer 内的起始位置。 - /// buffer 内实际填充了多少字节。 - [Preserve] - public static int GetBytes(string value, Encoding encoding, byte[] buffer, int startIndex) - { - if (value == null) - { - throw new GameFrameworkException("Value is invalid."); - } - - if (encoding == null) - { - throw new GameFrameworkException("Encoding is invalid."); - } - - return encoding.GetBytes(value, 0, value.Length, buffer, startIndex); - } - - /// - /// 返回由字节数组使用 UTF-8 编码转换成的字符串。 - /// - /// 字节数组。 - /// 转换后的字符串。 - [Preserve] - public static string GetString(byte[] value) - { - return GetString(value, Encoding.UTF8); - } - - /// - /// 返回由字节数组使用指定编码转换成的字符串。 - /// - /// 字节数组。 - /// 要使用的编码。 - /// 转换后的字符串。 - [Preserve] - public static string GetString(byte[] value, Encoding encoding) - { - if (value == null) - { - throw new GameFrameworkException("Value is invalid."); - } - - if (encoding == null) - { - throw new GameFrameworkException("Encoding is invalid."); - } - - return encoding.GetString(value); - } - - /// - /// 返回由字节数组使用 UTF-8 编码转换成的字符串。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 长度。 - /// 转换后的字符串。 - [Preserve] - public static string GetString(byte[] value, int startIndex, int length) - { - return GetString(value, startIndex, length, Encoding.UTF8); - } - - /// - /// 返回由字节数组使用指定编码转换成的字符串。 - /// - /// 字节数组。 - /// value 内的起始位置。 - /// 长度。 - /// 要使用的编码。 - /// 转换后的字符串。 - [Preserve] - public static string GetString(byte[] value, int startIndex, int length, Encoding encoding) - { - if (value == null) - { - throw new GameFrameworkException("Value is invalid."); - } - - if (encoding == null) - { - throw new GameFrameworkException("Encoding is invalid."); - } - - return encoding.GetString(value, startIndex, length); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Aes.cs b/Runtime/Utility/Utility.Encryption.Aes.cs deleted file mode 100644 index 520f384..0000000 --- a/Runtime/Utility/Utility.Encryption.Aes.cs +++ /dev/null @@ -1,325 +0,0 @@ -using System; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 加密解密相关的实用函数。 - /// - /// - /// Encryption and decryption related utility functions. - /// - public static partial class Encryption - { - /// - /// AES 加密算法的实现。 - /// - /// - /// AES encryption algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public static class Aes - { - #region 加密 - - #region 加密字符串 - - /// - /// AES 加密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 - /// - /// - /// AES encryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). - /// - /// 待加密密文 / The plaintext to encrypt - /// 加密密钥 / The encryption key - /// 加密后的 Base64 字符串 / The Base64 encrypted string - [Obsolete("AESEncrypt uses hardcoded IV/Salt. Use AESEncryptSecure instead.")] - [UnityEngine.Scripting.Preserve] - public static string AESEncrypt(string EncryptString, string EncryptKey) - { - return AESEncryptSecure(EncryptString, EncryptKey); - } - - #endregion - - #region 加密字节数组 - - /// - /// AES 加密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 - /// - /// - /// AES encryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). - /// - /// 待加密的字节数组 / The byte array to encrypt - /// 加密密钥 / The encryption key - /// 加密后的字节数组 / The encrypted byte array - [Obsolete("AESEncrypt uses hardcoded IV/Salt. Use AESEncryptSecure instead.")] - [UnityEngine.Scripting.Preserve] - public static byte[] AESEncrypt(byte[] EncryptByte, string EncryptKey) - { - return AESEncryptSecure(EncryptByte, EncryptKey); - } - - #endregion - - #endregion - - #region 解密 - - #region 解密字符串 - - /// - /// AES 解密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 - /// - /// - /// AES decryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). - /// - /// 待解密密文 / The ciphertext to decrypt - /// 解密密钥 / The decryption key - /// 解密后的字符串 / The decrypted string - [Obsolete("AESDecrypt uses hardcoded IV/Salt. Use AESDecryptSecure instead.")] - [UnityEngine.Scripting.Preserve] - public static string AESDecrypt(string DecryptString, string DecryptKey) - { - return AESDecryptSecure(DecryptString, DecryptKey); - } - - #endregion - - #region 解密字节数组 - - /// - /// AES 解密(高级加密标准,是下一代的加密算法标准,速度快,安全级别高,目前 AES 标准的一个实现是 Rijndael 算法)。 - /// - /// - /// AES decryption (Advanced Encryption Standard, the next generation encryption algorithm standard, fast and highly secure, one implementation of the AES standard is the Rijndael algorithm). - /// - /// 待解密的字节数组 / The byte array to decrypt - /// 解密密钥 / The decryption key - /// 解密后的字节数组 / The decrypted byte array - [Obsolete("AESDecrypt uses hardcoded IV/Salt. Use AESDecryptSecure instead.")] - [UnityEngine.Scripting.Preserve] - public static byte[] AESDecrypt(byte[] DecryptByte, string DecryptKey) - { - return AESDecryptSecure(DecryptByte, DecryptKey); - } - - #endregion - - #endregion - - #region 安全加密 - - #region 安全加密字符串 - - /// - /// AES 安全加密(使用随机 IV 和 Salt,相同明文产生不同密文)。 - /// - /// - /// AES secure encryption (uses random IV and Salt, same plaintext produces different ciphertext). - /// - /// 待加密明文 / The plaintext to encrypt - /// 加密密钥 / The encryption key - /// 加密后的 Base64 字符串 / The Base64 encrypted string - [UnityEngine.Scripting.Preserve] - public static string AESEncryptSecure(string EncryptString, string EncryptKey) - { - return Convert.ToBase64String(AESEncryptSecure(Encoding.UTF8.GetBytes(EncryptString), EncryptKey)); - } - - #endregion - - #region 安全加密字节数组 - - /// - /// AES 安全加密(使用随机 IV 和 Salt,相同明文产生不同密文)。 - /// 密文格式:[IV(16字节)][Salt(16字节)][加密数据]。 - /// - /// - /// AES secure encryption (uses random IV and Salt, same plaintext produces different ciphertext). - /// Ciphertext format: [IV(16 bytes)][Salt(16 bytes)][Encrypted data]. - /// - /// 待加密的字节数组 / The byte array to encrypt - /// 加密密钥 / The encryption key - /// 加密后的字节数组 / The encrypted byte array - [UnityEngine.Scripting.Preserve] - public static byte[] AESEncryptSecure(byte[] EncryptByte, string EncryptKey) - { - if (EncryptByte == null) - { - throw new ArgumentNullException("EncryptByte"); - } - - if (EncryptByte.Length == 0) - { - throw (new Exception("明文不得为空")); - } - - if (string.IsNullOrEmpty(EncryptKey)) - { - throw (new Exception("密钥不得为空")); - } - - byte[] m_strEncrypt; - byte[] m_btIV = new byte[16]; - byte[] m_salt = new byte[16]; - using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) - { - rng.GetBytes(m_btIV); - rng.GetBytes(m_salt); - } - - Rijndael m_AESProvider = Rijndael.Create(); - try - { - MemoryStream m_stream = new MemoryStream(); - m_stream.Write(m_btIV, 0, m_btIV.Length); - m_stream.Write(m_salt, 0, m_salt.Length); - PasswordDeriveBytes pdb = new PasswordDeriveBytes(EncryptKey, m_salt); - ICryptoTransform transform = m_AESProvider.CreateEncryptor(pdb.GetBytes(32), m_btIV); - CryptoStream m_csstream = new CryptoStream(m_stream, transform, CryptoStreamMode.Write); - m_csstream.Write(EncryptByte, 0, EncryptByte.Length); - m_csstream.FlushFinalBlock(); - m_strEncrypt = m_stream.ToArray(); - m_stream.Close(); - m_stream.Dispose(); - m_csstream.Close(); - m_csstream.Dispose(); - } - catch (IOException ex) - { - throw ex; - } - catch (CryptographicException ex) - { - throw ex; - } - catch (ArgumentException ex) - { - throw ex; - } - catch (Exception ex) - { - throw ex; - } - finally - { - m_AESProvider.Clear(); - } - - return m_strEncrypt; - } - - #endregion - - #endregion - - #region 安全解密 - - #region 安全解密字符串 - - /// - /// AES 安全解密(配合 AESEncryptSecure 使用,从密文头部提取随机 IV 和 Salt)。 - /// - /// - /// AES secure decryption (used with AESEncryptSecure, extracts random IV and Salt from ciphertext header). - /// - /// 待解密密文 / The ciphertext to decrypt - /// 解密密钥 / The decryption key - /// 解密后的字符串 / The decrypted string - [UnityEngine.Scripting.Preserve] - public static string AESDecryptSecure(string DecryptString, string DecryptKey) - { - return Encoding.UTF8.GetString(AESDecryptSecure(Convert.FromBase64String(DecryptString), DecryptKey)); - } - - #endregion - - #region 安全解密字节数组 - - /// - /// AES 安全解密(配合 AESEncryptSecure 使用,从密文头部提取随机 IV 和 Salt)。 - /// 密文格式:[IV(16字节)][Salt(16字节)][加密数据]。 - /// - /// - /// AES secure decryption (used with AESEncryptSecure, extracts random IV and Salt from ciphertext header). - /// Ciphertext format: [IV(16 bytes)][Salt(16 bytes)][Encrypted data]. - /// - /// 待解密的字节数组 / The byte array to decrypt - /// 解密密钥 / The decryption key - /// 解密后的字节数组 / The decrypted byte array - [UnityEngine.Scripting.Preserve] - public static byte[] AESDecryptSecure(byte[] DecryptByte, string DecryptKey) - { - if (DecryptByte == null) - { - throw new ArgumentNullException("DecryptByte"); - } - - if (DecryptByte.Length <= 32) - { - throw (new Exception("密文不得为空")); - } - - if (string.IsNullOrEmpty(DecryptKey)) - { - throw (new Exception("密钥不得为空")); - } - - byte[] m_strDecrypt; - byte[] m_btIV = new byte[16]; - byte[] m_salt = new byte[16]; - byte[] m_EncryptData = new byte[DecryptByte.Length - 32]; - Buffer.BlockCopy(DecryptByte, 0, m_btIV, 0, 16); - Buffer.BlockCopy(DecryptByte, 16, m_salt, 0, 16); - Buffer.BlockCopy(DecryptByte, 32, m_EncryptData, 0, m_EncryptData.Length); - Rijndael m_AESProvider = Rijndael.Create(); - try - { - MemoryStream m_stream = new MemoryStream(); - PasswordDeriveBytes pdb = new PasswordDeriveBytes(DecryptKey, m_salt); - ICryptoTransform transform = m_AESProvider.CreateDecryptor(pdb.GetBytes(32), m_btIV); - CryptoStream m_csstream = new CryptoStream(m_stream, transform, CryptoStreamMode.Write); - m_csstream.Write(m_EncryptData, 0, m_EncryptData.Length); - m_csstream.FlushFinalBlock(); - m_strDecrypt = m_stream.ToArray(); - m_stream.Close(); - m_stream.Dispose(); - m_csstream.Close(); - m_csstream.Dispose(); - } - catch (IOException ex) - { - throw ex; - } - catch (CryptographicException ex) - { - throw ex; - } - catch (ArgumentException ex) - { - throw ex; - } - catch (Exception ex) - { - throw ex; - } - finally - { - m_AESProvider.Clear(); - } - - return m_strDecrypt; - } - - #endregion - - #endregion - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Dsa.cs b/Runtime/Utility/Utility.Encryption.Dsa.cs deleted file mode 100644 index fd55e08..0000000 --- a/Runtime/Utility/Utility.Encryption.Dsa.cs +++ /dev/null @@ -1,235 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 加密解密相关的实用函数。 - /// - public static partial class Encryption - { - /// - /// DSA 加密算法的实现。 - /// - /// - /// DSA encryption algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public sealed class Dsa - { - private readonly DSACryptoServiceProvider _dsa = null; - - /// - /// Dsa 构造函数,使用提供的 DSACryptoServiceProvider 实例初始化。 - /// - /// - /// Dsa constructor, initializes with the provided DSACryptoServiceProvider instance. - /// - /// DSACryptoServiceProvider 实例 / The DSACryptoServiceProvider instance - [UnityEngine.Scripting.Preserve] - public Dsa(DSACryptoServiceProvider dsa) - { - _dsa = dsa; - } - - /// - /// Dsa 构造函数,使用提供的密钥字符串初始化。 - /// - /// - /// Dsa constructor, initializes with the provided key string. - /// - /// 密钥字符串 / The key string - [UnityEngine.Scripting.Preserve] - public Dsa(string key) - { - DSACryptoServiceProvider rsa = new DSACryptoServiceProvider(); - rsa.FromXmlString(key); - this._dsa = rsa; - } - - /// - /// 创建 DSA 密钥对。 - /// - /// - /// Creates a DSA key pair. - /// - /// 包含私钥和公钥的字典 / A dictionary containing the private key and public key - [UnityEngine.Scripting.Preserve] - public static Dictionary Make() - { - Dictionary dic = new Dictionary(); - DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); - dic["privatekey"] = dsa.ToXmlString(true); - dic["publickey"] = dsa.ToXmlString(false); - return dic; - } - - /// - /// 使用私钥对数据进行签名。 - /// - /// - /// Signs data using the private key. - /// - /// 要签名的数据 / The data to sign - /// 私钥字符串 / The private key string - /// 签名后的字节数组 / The signed byte array - [UnityEngine.Scripting.Preserve] - public static byte[] DSASignData(byte[] dataToSign, string privateKey) - { - try - { - DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); - dsa.FromXmlString(privateKey); - return dsa.SignData(dataToSign); - } - catch (Exception ex) - { - throw new GameFrameworkException("DSA sign data failed.", ex); - } - } - - /// - /// 使用私钥对字符串数据进行签名。 - /// - /// - /// Signs string data using the private key. - /// - /// 要签名的字符串数据 / The string data to sign - /// 私钥字符串 / The private key string - /// 签名后的 Base64 字符串 / The Base64 signed string - [UnityEngine.Scripting.Preserve] - public static string DSASignData(string dataToSign, string privateKey) - { - byte[] res = DSASignData(Encoding.UTF8.GetBytes(dataToSign), privateKey); - return Convert.ToBase64String(res); - } - - /// - /// 使用 DSA 对数据进行签名。 - /// - /// - /// Signs data using DSA. - /// - /// 要签名的数据 / The data to sign - /// 签名后的字节数组 / The signed byte array - [UnityEngine.Scripting.Preserve] - public byte[] SignData(byte[] dataToSign) - { - try - { - return _dsa.SignData(dataToSign); - } - catch (Exception ex) - { - throw new GameFrameworkException("DSA sign data failed.", ex); - } - } - - /// - /// 使用 DSA 对字符串数据进行签名。 - /// - /// - /// Signs string data using DSA. - /// - /// 要签名的字符串数据 / The string data to sign - /// 签名后的 Base64 字符串 / The Base64 signed string - [UnityEngine.Scripting.Preserve] - public string SignData(string dataToSign) - { - byte[] res = SignData(Encoding.UTF8.GetBytes(dataToSign)); - return Convert.ToBase64String(res); - } - - /// - /// 验证签名。 - /// - /// - /// Verifies the signature. - /// - /// 要验证的数据 / The data to verify - /// 签名数据 / The signed data - /// 私钥字符串 / The private key string - /// 验证结果 / The verification result - [UnityEngine.Scripting.Preserve] - public static bool DSAVerifyData(byte[] dataToVerify, byte[] signedData, string privateKey) - { - try - { - DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); - dsa.FromXmlString(privateKey); - return dsa.VerifyData(dataToVerify, signedData); - } - catch (Exception ex) - { - throw new GameFrameworkException("DSA verify data failed.", ex); - } - } - - /// - /// 验证签名。 - /// - /// - /// Verifies the signature. - /// - /// 要验证的字符串数据 / The string data to verify - /// 签名的 Base64 字符串 / The Base64 signed string - /// 私钥字符串 / The private key string - /// 验证结果 / The verification result - [UnityEngine.Scripting.Preserve] - public static bool DSAVerifyData(string dataToVerify, string signedData, string privateKey) - { - return DSAVerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData), - privateKey); - } - - /// - /// 使用 DSA 验证签名。 - /// - /// - /// Verifies the signature using DSA. - /// - /// 要验证的数据 / The data to verify - /// 签名数据 / The signed data - /// 验证结果 / The verification result - [UnityEngine.Scripting.Preserve] - public bool VerifyData(byte[] dataToVerify, byte[] signedData) - { - try - { - return _dsa.VerifyData(dataToVerify, signedData); - } - catch (Exception ex) - { - throw new GameFrameworkException("DSA verify data failed.", ex); - } - } - - /// - /// 使用 DSA 验证签名。 - /// - /// - /// Verifies the signature using DSA. - /// - /// 要验证的字符串数据 / The string data to verify - /// 签名的 Base64 字符串 / The Base64 signed string - /// 验证结果 / The verification result - [UnityEngine.Scripting.Preserve] - public bool VerifyData(string dataToVerify, string signedData) - { - try - { - return VerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData)); - } - catch (Exception ex) - { - throw new GameFrameworkException("DSA verify data failed.", ex); - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.Rsa.cs b/Runtime/Utility/Utility.Encryption.Rsa.cs deleted file mode 100644 index 316f8fa..0000000 --- a/Runtime/Utility/Utility.Encryption.Rsa.cs +++ /dev/null @@ -1,260 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 加密解密相关的实用函数。 - /// - public static partial class Encryption - { - /// - /// RSA 加密算法的实现。 - /// - /// - /// RSA encryption algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public sealed class Rsa - { - private readonly RSACryptoServiceProvider _rsa = null; - - /// - /// 使用提供的 RSACryptoServiceProvider 实例初始化 Rsa 类。 - /// - /// - /// Initializes the Rsa class with the provided RSACryptoServiceProvider instance. - /// - /// RSACryptoServiceProvider 实例 / The RSACryptoServiceProvider instance - [UnityEngine.Scripting.Preserve] - public Rsa(RSACryptoServiceProvider rsa) - { - _rsa = rsa; - } - - /// - /// 使用提供的密钥字符串初始化 Rsa 类。 - /// - /// - /// Initializes the Rsa class with the provided key string. - /// - /// 密钥字符串 / The key string - [UnityEngine.Scripting.Preserve] - public Rsa(string key) - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.FromXmlString(key); - this._rsa = rsa; - } - - /// - /// 创建 RSA 密钥对。 - /// - /// - /// Creates an RSA key pair. - /// - /// 包含私钥和公钥的字典 / A dictionary containing the private key and public key - [UnityEngine.Scripting.Preserve] - public static Dictionary Make() - { - Dictionary dic = new Dictionary(); - RSACryptoServiceProvider dsa = new RSACryptoServiceProvider(); - dic["privateKey"] = dsa.ToXmlString(true); - dic["publicKey"] = dsa.ToXmlString(false); - return dic; - } - - /// - /// 使用公钥加密内容。 - /// - /// - /// Encrypts content using the public key. - /// - /// 公钥 / The public key - /// 要加密的内容 / The content to encrypt - /// 加密后的 Base64 字符串 / The Base64 encrypted string - [UnityEngine.Scripting.Preserve] - public static string RSAEncrypt(string publicKey, string content) - { - byte[] res = RSAEncrypt(publicKey, Encoding.UTF8.GetBytes(content)); - return Convert.ToBase64String(res); - } - - [UnityEngine.Scripting.Preserve] - public string Encrypt(string content) - { - byte[] res = Encrypt(Encoding.UTF8.GetBytes(content)); - return Convert.ToBase64String(res); - } - - [UnityEngine.Scripting.Preserve] - public static byte[] RSAEncrypt(string publicKey, byte[] content) - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.FromXmlString(publicKey); - byte[] cipherBytes = rsa.Encrypt(content, false); - return cipherBytes; - } - - [UnityEngine.Scripting.Preserve] - public byte[] Encrypt(byte[] content) - { - byte[] cipherBytes = _rsa.Encrypt(content, false); - return cipherBytes; - } - - /// - /// 使用私钥解密内容。 - /// - /// - /// Decrypts content using the private key. - /// - /// 私钥 / The private key - /// 加密后的内容 / The encrypted content - /// 解密后的内容 / The decrypted content - [UnityEngine.Scripting.Preserve] - public static string RSADecrypt(string privateKey, string content) - { - byte[] res = RSADecrypt(privateKey, Convert.FromBase64String(content)); - return Encoding.UTF8.GetString(res); - } - - [UnityEngine.Scripting.Preserve] - public static byte[] RSADecrypt(string privateKey, byte[] content) - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.FromXmlString(privateKey); - byte[] cipherBytes = rsa.Decrypt(content, false); - return cipherBytes; - } - - [UnityEngine.Scripting.Preserve] - public string Decrypt(string content) - { - byte[] res = Decrypt(Convert.FromBase64String(content)); - return Encoding.UTF8.GetString(res); - } - - [UnityEngine.Scripting.Preserve] - public byte[] Decrypt(byte[] content) - { - byte[] bytes = _rsa.Decrypt(content, false); - return bytes; - } - - /// - /// 使用私钥对数据进行签名。 - /// - /// - /// Signs data using the private key. - /// - /// 要签名的数据 / The data to sign - /// 私钥字符串 / The private key string - /// 签名后的字节数组 / The signed byte array - [UnityEngine.Scripting.Preserve] - public static byte[] RSASignData(byte[] dataToSign, string privateKey) - { - try - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.FromXmlString(privateKey); - return rsa.SignData(dataToSign, new SHA1CryptoServiceProvider()); - } - catch (Exception ex) - { - throw new GameFrameworkException("RSA sign data failed.", ex); - } - } - - [UnityEngine.Scripting.Preserve] - public static string RSASignData(string dataToSign, string privateKey) - { - byte[] res = RSASignData(Encoding.UTF8.GetBytes(dataToSign), privateKey); - return Convert.ToBase64String(res); - } - - [UnityEngine.Scripting.Preserve] - public byte[] SignData(byte[] dataToSign) - { - try - { - return _rsa.SignData(dataToSign, new SHA1CryptoServiceProvider()); - } - catch (Exception ex) - { - throw new GameFrameworkException("RSA sign data failed.", ex); - } - } - - [UnityEngine.Scripting.Preserve] - public string SignData(string dataToSign) - { - byte[] res = SignData(Encoding.UTF8.GetBytes(dataToSign)); - return Convert.ToBase64String(res); - } - - /// - /// 验证签名。 - /// - /// - /// Verifies the signature. - /// - /// 要验证的数据 / The data to verify - /// 签名数据 / The signed data - /// 公钥字符串 / The public key string - /// 验证结果 / The verification result - [UnityEngine.Scripting.Preserve] - public static bool RSAVerifyData(byte[] dataToVerify, byte[] signedData, string publicKey) - { - try - { - RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); - rsa.FromXmlString(publicKey); - return rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signedData); - } - catch (Exception ex) - { - throw new GameFrameworkException("RSA verify data failed.", ex); - } - } - - [UnityEngine.Scripting.Preserve] - public static bool RSAVerifyData(string dataToVerify, string signedData, string publicKey) - { - return RSAVerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData), - publicKey); - } - - [UnityEngine.Scripting.Preserve] - public bool VerifyData(byte[] dataToVerify, byte[] signedData) - { - try - { - return _rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signedData); - } - catch (Exception ex) - { - throw new GameFrameworkException("RSA verify data failed.", ex); - } - } - - [UnityEngine.Scripting.Preserve] - public bool VerifyData(string dataToVerify, string signedData) - { - try - { - return VerifyData(Encoding.UTF8.GetBytes(dataToVerify), Convert.FromBase64String(signedData)); - } - catch (Exception ex) - { - throw new GameFrameworkException("RSA verify data failed.", ex); - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Encryption.cs b/Runtime/Utility/Utility.Encryption.cs deleted file mode 100644 index 4a57ab6..0000000 --- a/Runtime/Utility/Utility.Encryption.cs +++ /dev/null @@ -1,173 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 加密解密相关的实用函数。 - /// - /// - /// Encryption and decryption related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static partial class Encryption - { - private const int QuickEncryptLength = 220; - - /// - /// 将 bytes 使用 code 做异或运算的快速版本。 - /// - /// 原始二进制流。 - /// 异或二进制流。 - /// 异或后的二进制流。 - [UnityEngine.Scripting.Preserve] - public static byte[] GetQuickXorBytes(byte[] bytes, byte[] code) - { - return GetXorBytes(bytes, 0, QuickEncryptLength, code); - } - - /// - /// 将 bytes 使用 code 做异或运算的快速版本。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 - /// - /// 原始及异或后的二进制流。 - /// 异或二进制流。 - [UnityEngine.Scripting.Preserve] - public static void GetQuickSelfXorBytes(byte[] bytes, byte[] code) - { - GetSelfXorBytes(bytes, 0, QuickEncryptLength, code); - } - - /// - /// 将 bytes 使用 code 做异或运算。 - /// - /// 原始二进制流。 - /// 异或二进制流。 - /// 异或后的二进制流。 - [UnityEngine.Scripting.Preserve] - public static byte[] GetXorBytes(byte[] bytes, byte[] code) - { - if (bytes == null) - { - return null; - } - - return GetXorBytes(bytes, 0, bytes.Length, code); - } - - /// - /// 将 bytes 使用 code 做异或运算。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 - /// - /// 原始及异或后的二进制流。 - /// 异或二进制流。 - [UnityEngine.Scripting.Preserve] - public static void GetSelfXorBytes(byte[] bytes, byte[] code) - { - if (bytes == null) - { - return; - } - - GetSelfXorBytes(bytes, 0, bytes.Length, code); - } - - /// - /// 将 bytes 使用 code 做异或运算。 - /// - /// 原始二进制流。 - /// 异或计算的开始位置。 - /// 异或计算长度,若小于 0,则计算整个二进制流。 - /// 异或二进制流。 - /// 异或后的二进制流。 - [UnityEngine.Scripting.Preserve] - public static byte[] GetXorBytes(byte[] bytes, int startIndex, int length, byte[] code) - { - if (bytes == null) - { - return null; - } - - int bytesLength = bytes.Length; - byte[] results = new byte[bytesLength]; - Array.Copy(bytes, 0, results, 0, bytesLength); - GetSelfXorBytes(results, startIndex, length, code); - return results; - } - - /// - /// 将 bytes 使用 code 做异或运算。此方法将复用并改写传入的 bytes 作为返回值,而不额外分配内存空间。 - /// - /// 原始及异或后的二进制流。 - /// 异或计算的开始位置。 - /// 异或计算长度。 - /// 异或二进制流。 - [UnityEngine.Scripting.Preserve] - public static void GetSelfXorBytes(byte[] bytes, int startIndex, int length, byte[] code) - { - if (bytes == null) - { - return; - } - - if (code == null) - { - throw new GameFrameworkException("Code is invalid."); - } - - int codeLength = code.Length; - if (codeLength <= 0) - { - throw new GameFrameworkException("Code length is invalid."); - } - - if (startIndex < 0 || length < 0 || startIndex + length > bytes.Length) - { - throw new GameFrameworkException("Start index or length is invalid."); - } - - int codeIndex = startIndex % codeLength; - for (int i = startIndex; i < startIndex + length; i++) - { - bytes[i] ^= code[codeIndex++]; - codeIndex %= codeLength; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.File.cs b/Runtime/Utility/Utility.File.cs deleted file mode 100644 index 814b91a..0000000 --- a/Runtime/Utility/Utility.File.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 文件相关的实用函数。 - /// - /// - /// File related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static class File - { - private static readonly string[] UnitList = new[] { "B", "KB", "MB", "GB", "TB", "PB" }; - - /// - /// 获取字节大小的可读字符串表示。 - /// - /// - /// Gets a human-readable string representation of byte size. - /// - /// 字节大小 / The byte size - /// 格式化后的字节大小字符串 / The formatted byte size string - [UnityEngine.Scripting.Preserve] - public static string GetBytesSize(long size) - { - double dSize = size; - int unitIndex = 0; - - while (dSize >= 1024 && unitIndex < UnitList.Length - 1) - { - dSize /= 1024; - unitIndex++; - } - - if (unitIndex == 0) - { - return dSize + UnitList[unitIndex]; - } - - // 格式化为保留两位小数,但去除尾部不必要的零 - string formattedSize = dSize.ToString("F2").TrimEnd('0').TrimEnd('.'); - return formattedSize + UnitList[unitIndex]; - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.HMACSha256.cs b/Runtime/Utility/Utility.Hash.HMACSha256.cs deleted file mode 100644 index 0f4a281..0000000 --- a/Runtime/Utility/Utility.Hash.HMACSha256.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 哈希计算相关的实用函数。 - /// - /// - /// Hash calculation related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static partial class Hash - { - /// - /// HMACSHA256 哈希算法的实现。 - /// - /// - /// HMACSHA256 hash algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public static class HMACSha256 - { - /// - /// 使用提供的密钥对指定消息进行 HMACSHA256 哈希计算。 - /// - /// - /// Computes the HMACSHA256 hash of the specified message using the provided key. - /// - /// 要进行哈希计算的消息 / The message to hash - /// 用于哈希计算的密钥 / The key for hash calculation - /// Base64 编码的哈希值 / The Base64 encoded hash value - [UnityEngine.Scripting.Preserve] - public static string Hash(string message, string key) - { - byte[] keyBytes = Encoding.UTF8.GetBytes(key); - byte[] messageBytes = Encoding.UTF8.GetBytes(message); - - using (var hmac = new HMACSHA256(keyBytes)) - { - byte[] hashBytes = hmac.ComputeHash(messageBytes); - return Convert.ToBase64String(hashBytes); - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.Md5.cs b/Runtime/Utility/Utility.Hash.Md5.cs deleted file mode 100644 index 2eb5f44..0000000 --- a/Runtime/Utility/Utility.Hash.Md5.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.IO; -using System.Text; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 哈希计算相关的实用函数。 - /// - /// - /// Hash calculation related utility functions. - /// - public static partial class Hash - { - /// - /// MD5 哈希算法的实现。 - /// - /// - /// MD5 hash algorithm implementation. - /// - [Preserve] - public static class MD5 - { - /// - /// 获取字符串的 MD5 哈希值。 - /// - /// - /// Gets the MD5 hash value of the string. - /// - /// 要计算哈希的字符串 / The string to hash - /// MD5 哈希值 / The MD5 hash value - [Preserve] - public static string Hash(string input) - { - using (var md5 = System.Security.Cryptography.MD5.Create()) - { - var data = md5.ComputeHash(Encoding.UTF8.GetBytes(input)); - return ToHash(data); - } - } - - /// - /// 获取流的 MD5 哈希值。 - /// - /// - /// Gets the MD5 hash value of the stream. - /// - /// 要计算哈希的流 / The stream to hash - /// MD5 哈希值 / The MD5 hash value - [Preserve] - public static string Hash(Stream input) - { - using (var md5 = System.Security.Cryptography.MD5.Create()) - { - var data = md5.ComputeHash(input); - return ToHash(data); - } - } - - /// - /// 验证 MD5 哈希值是否一致。 - /// - /// - /// Verifies if the MD5 hash values match. - /// - /// 要验证的哈希值 / The hash value to verify - /// 目标哈希值 / The target hash value - /// 如果一致则返回 true,否则返回 false / Returns true if they match, otherwise false - [Preserve] - public static bool IsVerify(string input, string hash) - { - var comparer = StringComparer.OrdinalIgnoreCase; - return 0 == comparer.Compare(input, hash); - } - - static string ToHash(byte[] data) - { - var sb = new StringBuilder(); - foreach (var t in data) - { - sb.Append(t.ToString("x2")); - } - - return sb.ToString(); - } - - /// - /// 获取指定文件路径的 MD5 哈希值。 - /// - /// - /// Gets the MD5 hash value of the file at the specified path. - /// - /// 文件路径 / The file path - /// MD5 哈希值 / The MD5 hash value - [Preserve] - public static string FileHash(string filePath) - { - using (var file = new FileStream(filePath, FileMode.Open)) - { - return Hash(file); - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.MurmurHash3.cs b/Runtime/Utility/Utility.Hash.MurmurHash3.cs deleted file mode 100644 index 4b3e302..0000000 --- a/Runtime/Utility/Utility.Hash.MurmurHash3.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 哈希计算相关的实用函数。 - /// - /// - /// Hash calculation related utility functions. - /// - public static partial class Hash - { - /// - /// MurmurHash3 哈希算法的实现。 - /// - /// - /// MurmurHash3 hash algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public static class MurmurHash3 - { - /// - /// 计算给定字符串的 MurmurHash3 哈希值。 - /// - /// - /// Computes the MurmurHash3 hash value of the given string. - /// - /// 要哈希的字符串 / The string to hash - /// 哈希种子,默认为 27 / The hash seed, default is 27 - /// 计算得到的哈希值 / The computed hash value - [UnityEngine.Scripting.Preserve] - public static uint Hash(string str, uint seed = 27) - { - var data = System.Text.Encoding.UTF8.GetBytes(str); - return Hash(data, (uint) data.Length, seed); - } - - private static uint Hash(byte[] data, uint length, uint seed) - { - uint nBlocks = length >> 2; - - uint h1 = seed; - - const uint c1 = 0xcc9e2d51; - const uint c2 = 0x1b873593; - - //---------- - // body - - int i = 0; - - for (uint j = nBlocks; j > 0; --j) - { - uint k1L = BitConverter.ToUInt32(data, i); - - k1L *= c1; - k1L = Rotl32(k1L, 15); - k1L *= c2; - - h1 ^= k1L; - h1 = Rotl32(h1, 13); - h1 = h1 * 5 + 0xe6546b64; - - i += 4; - } - - //---------- - // tail - - nBlocks <<= 2; - - uint k1 = 0; - - uint tailLength = length & 3; - - if (tailLength == 3) - k1 ^= (uint) data[2 + nBlocks] << 16; - if (tailLength >= 2) - k1 ^= (uint) data[1 + nBlocks] << 8; - if (tailLength >= 1) - { - k1 ^= data[nBlocks]; - k1 *= c1; - k1 = Rotl32(k1, 15); - k1 *= c2; - h1 ^= k1; - } - - //---------- - // finalization - - h1 ^= length; - - h1 = Fmix32(h1); - - return h1; - } - - static uint Fmix32(uint h) - { - h ^= h >> 16; - h *= 0x85ebca6b; - h ^= h >> 13; - h *= 0xc2b2ae35; - h ^= h >> 16; - - return h; - } - - static uint Rotl32(uint x, byte r) - { - return x << r | x >> 32 - r; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.Sha1.cs b/Runtime/Utility/Utility.Hash.Sha1.cs deleted file mode 100644 index 226239f..0000000 --- a/Runtime/Utility/Utility.Hash.Sha1.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 哈希计算相关的实用函数。 - /// - /// - /// Hash calculation related utility functions. - /// - public static partial class Hash - { - /// - /// SHA1 哈希算法的实现。 - /// - /// - /// SHA1 hash algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public static class Sha1 - { - - /// - /// 计算给定内容的 SHA1 哈希值,使用 UTF-8 编码。 - /// - /// - /// Computes the SHA1 hash value of the given content using UTF-8 encoding. - /// - /// 要计算哈希值的内容 / The content to hash - /// 返回计算得到的 SHA1 哈希值 / The computed SHA1 hash value - [UnityEngine.Scripting.Preserve] - public static string Hash(string content) - { - return Hash(content, Encoding.UTF8); - } - - /// - /// 使用指定编码计算 SHA1 哈希值。 - /// - /// - /// Computes the SHA1 hash value using the specified encoding. - /// - /// 要计算哈希值的内容 / The content to hash - /// 用于编码的 Encoding 对象 / The encoding to use - /// 返回计算得到的 SHA1 哈希值 / The computed SHA1 hash value - [UnityEngine.Scripting.Preserve] - public static string Hash(string content, Encoding encode) - { - //创建SHA1对象 - using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider()) - { - //将待加密字符串转为byte类型 - var bytesIn = encode.GetBytes(content); - var bytesOut = sha1.ComputeHash(bytesIn); - var result = BitConverter.ToString(bytesOut); //将运算结果转为string类型 - result = result.Replace("-", string.Empty).ToLower(); - return result; - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Hash.XxHash.cs b/Runtime/Utility/Utility.Hash.XxHash.cs deleted file mode 100644 index 088430a..0000000 --- a/Runtime/Utility/Utility.Hash.XxHash.cs +++ /dev/null @@ -1,375 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Text; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 哈希计算相关的实用函数。 - /// - /// - /// Hash calculation related utility functions. - /// - public static partial class Hash - { - /// - /// XXHash 哈希算法的实现。 - /// - /// - /// XXHash hash algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - public static class XXHash - { - /// - /// 计算给定字节数组的32位哈希值。 - /// - /// 要计算哈希值的字节数组。 - /// 返回计算得到的32位哈希值。 - [UnityEngine.Scripting.Preserve] - public static uint Hash32(byte[] buffer) - { - return XXHashHelper.Hash32(buffer); - } - - /// - /// 计算给定字符串的32位哈希值。 - /// - /// 要计算哈希值的字符串。 - /// 返回计算得到的32位哈希值。 - [UnityEngine.Scripting.Preserve] - public static uint Hash32(string text) - { - return XXHashHelper.Hash32(text); - } - - /// - /// 计算给定类型的32位哈希值。 - /// - /// 要计算哈希值的类型。 - /// 返回计算得到的32位哈希值。 - [UnityEngine.Scripting.Preserve] - public static uint Hash32(Type type) - { - return XXHashHelper.Hash32(type); - } - - /// - /// 计算给定泛型类型的32位哈希值。 - /// - /// 要计算哈希值的泛型类型。 - /// 返回计算得到的32位哈希值。 - [UnityEngine.Scripting.Preserve] - public static uint Hash32() - { - return XXHashHelper.Hash32(); - } - - /// - /// 计算给定字节数组的64位哈希值。 - /// - /// 要计算哈希值的字节数组。 - /// 返回计算得到的64位哈希值。 - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(byte[] buffer) - { - return XXHashHelper.Hash64(buffer); - } - - /// - /// 计算给定字符串的64位哈希值。 - /// - /// 要计算哈希值的字符串。 - /// 返回计算得到的64位哈希值。 - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(string text) - { - return XXHashHelper.Hash64(text); - } - - /// - /// 计算给定类型的64位哈希值。 - /// - /// 要计算哈希值的类型。 - /// 返回计算得到的64位哈希值。 - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(Type type) - { - return XXHashHelper.Hash64(type); - } - - /// - /// 计算给定泛型类型的64位哈希值。 - /// - /// 要计算哈希值的泛型类型。 - /// 返回计算得到的64位哈希值。 - [UnityEngine.Scripting.Preserve] - public static ulong Hash64() - { - return XXHashHelper.Hash64(); - } - } - - /// - /// XXHash 计算帮助类。 - /// - /// - /// XXHash calculation helper class. - /// - static class XXHashHelper - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static unsafe uint Hash32(byte* input, int length, uint seed = 0) - { - unchecked - { - const uint prime1 = 2654435761u; - const uint prime2 = 2246822519u; - const uint prime3 = 3266489917u; - const uint prime4 = 0668265263u; - const uint prime5 = 0374761393u; - - uint hash = seed + prime5; - - if (length >= 16) - { - uint val0 = seed + prime1 + prime2; - uint val1 = seed + prime2; - uint val2 = seed + 0; - uint val3 = seed - prime1; - - int count = length >> 4; - for (int i = 0; i < count; i++) - { - var pos0 = *(uint*) (input + 0); - var pos1 = *(uint*) (input + 4); - var pos2 = *(uint*) (input + 8); - var pos3 = *(uint*) (input + 12); - - val0 += pos0 * prime2; - val0 = (val0 << 13) | (val0 >> (32 - 13)); - val0 *= prime1; - - val1 += pos1 * prime2; - val1 = (val1 << 13) | (val1 >> (32 - 13)); - val1 *= prime1; - - val2 += pos2 * prime2; - val2 = (val2 << 13) | (val2 >> (32 - 13)); - val2 *= prime1; - - val3 += pos3 * prime2; - val3 = (val3 << 13) | (val3 >> (32 - 13)); - val3 *= prime1; - - input += 16; - } - - hash = ((val0 << 01) | (val0 >> (32 - 01))) + - ((val1 << 07) | (val1 >> (32 - 07))) + - ((val2 << 12) | (val2 >> (32 - 12))) + - ((val3 << 18) | (val3 >> (32 - 18))); - } - - hash += (uint) length; - - length &= 15; - while (length >= 4) - { - hash += *(uint*) input * prime3; - hash = ((hash << 17) | (hash >> (32 - 17))) * prime4; - input += 4; - length -= 4; - } - - while (length > 0) - { - hash += *input * prime5; - hash = ((hash << 11) | (hash >> (32 - 11))) * prime1; - ++input; - --length; - } - - hash ^= hash >> 15; - hash *= prime2; - hash ^= hash >> 13; - hash *= prime3; - hash ^= hash >> 16; - - return hash; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - static unsafe ulong Hash64(byte* input, int length, uint seed = 0) - { - unchecked - { - const ulong prime1 = 11400714785074694791ul; - const ulong prime2 = 14029467366897019727ul; - const ulong prime3 = 01609587929392839161ul; - const ulong prime4 = 09650029242287828579ul; - const ulong prime5 = 02870177450012600261ul; - - ulong hash = seed + prime5; - - if (length >= 32) - { - ulong val0 = seed + prime1 + prime2; - ulong val1 = seed + prime2; - ulong val2 = seed + 0; - ulong val3 = seed - prime1; - - int count = length >> 5; - for (int i = 0; i < count; i++) - { - var pos0 = *(ulong*) (input + 0); - var pos1 = *(ulong*) (input + 8); - var pos2 = *(ulong*) (input + 16); - var pos3 = *(ulong*) (input + 24); - - val0 += pos0 * prime2; - val0 = (val0 << 31) | (val0 >> (64 - 31)); - val0 *= prime1; - - val1 += pos1 * prime2; - val1 = (val1 << 31) | (val1 >> (64 - 31)); - val1 *= prime1; - - val2 += pos2 * prime2; - val2 = (val2 << 31) | (val2 >> (64 - 31)); - val2 *= prime1; - - val3 += pos3 * prime2; - val3 = (val3 << 31) | (val3 >> (64 - 31)); - val3 *= prime1; - - input += 32; - } - - hash = ((val0 << 01) | (val0 >> (64 - 01))) + - ((val1 << 07) | (val1 >> (64 - 07))) + - ((val2 << 12) | (val2 >> (64 - 12))) + - ((val3 << 18) | (val3 >> (64 - 18))); - - val0 *= prime2; - val0 = (val0 << 31) | (val0 >> (64 - 31)); - val0 *= prime1; - hash ^= val0; - hash = hash * prime1 + prime4; - - val1 *= prime2; - val1 = (val1 << 31) | (val1 >> (64 - 31)); - val1 *= prime1; - hash ^= val1; - hash = hash * prime1 + prime4; - - val2 *= prime2; - val2 = (val2 << 31) | (val2 >> (64 - 31)); - val2 *= prime1; - hash ^= val2; - hash = hash * prime1 + prime4; - - val3 *= prime2; - val3 = (val3 << 31) | (val3 >> (64 - 31)); - val3 *= prime1; - hash ^= val3; - hash = hash * prime1 + prime4; - } - - hash += (ulong) length; - - length &= 31; - while (length >= 8) - { - ulong lane = *(ulong*) input * prime2; - lane = ((lane << 31) | (lane >> (64 - 31))) * prime1; - hash ^= lane; - hash = ((hash << 27) | (hash >> (64 - 27))) * prime1 + prime4; - input += 8; - length -= 8; - } - - if (length >= 4) - { - hash ^= *(uint*) input * prime1; - hash = ((hash << 23) | (hash >> (64 - 23))) * prime2 + prime3; - input += 4; - length -= 4; - } - - while (length > 0) - { - hash ^= *input * prime5; - hash = ((hash << 11) | (hash >> (64 - 11))) * prime1; - ++input; - --length; - } - - hash ^= hash >> 33; - hash *= prime2; - hash ^= hash >> 29; - hash *= prime3; - hash ^= hash >> 32; - - return hash; - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static uint Hash32(byte[] buffer) - { - int length = buffer.Length; - unsafe - { - fixed (byte* pointer = buffer) - { - return Hash32(pointer, length); - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static uint Hash32(string text) => Hash32(Encoding.UTF8.GetBytes(text)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static uint Hash32(Type type) => Hash32(type.FullName); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static uint Hash32() => Hash32(typeof(T)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(byte[] buffer) - { - int length = buffer.Length; - unsafe - { - fixed (byte* pointer = buffer) - { - return Hash64(pointer, length); - } - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(string text) => Hash64(Encoding.UTF8.GetBytes(text)); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static ulong Hash64(Type type) => Hash64(type.FullName); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [UnityEngine.Scripting.Preserve] - public static ulong Hash64() => Hash64(typeof(T)); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.IdGenerator.cs b/Runtime/Utility/Utility.IdGenerator.cs deleted file mode 100644 index 5b550b8..0000000 --- a/Runtime/Utility/Utility.IdGenerator.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Threading; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// ID 生成器相关的实用函数。 - /// - /// - /// ID generator related utility functions. - /// - /// - /// ID 生成器相关的实用函数。 - /// - /// - /// ID generator related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static class IdGenerator - { - /// - /// 全局UTC起始时间,用作计数器的基准时间点。 - /// 设置为2020年1月1日0时0分0秒(UTC)。 - /// - /// - /// Global UTC start time, used as the reference point for the counter. - /// Set to January 1, 2020, 00:00:00 (UTC). - /// - public static readonly DateTime UtcTimeStart = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc); - - // 共享计数器 - private static long _counter = (long)(DateTime.UtcNow - UtcTimeStart).TotalSeconds; - private static int _intCounter = (int)(DateTime.UtcNow - UtcTimeStart).TotalSeconds; - - /// - /// 使用 Interlocked.Increment 生成唯一的长整型ID。 - /// - /// - /// Generates a unique long integer ID using Interlocked.Increment. - /// - /// 返回一个唯一的长整型ID / A unique long integer ID - [UnityEngine.Scripting.Preserve] - public static long GetNextUniqueId() - { - // 原子性地递增值 - return Interlocked.Increment(ref _counter); - } - - /// - /// 使用 Interlocked.Increment 生成唯一的整型ID。 - /// - /// - /// Generates a unique integer ID using Interlocked.Increment. - /// - /// 返回一个唯一的整型ID / A unique integer ID - [UnityEngine.Scripting.Preserve] - public static int GetNextUniqueIntId() - { - return Interlocked.Increment(ref _intCounter); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Json.IJsonHelper.cs.meta b/Runtime/Utility/Utility.Json.IJsonHelper.cs.meta deleted file mode 100644 index e093ec8..0000000 --- a/Runtime/Utility/Utility.Json.IJsonHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 845c3d12e67de0249b60934d1d850a56 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Json.cs b/Runtime/Utility/Utility.Json.cs deleted file mode 100644 index 2894be2..0000000 --- a/Runtime/Utility/Utility.Json.cs +++ /dev/null @@ -1,156 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// JSON 相关的实用函数。 - /// - /// - /// JSON related utility functions. - /// - public static partial class Json - { - private static IJsonHelper s_JsonHelper = null; - - /// - /// 设置 JSON 辅助器。 - /// - /// - /// Sets the JSON helper. - /// - /// 要设置的 JSON 辅助器 / The JSON helper to set - [Preserve] - public static void SetJsonHelper(IJsonHelper jsonHelper) - { - s_JsonHelper = jsonHelper; - } - - /// - /// 将对象序列化为 JSON 字符串。 - /// - /// 要序列化的对象。 - /// 序列化后的 JSON 字符串。 - [Preserve] - public static string ToJson(object obj) - { - if (s_JsonHelper == null) - { - throw new GameFrameworkException("JSON helper is invalid."); - } - - try - { - return s_JsonHelper.ToJson(obj); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not convert to JSON with exception '{0}'.", exception), exception); - } - } - - /// - /// 将 JSON 字符串反序列化为对象。 - /// - /// 对象类型。 - /// 要反序列化的 JSON 字符串。 - /// 反序列化后的对象。 - [Preserve] - public static T ToObject(string json) - { - if (s_JsonHelper == null) - { - throw new GameFrameworkException("JSON helper is invalid."); - } - - try - { - return s_JsonHelper.ToObject(json); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not convert to object with exception '{0}'.", exception), exception); - } - } - - /// - /// 将 JSON 字符串反序列化为对象。 - /// - /// 对象类型。 - /// 要反序列化的 JSON 字符串。 - /// 反序列化后的对象。 - [Preserve] - public static object ToObject(Type objectType, string json) - { - if (s_JsonHelper == null) - { - throw new GameFrameworkException("JSON helper is invalid."); - } - - if (objectType == null) - { - throw new GameFrameworkException("Object type is invalid."); - } - - try - { - return s_JsonHelper.ToObject(objectType, json); - } - catch (Exception exception) - { - if (exception is GameFrameworkException) - { - throw; - } - - throw new GameFrameworkException(Text.Format("Can not convert to object with exception '{0}'.", exception), exception); - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Json.cs.meta b/Runtime/Utility/Utility.Json.cs.meta deleted file mode 100644 index 05f6f18..0000000 --- a/Runtime/Utility/Utility.Json.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7b5c8538c4ca0bf4abed59f5dd4c6cfe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Marshal.cs b/Runtime/Utility/Utility.Marshal.cs deleted file mode 100644 index 87bc43c..0000000 --- a/Runtime/Utility/Utility.Marshal.cs +++ /dev/null @@ -1,297 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// Marshal 相关的实用函数。 - /// - /// - /// Marshal related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static class Marshal - { - private const int BlockSize = 1024 * 4; - private static IntPtr _cachedHGlobalPtr = IntPtr.Zero; - private static int _cachedHGlobalSize; - private static readonly object Lock = new object(); - - /// - /// 获取缓存的从进程的非托管内存中分配的内存的大小。 - /// - [UnityEngine.Scripting.Preserve] - public static int CachedHGlobalSize - { - get { return _cachedHGlobalSize; } - } - - /// - /// 确保从进程的非托管内存中分配足够大小的内存并缓存。 - /// - /// 要确保从进程的非托管内存中分配内存的大小。 - [UnityEngine.Scripting.Preserve] - public static void EnsureCachedHGlobalSize(int ensureSize) - { - if (ensureSize < 0) - { - throw new GameFrameworkException("Ensure size is invalid."); - } - - lock (Lock) - { - if (_cachedHGlobalPtr == IntPtr.Zero || _cachedHGlobalSize < ensureSize) - { - FreeCachedHGlobal(); - var size = (ensureSize - 1 + BlockSize) / BlockSize * BlockSize; - _cachedHGlobalPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(size); - _cachedHGlobalSize = size; - } - } - } - - /// - /// 释放缓存的从进程的非托管内存中分配的内存。 - /// - [UnityEngine.Scripting.Preserve] - public static void FreeCachedHGlobal() - { - lock (Lock) - { - if (_cachedHGlobalPtr != IntPtr.Zero) - { - System.Runtime.InteropServices.Marshal.FreeHGlobal(_cachedHGlobalPtr); - _cachedHGlobalPtr = IntPtr.Zero; - _cachedHGlobalSize = 0; - } - } - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 存储转换结果的二进制流。 - [UnityEngine.Scripting.Preserve] - public static byte[] StructureToBytes(T structure) - { - return StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T))); - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 要转换的对象的大小。 - /// 存储转换结果的二进制流。 - [UnityEngine.Scripting.Preserve] - internal static byte[] StructureToBytes(T structure, int structureSize) - { - if (structureSize < 0) - { - throw new GameFrameworkException("Structure size is invalid."); - } - - var result = new byte[structureSize]; - lock (Lock) - { - EnsureCachedHGlobalSize(structureSize); - System.Runtime.InteropServices.Marshal.StructureToPtr(structure, _cachedHGlobalPtr, true); - System.Runtime.InteropServices.Marshal.Copy(_cachedHGlobalPtr, result, 0, structureSize); - } - - return result; - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 存储转换结果的二进制流。 - [UnityEngine.Scripting.Preserve] - public static void StructureToBytes(T structure, byte[] result) - { - StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), result, 0); - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 要转换的对象的大小。 - /// 存储转换结果的二进制流。 - [UnityEngine.Scripting.Preserve] - internal static void StructureToBytes(T structure, int structureSize, byte[] result) - { - StructureToBytes(structure, structureSize, result, 0); - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 存储转换结果的二进制流。 - /// 写入存储转换结果的二进制流的起始位置。 - [UnityEngine.Scripting.Preserve] - public static void StructureToBytes(T structure, byte[] result, int startIndex) - { - StructureToBytes(structure, System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), result, startIndex); - } - - /// - /// 将数据从对象转换为二进制流。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象。 - /// 要转换的对象的大小。 - /// 存储转换结果的二进制流。 - /// 写入存储转换结果的二进制流的起始位置。 - [UnityEngine.Scripting.Preserve] - internal static void StructureToBytes(T structure, int structureSize, byte[] result, int startIndex) - { - if (structureSize < 0) - { - throw new GameFrameworkException("Structure size is invalid."); - } - - if (result == null) - { - throw new GameFrameworkException("Result is invalid."); - } - - if (startIndex < 0) - { - throw new GameFrameworkException("Start index is invalid."); - } - - if (startIndex + structureSize > result.Length) - { - throw new GameFrameworkException("Result length is not enough."); - } - - lock (Lock) - { - EnsureCachedHGlobalSize(structureSize); - System.Runtime.InteropServices.Marshal.StructureToPtr(structure, _cachedHGlobalPtr, true); - System.Runtime.InteropServices.Marshal.Copy(_cachedHGlobalPtr, result, startIndex, structureSize); - } - } - - /// - /// 将数据从二进制流转换为对象。 - /// - /// 要转换的对象的类型。 - /// 要转换的二进制流。 - /// 存储转换结果的对象。 - [UnityEngine.Scripting.Preserve] - public static T BytesToStructure(byte[] buffer) - { - return BytesToStructure(System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), buffer, 0); - } - - /// - /// 将数据从二进制流转换为对象。 - /// - /// 要转换的对象的类型。 - /// 要转换的二进制流。 - /// 读取要转换的二进制流的起始位置。 - /// 存储转换结果的对象。 - [UnityEngine.Scripting.Preserve] - public static T BytesToStructure(byte[] buffer, int startIndex) - { - return BytesToStructure(System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)), buffer, startIndex); - } - - /// - /// 将数据从二进制流转换为对象。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象的大小。 - /// 要转换的二进制流。 - /// 存储转换结果的对象。 - [UnityEngine.Scripting.Preserve] - internal static T BytesToStructure(int structureSize, byte[] buffer) - { - return BytesToStructure(structureSize, buffer, 0); - } - - /// - /// 将数据从二进制流转换为对象。 - /// - /// 要转换的对象的类型。 - /// 要转换的对象的大小。 - /// 要转换的二进制流。 - /// 读取要转换的二进制流的起始位置。 - /// 存储转换结果的对象。 - [UnityEngine.Scripting.Preserve] - internal static T BytesToStructure(int structureSize, byte[] buffer, int startIndex) - { - if (structureSize < 0) - { - throw new GameFrameworkException("Structure size is invalid."); - } - - if (buffer == null) - { - throw new GameFrameworkException("Buffer is invalid."); - } - - if (startIndex < 0) - { - throw new GameFrameworkException("Start index is invalid."); - } - - if (startIndex + structureSize > buffer.Length) - { - throw new GameFrameworkException("Buffer length is not enough."); - } - - lock (Lock) - { - EnsureCachedHGlobalSize(structureSize); - System.Runtime.InteropServices.Marshal.Copy(buffer, startIndex, _cachedHGlobalPtr, structureSize); - return (T)System.Runtime.InteropServices.Marshal.PtrToStructure(_cachedHGlobalPtr, typeof(T)); - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Net.cs b/Runtime/Utility/Utility.Net.cs deleted file mode 100644 index 72ca60b..0000000 --- a/Runtime/Utility/Utility.Net.cs +++ /dev/null @@ -1,185 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Net; -using System.Net.NetworkInformation; -using System.Net.Sockets; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 网络相关的实用函数。 - /// - /// - /// Network related utility functions. - /// - [Preserve] - public static class Net - { - /// - /// 获取第一个可用的端口号 - /// - /// 起始端口号 - /// 结束端口号 - /// 返回第一个可用的端口号,如果没有可用端口则返回-1 - [Preserve] - public static int GetFirstAvailablePort(int startPort = 667, int maxPort = 65535) - { - for (int i = startPort; i < maxPort; i++) - { - if (PortIsAvailable(i)) return i; - } - - return -1; - } - - /// - /// 获取操作系统已用的端口号 - /// - /// 返回一个包含所有已用端口号的列表 - [Preserve] - public static List PortIsUsed() - { - //获取本地计算机的网络连接和通信统计数据的信息 - var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); - - //返回本地计算机上的所有Tcp监听程序 - var ipsTcp = ipGlobalProperties.GetActiveTcpListeners(); - - //返回本地计算机上的所有UDP监听程序 - var ipsUDP = ipGlobalProperties.GetActiveUdpListeners(); - - //返回本地计算机上的Internet协议版本4(IPV4 传输控制协议(TCP)连接的信息。 - var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); - - var allPorts = new List(); - foreach (var ep in ipsTcp) - { - allPorts.Add(ep.Port); - } - - foreach (var ep in ipsUDP) - { - allPorts.Add(ep.Port); - } - - foreach (var conn in tcpConnInfoArray) - { - allPorts.Add(conn.LocalEndPoint.Port); - } - - return allPorts; - } - - /// - /// 检查指定端口是否已用 - /// - /// 要检查的端口号 - /// 如果端口可用则返回true,否则返回false - [Preserve] - public static bool PortIsAvailable(int port) - { - var isAvailable = true; - - var portUsed = PortIsUsed(); - - foreach (int p in portUsed) - { - if (p == port) - { - isAvailable = false; - break; - } - } - - return isAvailable; - } - - /// - /// 获取域名的IpV4 地址 - /// - /// 域名 - /// 返回域名的IPv4地址,如果没有则返回空字符串 - [Preserve] - public static string GetHostIPv4(string domainName) - { - var iPHostEntry = Dns.GetHostEntry(domainName); - foreach (var address in iPHostEntry.AddressList) - { - if (address.AddressFamily == AddressFamily.InterNetwork) - { - return address.ToString(); - } - } - - return string.Empty; - } - - /// - /// 获取域名的IpV6 地址 - /// - /// 域名 - /// 返回域名的IPv4地址,如果没有则返回空字符串 - [Preserve] - public static string GetHostIPv6(string domainName) - { - var iPHostEntry = Dns.GetHostEntry(domainName); - foreach (var address in iPHostEntry.AddressList) - { - if (address.AddressFamily == AddressFamily.InterNetworkV6) - { - return address.ToString(); - } - } - - return string.Empty; - } - - /// - /// 获取本机ip地址 - /// - /// 返回本机的IPv4地址,如果没有则返回空字符串 - [Preserve] - public static string GetIP() - { - var hostName = Dns.GetHostName(); - var iPHostEntry = Dns.GetHostEntry(hostName); - foreach (var address in iPHostEntry.AddressList) - { - if (address.AddressFamily == AddressFamily.InterNetwork) - { - return address.ToString(); - } - } - - return string.Empty; - } - - [Preserve] - public static (AddressFamily, string) GetIPv6Address(string host) - { - var addresses = Dns.GetHostAddresses(host); - - foreach (var ipAddress in addresses) - { - if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) - { - return (AddressFamily.InterNetworkV6, ipAddress.ToString()); - } - } - - foreach (var ipAddress in addresses) - { - if (ipAddress.AddressFamily == AddressFamily.InterNetwork) - { - return (AddressFamily.InterNetwork, ipAddress.ToString()); - } - } - - return (AddressFamily.InterNetwork, host); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Object.cs b/Runtime/Utility/Utility.Object.cs deleted file mode 100644 index f38a22d..0000000 --- a/Runtime/Utility/Utility.Object.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// Object 对象工具类。 - /// - /// - /// Object utility class. - /// - [UnityEngine.Scripting.Preserve] - public static class Object - { - /// - /// 交换两个对象的值。 - /// - /// - /// Swaps the values of two objects. - /// - /// 第一个对象的引用 / Reference to the first object - /// 第二个对象的引用 / Reference to the second object - /// 对象的类型 / The type of the objects - [UnityEngine.Scripting.Preserve] - public static void Swap(ref T t1, ref T t2) - { - (t1, t2) = (t2, t1); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Path.cs b/Runtime/Utility/Utility.Path.cs deleted file mode 100644 index bc21dc8..0000000 --- a/Runtime/Utility/Utility.Path.cs +++ /dev/null @@ -1,142 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System.IO; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 路径相关的实用函数。 - /// - /// - /// Path related utility functions. - /// - [UnityEngine.Scripting.Preserve] - public static class Path - { - /// - /// 获取规范的路径。 - /// - /// - /// Gets the regularized path. - /// - /// 要规范的路径 / The path to regularize - /// 规范的路径 / The regularized path - [UnityEngine.Scripting.Preserve] - public static string GetRegularPath(string path) - { - if (path == null) - { - return null; - } - - return path.Replace('\\', '/'); - } - - /// - /// 获取远程格式的路径(带有file:// 或 http:// 前缀)。 - /// - /// - /// Gets the remote format path (with file:// or http:// prefix). - /// - /// 原始路径 / The original path - /// 远程格式路径 / The remote format path - [UnityEngine.Scripting.Preserve] - public static string GetRemotePath(string path) - { - string regularPath = GetRegularPath(path); - if (regularPath == null) - { - return null; - } - - return regularPath.Contains("://") ? regularPath : ("file:///" + regularPath).Replace("file:////", "file:///"); - } - - /// - /// 移除空文件夹。 - /// - /// - /// Removes empty directories. - /// - /// 要处理的文件夹名称 / The directory name to process - /// 是否移除空文件夹成功 / Whether the empty directory was removed successfully - [UnityEngine.Scripting.Preserve] - public static bool RemoveEmptyDirectory(string directoryName) - { - if (string.IsNullOrEmpty(directoryName)) - { - throw new GameFrameworkException("Directory name is invalid."); - } - - try - { - if (!Directory.Exists(directoryName)) - { - return false; - } - - // 不使用 SearchOption.AllDirectories,以便于在可能产生异常的环境下删除尽可能多的目录 - string[] subDirectoryNames = Directory.GetDirectories(directoryName, "*"); - int subDirectoryCount = subDirectoryNames.Length; - foreach (string subDirectoryName in subDirectoryNames) - { - if (RemoveEmptyDirectory(subDirectoryName)) - { - subDirectoryCount--; - } - } - - if (subDirectoryCount > 0) - { - return false; - } - - if (Directory.GetFiles(directoryName, "*").Length > 0) - { - return false; - } - - Directory.Delete(directoryName); - return true; - } - catch - { - return false; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.RandomUtility.cs b/Runtime/Utility/Utility.RandomUtility.cs deleted file mode 100644 index 19c9b62..0000000 --- a/Runtime/Utility/Utility.RandomUtility.cs +++ /dev/null @@ -1,139 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.Threading; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 随机相关的实用函数。 - /// - /// - /// Random related utility functions. - /// - [Preserve] - public static class RandomUtility - { - private static int s_Seed = (int)DateTime.UtcNow.Ticks; - private static ThreadLocal s_Random = new ThreadLocal(() => new System.Random(Interlocked.Increment(ref s_Seed))); - - /// - /// 设置随机数种子。 - /// - /// - /// Sets the random seed. - /// - /// 随机数种子 / The random seed - [Preserve] - public static void SetSeed(int seed) - { - s_Seed = seed; - var oldRandom = s_Random; - s_Random = new ThreadLocal(() => new System.Random(Interlocked.Increment(ref s_Seed))); - oldRandom.Dispose(); - } - - /// - /// 返回非负随机数。 - /// - /// - /// Returns a non-negative random number. - /// - /// 返回一个大于等于零且小于 System.Int32.MaxValue 的 32 位带符号整数 / A 32-bit signed integer that is greater than or equal to 0 and less than System.Int32.MaxValue - [Preserve] - public static int GetRandom() - { - return s_Random.Value.Next(); - } - - /// - /// 返回一个小于所指定最大值的非负随机数。 - /// - /// - /// Returns a non-negative random number that is less than the specified maximum. - /// - /// 要生成的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于零 / The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero - /// 返回一个大于等于零且小于 maxValue 的 32 位带符号整数。如果 maxValue 等于零,则返回 maxValue / A 32-bit signed integer that is greater than or equal to 0 and less than maxValue. If maxValue equals 0, maxValue is returned - [Preserve] - public static int GetRandom(int maxValue) - { - return s_Random.Value.Next(maxValue); - } - - /// - /// 返回一个指定范围内的随机数。 - /// - /// - /// Returns a random number within a specified range. - /// - /// 返回的随机数的下界(随机数可取该下界值) / The inclusive lower bound of the random number returned - /// 返回的随机数的上界(随机数不能取该上界值)。maxValue 必须大于等于 minValue / The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue - /// 返回一个大于等于 minValue 且小于 maxValue 的 32 位带符号整数。如果 minValue 等于 maxValue,则返回 minValue / A 32-bit signed integer greater than or equal to minValue and less than maxValue. If minValue equals maxValue, minValue is returned - [Preserve] - public static int GetRandom(int minValue, int maxValue) - { - return s_Random.Value.Next(minValue, maxValue); - } - - /// - /// 返回一个介于 0.0 和 1.0 之间的随机数。 - /// - /// - /// Returns a random number between 0.0 and 1.0. - /// - /// 返回一个大于等于 0.0 并且小于 1.0 的双精度浮点数 / A double-precision floating point number that is greater than or equal to 0.0 and less than 1.0 - [Preserve] - public static double GetRandomDouble() - { - return s_Random.Value.NextDouble(); - } - - /// - /// 用随机数填充指定字节数组的元素。 - /// - /// - /// Fills the elements of a specified array of bytes with random numbers. - /// - /// 包含随机数的字节数组 / The byte array to contain random numbers - [Preserve] - public static void GetRandomBytes(byte[] buffer) - { - s_Random.Value.NextBytes(buffer); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Text.ITextHelper.cs b/Runtime/Utility/Utility.Text.ITextHelper.cs deleted file mode 100644 index b66d3dd..0000000 --- a/Runtime/Utility/Utility.Text.ITextHelper.cs +++ /dev/null @@ -1,442 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - public static partial class Text - { - /// - /// 字符辅助器接口。 - /// - /// - /// Text helper interface. - /// - public interface ITextHelper - { - /// - /// 获取格式化字符串。 - /// - /// 字符串格式。 - /// 参数列表。 - /// 格式化后的字符串。 - string Format(string format, params object[] args); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数的类型。 - /// 字符串格式。 - /// 字符串参数。 - /// 格式化后的字符串。 - string Format(string format, T arg); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串参数 12 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 字符串参数 12。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串参数 12 的类型。 - /// 字符串参数 13 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 字符串参数 12。 - /// 字符串参数 13。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串参数 12 的类型。 - /// 字符串参数 13 的类型。 - /// 字符串参数 14 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 字符串参数 12。 - /// 字符串参数 13。 - /// 字符串参数 14。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串参数 12 的类型。 - /// 字符串参数 13 的类型。 - /// 字符串参数 14 的类型。 - /// 字符串参数 15 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 字符串参数 12。 - /// 字符串参数 13。 - /// 字符串参数 14。 - /// 字符串参数 15。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15); - - /// - /// 获取格式化字符串。 - /// - /// 字符串参数 1 的类型。 - /// 字符串参数 2 的类型。 - /// 字符串参数 3 的类型。 - /// 字符串参数 4 的类型。 - /// 字符串参数 5 的类型。 - /// 字符串参数 6 的类型。 - /// 字符串参数 7 的类型。 - /// 字符串参数 8 的类型。 - /// 字符串参数 9 的类型。 - /// 字符串参数 10 的类型。 - /// 字符串参数 11 的类型。 - /// 字符串参数 12 的类型。 - /// 字符串参数 13 的类型。 - /// 字符串参数 14 的类型。 - /// 字符串参数 15 的类型。 - /// 字符串参数 16 的类型。 - /// 字符串格式。 - /// 字符串参数 1。 - /// 字符串参数 2。 - /// 字符串参数 3。 - /// 字符串参数 4。 - /// 字符串参数 5。 - /// 字符串参数 6。 - /// 字符串参数 7。 - /// 字符串参数 8。 - /// 字符串参数 9。 - /// 字符串参数 10。 - /// 字符串参数 11。 - /// 字符串参数 12。 - /// 字符串参数 13。 - /// 字符串参数 14。 - /// 字符串参数 15。 - /// 字符串参数 16。 - /// 格式化后的字符串。 - string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Text.ITextHelper.cs.meta b/Runtime/Utility/Utility.Text.ITextHelper.cs.meta deleted file mode 100644 index 65ed6ea..0000000 --- a/Runtime/Utility/Utility.Text.ITextHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8d5557039b48bfa41bfee705a4c55e7c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Text.cs.meta b/Runtime/Utility/Utility.Text.cs.meta deleted file mode 100644 index 76312f5..0000000 --- a/Runtime/Utility/Utility.Text.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: e24f036db8b212749997897120eb8cc5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/Utility.Verifier.Crc32.cs b/Runtime/Utility/Utility.Verifier.Crc32.cs deleted file mode 100644 index c80c788..0000000 --- a/Runtime/Utility/Utility.Verifier.Crc32.cs +++ /dev/null @@ -1,165 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - public static partial class Verifier - { - /// - /// CRC32 算法。 - /// - /// - /// CRC32 algorithm implementation. - /// - [UnityEngine.Scripting.Preserve] - private sealed class Crc32 - { - private const int TableLength = 256; - private const uint DefaultPolynomial = 0xedb88320; - private const uint DefaultSeed = 0xffffffff; - - private readonly uint m_Seed; - private readonly uint[] m_Table; - private uint m_Hash; - - /// - /// 初始化 CRC32 类的新实例。 - /// - /// - /// Initializes a new instance of the CRC32 class. - /// - [UnityEngine.Scripting.Preserve] - public Crc32() - : this(DefaultPolynomial, DefaultSeed) - { - } - - /// - /// 使用指定的多项式和种子初始化 CRC32 类的新实例。 - /// - /// - /// Initializes a new instance of the CRC32 class with the specified polynomial and seed. - /// - /// 用于计算 CRC 的多项式 / The polynomial for CRC calculation - /// 用于初始化哈希值的种子 / The seed for initializing the hash value - [UnityEngine.Scripting.Preserve] - public Crc32(uint polynomial, uint seed) - { - m_Seed = seed; - m_Table = InitializeTable(polynomial); - m_Hash = seed; - } - - /// - /// 初始化 CRC32 计算。 - /// - /// - /// Initializes the CRC32 calculation. - /// - [UnityEngine.Scripting.Preserve] - public void Initialize() - { - m_Hash = m_Seed; - } - - /// - /// 计算给定字节数组的哈希值。 - /// - /// - /// Computes the hash value of the given byte array. - /// - /// 要计算哈希的字节数组 / The byte array to hash - /// 字节数组的起始偏移量 / The starting offset in the byte array - /// 要计算的字节数 / The number of bytes to compute - [UnityEngine.Scripting.Preserve] - public void HashCore(byte[] bytes, int offset, int length) - { - m_Hash = CalculateHash(m_Table, m_Hash, bytes, offset, length); - } - - /// - /// 返回计算的 CRC32 哈希值。 - /// - /// - /// Returns the computed CRC32 hash value. - /// - /// 计算的 CRC32 哈希值 / The computed CRC32 hash value - [UnityEngine.Scripting.Preserve] - public uint HashFinal() - { - return ~m_Hash; - } - - private static uint CalculateHash(uint[] table, uint value, byte[] bytes, int offset, int length) - { - int last = offset + length; - for (int i = offset; i < last; i++) - { - unchecked - { - value = (value >> 8) ^ table[bytes[i] ^ value & 0xff]; - } - } - - return value; - } - - private static uint[] InitializeTable(uint polynomial) - { - uint[] table = new uint[TableLength]; - for (int i = 0; i < TableLength; i++) - { - uint entry = (uint)i; - for (int j = 0; j < 8; j++) - { - if ((entry & 1) == 1) - { - entry = (entry >> 1) ^ polynomial; - } - else - { - entry >>= 1; - } - } - - table[i] = entry; - } - - return table; - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Verifier.Crc64.cs b/Runtime/Utility/Utility.Verifier.Crc64.cs deleted file mode 100644 index 4c4c61a..0000000 --- a/Runtime/Utility/Utility.Verifier.Crc64.cs +++ /dev/null @@ -1,646 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.Buffers; -using System.Buffers.Binary; -using System.ComponentModel; -using System.IO; -using System.Threading; -using UnityEngine; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - public static partial class Verifier - { - /// - /// 提供了根据 ECMA-182 附录 B 描述的 CRC-64 算法的实现。 - /// - /// - /// - /// 对于返回字节数组或写入字节跨度的方法, - /// 此实现以大端字节顺序发出答案,以便 - /// CRC 残差关系(CRC(消息连接 CRC(消息)))是固定值。 - /// 对于 CRC-64,此稳定输出是字节序列 - /// { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }。 - /// - /// - /// 有多个不兼容的 64 位循环冗余 - /// 检查(CRC)算法的定义。在与另一个系统互操作时,请确保您 - /// 使用相同的定义。此实现使用的定义与 - /// ISO 3309 中描述的循环冗余检查不兼容。 - /// - /// - [UnityEngine.Scripting.Preserve] - public sealed partial class Crc64 : NonCryptographicHashAlgorithm - { - private const ulong InitialState = 0UL; - private const int Size = sizeof(ulong); - - private ulong _crc = InitialState; - - /// - /// 初始化 类的新实例。 - /// - [UnityEngine.Scripting.Preserve] - public Crc64() - : base(Size) - { - } - - /// - /// 将 的内容附加到当前哈希计算中已处理的数据。 - /// - /// 要处理的数据。 - [UnityEngine.Scripting.Preserve] - public override void Append(ReadOnlySpan source) - { - _crc = Update(_crc, source); - } - - /// - /// 将哈希计算重置为初始状态。 - /// - [UnityEngine.Scripting.Preserve] - public override void Reset() - { - _crc = InitialState; - } - - /// - /// 将计算出的哈希值写入 - /// 而不修改累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - [UnityEngine.Scripting.Preserve] - protected override void GetCurrentHashCore(Span destination) - { - BinaryPrimitives.WriteUInt64BigEndian(destination, _crc); - } - - /// - /// 将计算出的哈希值写入 - /// 然后清除累积状态。 - /// - [UnityEngine.Scripting.Preserve] - protected override void GetHashAndResetCore(Span destination) - { - BinaryPrimitives.WriteUInt64BigEndian(destination, _crc); - _crc = InitialState; - } - - /// - /// 获取当前计算的哈希值而不修改累积状态。 - /// - /// 已提供数据的哈希值。 - [UnityEngine.Scripting.Preserve] - public ulong GetCurrentHashAsUInt64() => _crc; - - /// - /// 计算提供数据的 CRC-64 哈希值。 - /// - /// 要哈希的数据。 - /// 提供数据的 CRC-64 哈希值。 - /// - /// 。 - /// - [UnityEngine.Scripting.Preserve] - public static byte[] Hash(byte[] source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - return Hash(new ReadOnlySpan(source)); - } - - /// - /// 计算提供数据的 CRC-64 哈希值。 - /// - /// 要哈希的数据。 - /// 提供数据的 CRC-64 哈希值。 - [UnityEngine.Scripting.Preserve] - public static byte[] Hash(ReadOnlySpan source) - { - byte[] ret = new byte[Size]; - ulong hash = HashToUInt64(source); - BinaryPrimitives.WriteUInt64BigEndian(ret, hash); - return ret; - } - - /// - /// 尝试将提供数据的 CRC-64 哈希值计算到提供的目标中。 - /// - /// 要哈希的数据。 - /// 接收计算哈希值的缓冲区。 - /// - /// 成功时,接收写入 的字节数。 - /// - /// - /// 如果 足够长以接收 - /// 计算的哈希值(8 字节);否则 。 - /// - [UnityEngine.Scripting.Preserve] - public static bool TryHash(ReadOnlySpan source, Span destination, out int bytesWritten) - { - if (destination.Length < Size) - { - bytesWritten = 0; - return false; - } - - ulong hash = HashToUInt64(source); - BinaryPrimitives.WriteUInt64BigEndian(destination, hash); - bytesWritten = Size; - return true; - } - - /// - /// 计算提供数据的 CRC-64 哈希值到提供的目标中。 - /// - /// 要哈希的数据。 - /// 接收计算哈希值的缓冲区。 - /// - /// 写入 的字节数。 - /// - [UnityEngine.Scripting.Preserve] - public static int Hash(ReadOnlySpan source, Span destination) - { - if (destination.Length < Size) - { - ThrowDestinationTooShort(); - } - - ulong hash = HashToUInt64(source); - BinaryPrimitives.WriteUInt64BigEndian(destination, hash); - return Size; - } - - /// 计算提供数据的 CRC-64 哈希值。 - /// 要哈希的数据。 - /// 计算的 CRC-64 哈希值。 - [UnityEngine.Scripting.Preserve] - public static ulong HashToUInt64(ReadOnlySpan source) => - Update(InitialState, source); - - private static ulong Update(ulong crc, ReadOnlySpan source) - { - ReadOnlySpan crcLookup = CrcLookup; - for (int i = 0; i < source.Length; i++) - { - ulong idx = (crc >> 56); - idx ^= source[i]; - crc = crcLookup[(int)idx] ^ (crc << 8); - } - - return crc; - } - - /// CRC-64 过渡表。 - private static ReadOnlySpan CrcLookup => new ulong[256] - { - // Generated by GenerateTable(0x42F0E1EBA9EA3693): - // - // static ulong[] GenerateTable(ulong polynomial) - // { - // var table = new ulong[256]; - // for (int i = 0; i < table.Length; i++) - // { - // ulong val = (ulong)i << 56; - // for (int j = 0; j < 8; j++) - // { - // if ((val & 0x8000_0000_0000_0000) == 0) - // { - // val <<= 1; - // } - // else - // { - // val = (val << 1) ^ polynomial; - // } - // } - // table[i] = val; - // } - // return table; - // } - - 0x0, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF, 0xBC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, - 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4, - 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, - 0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, - 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0xB6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0xA8546D7C558A27, 0x4258B586D5BFBCB4, - 0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, - 0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B, - 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, - 0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645, - 0x4863CE9FF6E9F891, 0xA932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, 0x150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB, - 0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, - 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14, - 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, - 0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x1F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0xA3B7B1923564425, - 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874, - 0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, - 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7, - 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, - 0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648, - 0x2A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, 0x4B9237F0FF14C443, 0x962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6, - 0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, - 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7, - 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, - 0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x9CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x20905D88D03A2BB, 0x40F9E43324E99428, - 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288, - 0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, - 0x4AC29F2A07BFD00D, 0x8327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x3F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767, - 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, - 0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, - 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8, - 0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x89A2AACD2006CB9, - 0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507, - }; - } - - /// - /// 表示一种非加密哈希算法。 - /// - [UnityEngine.Scripting.Preserve] - public abstract class NonCryptographicHashAlgorithm - { - /// - /// 获取此哈希算法生成的字节数。 - /// - /// 此哈希算法生成的字节数。 - [UnityEngine.Scripting.Preserve] - public int HashLengthInBytes { get; } - - /// - /// 从派生类的构造函数调用以初始化 - /// 类。 - /// - /// - /// 此哈希算法生成的字节数。 - /// - /// - /// 小于 1。 - /// - [UnityEngine.Scripting.Preserve] - protected NonCryptographicHashAlgorithm(int hashLengthInBytes) - { - if (hashLengthInBytes < 1) - throw new ArgumentOutOfRangeException(nameof(hashLengthInBytes)); - - HashLengthInBytes = hashLengthInBytes; - } - - /// - /// 当在派生类中重写时, - /// 将 的内容附加到当前哈希计算中已处理的数据。 - /// - /// 要处理的数据。 - [UnityEngine.Scripting.Preserve] - public abstract void Append(ReadOnlySpan source); - - /// - /// 当在派生类中重写时, - /// 将哈希计算重置为初始状态。 - /// - [UnityEngine.Scripting.Preserve] - public abstract void Reset(); - - /// - /// 当在派生类中重写时, - /// 将计算出的哈希值写入 - /// 而不修改累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// - /// 此方法的实现必须写入 - /// 字节到 。 - /// 不要假设缓冲区已被零初始化。 - /// - /// - /// 类在调用此方法之前验证 - /// 缓冲区的大小,并将切片的跨度 - /// 降至正好 的长度。 - /// - /// - [UnityEngine.Scripting.Preserve] - protected abstract void GetCurrentHashCore(Span destination); - - /// - /// 将 的内容附加到当前哈希计算中已处理的数据。 - /// - /// 要处理的数据。 - /// - /// 。 - /// - [UnityEngine.Scripting.Preserve] - public void Append(byte[] source) - { - if (source is null) - { - throw new ArgumentNullException(nameof(source)); - } - - Append(new ReadOnlySpan(source)); - } - - /// - /// 将 的内容附加到当前哈希计算中已处理的数据。 - /// - /// 要处理的数据。 - /// - /// 。 - /// - /// - [UnityEngine.Scripting.Preserve] - public void Append(Stream stream) - { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - - byte[] buffer = ArrayPool.Shared.Rent(4096); - - while (true) - { - int read = stream.Read(buffer, 0, buffer.Length); - - if (read == 0) - { - break; - } - - Append(new ReadOnlySpan(buffer, 0, read)); - } - - ArrayPool.Shared.Return(buffer); - } - - /*/// - /// 异步读取 的内容 - /// 并将其附加到当前哈希计算中已处理的数据。 - /// - /// 要处理的数据。 - /// - /// 用于监视取消请求的令牌。 - /// 默认值为 。 - /// - /// - /// 表示异步附加操作的任务。 - /// - /// - /// 。 - /// - [UnityEngine.Scripting.Preserve] - public Task AppendAsync(Stream stream, CancellationToken cancellationToken = default) - { - if (stream is null) - { - throw new ArgumentNullException(nameof(stream)); - } - - return AppendAsyncCore(stream, cancellationToken); - } - - private async Task AppendAsyncCore(Stream stream, CancellationToken cancellationToken) - { - byte[] buffer = ArrayPool.Shared.Rent(4096); - - while (true) - { -#if NETCOREAPP - int read = await stream.ReadAsync(buffer.AsMemory(), cancellationToken).ConfigureAwait(false); -#else - int read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); -#endif - - if (read == 0) - { - break; - } - - Append(new ReadOnlySpan(buffer, 0, read)); - } - - ArrayPool.Shared.Return(buffer); - }*/ - - /// - /// 获取当前计算的哈希值而不修改累积状态。 - /// - /// - /// 已提供数据的哈希值。 - /// - [UnityEngine.Scripting.Preserve] - public byte[] GetCurrentHash() - { - byte[] ret = new byte[HashLengthInBytes]; - GetCurrentHashCore(ret); - return ret; - } - - /// - /// 尝试将计算出的哈希值写入 - /// 而不修改累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// 成功时,接收写入 的字节数。 - /// - /// - /// 如果 足够长以接收 - /// 计算的哈希值;否则 。 - /// - [UnityEngine.Scripting.Preserve] - public bool TryGetCurrentHash(Span destination, out int bytesWritten) - { - if (destination.Length < HashLengthInBytes) - { - bytesWritten = 0; - return false; - } - - GetCurrentHashCore(destination.Slice(0, HashLengthInBytes)); - bytesWritten = HashLengthInBytes; - return true; - } - - /// - /// 将计算出的哈希值写入 - /// 而不修改累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// 写入 的字节数, - /// 始终为 。 - /// - /// - /// 短于 。 - /// - [UnityEngine.Scripting.Preserve] - public int GetCurrentHash(Span destination) - { - if (destination.Length < HashLengthInBytes) - { - ThrowDestinationTooShort(); - } - - GetCurrentHashCore(destination.Slice(0, HashLengthInBytes)); - return HashLengthInBytes; - } - - /// - /// 获取当前计算的哈希值并清除累积状态。 - /// - /// - /// 已提供数据的哈希值。 - /// - [UnityEngine.Scripting.Preserve] - public byte[] GetHashAndReset() - { - byte[] ret = new byte[HashLengthInBytes]; - GetHashAndResetCore(ret); - return ret; - } - - /// - /// 尝试将计算出的哈希值写入 。 - /// 如果成功,清除累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// 成功时,接收写入 的字节数。 - /// - /// - /// 并清除累积状态 - /// 如果 足够长以接收 - /// 计算的哈希值;否则 。 - /// - [UnityEngine.Scripting.Preserve] - public bool TryGetHashAndReset(Span destination, out int bytesWritten) - { - if (destination.Length < HashLengthInBytes) - { - bytesWritten = 0; - return false; - } - - GetHashAndResetCore(destination.Slice(0, HashLengthInBytes)); - bytesWritten = HashLengthInBytes; - return true; - } - - /// - /// 将计算出的哈希值写入 - /// 然后清除累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// 写入 的字节数, - /// 始终为 。 - /// - /// - /// 短于 。 - /// - [UnityEngine.Scripting.Preserve] - public int GetHashAndReset(Span destination) - { - if (destination.Length < HashLengthInBytes) - { - ThrowDestinationTooShort(); - } - - GetHashAndResetCore(destination.Slice(0, HashLengthInBytes)); - return HashLengthInBytes; - } - - /// - /// 将计算出的哈希值写入 - /// 然后清除累积状态。 - /// - /// 接收计算哈希值的缓冲区。 - /// - /// - /// 此方法的实现必须写入 - /// 字节到 。 - /// 不要假设缓冲区已被零初始化。 - /// - /// - /// 类在调用此方法之前验证 - /// 缓冲区的大小,并将切片的跨度 - /// 降至正好 的长度。 - /// - /// - /// 此方法的默认实现调用 - /// 然后 。 - /// 此方法的重写不需要调用这两个方法, - /// 但必须确保调用者无法观察到行为的差异。 - /// - /// - [UnityEngine.Scripting.Preserve] - protected virtual void GetHashAndResetCore(Span destination) - { - Debug.Assert(destination.Length == HashLengthInBytes); - - GetCurrentHashCore(destination); - Reset(); - } - - /// - /// 此方法不受支持且不应被调用。 - /// 请改用 - /// 。 - /// - /// 此方法将始终引发 - /// 在所有情况下。 - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Use GetCurrentHash() to retrieve the computed hash code.", true)] - [UnityEngine.Scripting.Preserve] -#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member - public override int GetHashCode() -#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member - { - throw new NotSupportedException(); - } - - - private protected static void ThrowDestinationTooShort() => - throw new ArgumentException("destination"); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Verifier.cs b/Runtime/Utility/Utility.Verifier.cs deleted file mode 100644 index b1008ef..0000000 --- a/Runtime/Utility/Utility.Verifier.cs +++ /dev/null @@ -1,281 +0,0 @@ -// ========================================================================================== -// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 -// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights -// 均受中华人民共和国及相关国际法律法规保护。 -// are protected by the laws of the People's Republic of China and relevant international regulations. -// -// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 -// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. -// -// 本项目采用 Apache License 2.0 许可证分发, -// This project is licensed under the Apache License 2.0, -// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 -// please refer to the LICENSE file in the root directory of the source code for the full license text. -// -// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 -// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, -// 侵犯他人合法权益等法律法规所禁止的行为! -// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! -// 因基于本项目二次开发所产生的一切法律纠纷与责任, -// Any legal disputes and liabilities arising from secondary development based on this project -// 本项目组织与贡献者概不承担。 -// shall be borne solely by the developer; the project organization and contributors assume no responsibility. -// -// GitHub 仓库:https://github.com/GameFrameX -// GitHub Repository: https://github.com/GameFrameX -// Gitee 仓库:https://gitee.com/GameFrameX -// Gitee Repository: https://gitee.com/GameFrameX -// CNB 仓库:https://cnb.cool/GameFrameX -// CNB Repository: https://cnb.cool/GameFrameX -// 官方文档:https://gameframex.doc.alianblank.com/ -// Official Documentation: https://gameframex.doc.alianblank.com/ -// ========================================================================================== - -using System; -using System.IO; -using UnityEngine.Scripting; - -namespace GameFrameX.Runtime -{ - public static partial class Utility - { - /// - /// 校验相关的实用函数。 - /// - /// - /// Verification related utility functions. - /// - [Preserve] - public static partial class Verifier - { - private const int CachedBytesLength = 0x1000; - private static readonly byte[] SCachedBytes = new byte[CachedBytesLength]; - - /// - /// 计算二进制流的 CRC64。 - /// - /// - /// Computes the CRC64 of the byte array. - /// - /// 要计算的二进制流 / The byte array to compute - /// 计算后的 CRC64 / The computed CRC64 - [Preserve] - public static ulong GetCrc64(byte[] bytes) - { - var algorithm = new Crc64(); - algorithm.Append(bytes); - return algorithm.GetCurrentHashAsUInt64(); - } - - /// - /// 计算流的 CRC64。 - /// - /// - /// Computes the CRC64 of the stream. - /// - /// 要计算的流 / The stream to compute - /// 计算后的 CRC64 / The computed CRC64 - [Preserve] - public static ulong GetCrc64(Stream stream) - { - var algorithm = new Crc64(); - algorithm.Append(stream); - return algorithm.GetCurrentHashAsUInt64(); - } - - /// - /// 计算二进制流的 CRC32。 - /// - /// - /// Computes the CRC32 of the byte array. - /// - /// 指定的二进制流 / The specified byte array - /// 计算后的 CRC32 / The computed CRC32 - [Preserve] - public static int GetCrc32(byte[] bytes) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - return GetCrc32(bytes, 0, bytes.Length); - } - - /// - /// 计算二进制流的 CRC32。 - /// - /// - /// Computes the CRC32 of the byte array with offset and length. - /// - /// 指定的二进制流 / The specified byte array - /// 二进制流的偏移 / The offset of the byte array - /// 二进制流的长度 / The length of the byte array - /// 计算后的 CRC32 / The computed CRC32 - [Preserve] - public static int GetCrc32(byte[] bytes, int offset, int length) - { - if (bytes == null) - { - throw new GameFrameworkException("Bytes is invalid."); - } - - if (offset < 0 || length < 0 || offset + length > bytes.Length) - { - throw new GameFrameworkException("Offset or length is invalid."); - } - - var algorithm = new Crc32(); - algorithm.HashCore(bytes, offset, length); - int result = (int)algorithm.HashFinal(); - return result; - } - - /// - /// 计算二进制流的 CRC32。 - /// - /// - /// Computes the CRC32 of the stream. - /// - /// 指定的二进制流 / The specified stream - /// 计算后的 CRC32 / The computed CRC32 - [Preserve] - public static int GetCrc32(Stream stream) - { - if (stream == null) - { - throw new GameFrameworkException("Stream is invalid."); - } - - var algorithm = new Crc32(); - while (true) - { - int bytesRead = stream.Read(SCachedBytes, 0, CachedBytesLength); - if (bytesRead > 0) - { - algorithm.HashCore(SCachedBytes, 0, bytesRead); - } - else - { - break; - } - } - - int result = (int)algorithm.HashFinal(); - Array.Clear(SCachedBytes, 0, CachedBytesLength); - return result; - } - - /// - /// 获取 CRC32 数值的二进制数组。 - /// - /// - /// Gets the binary array of the CRC32 value. - /// - /// CRC32 数值 / The CRC32 value - /// CRC32 数值的二进制数组 / The binary array of the CRC32 value - [Preserve] - public static byte[] GetCrc32Bytes(int crc32) - { - return new byte[] { (byte)((crc32 >> 24) & 0xff), (byte)((crc32 >> 16) & 0xff), (byte)((crc32 >> 8) & 0xff), (byte)(crc32 & 0xff) }; - } - - /// - /// 获取 CRC32 数值的二进制数组。 - /// - /// - /// Gets the binary array of the CRC32 value. - /// - /// CRC32 数值 / The CRC32 value - /// 要存放结果的数组 / The array to store the result - [Preserve] - public static void GetCrc32Bytes(int crc32, byte[] bytes) - { - GetCrc32Bytes(crc32, bytes, 0); - } - - /// - /// 获取 CRC32 数值的二进制数组。 - /// - /// - /// Gets the binary array of the CRC32 value. - /// - /// CRC32 数值 / The CRC32 value - /// 要存放结果的数组 / The array to store the result - /// CRC32 数值的二进制数组在结果数组内的起始位置 / The starting position in the result array - [Preserve] - public static void GetCrc32Bytes(int crc32, byte[] bytes, int offset) - { - if (bytes == null) - { - throw new GameFrameworkException("Result is invalid."); - } - - if (offset < 0 || offset + 4 > bytes.Length) - { - throw new GameFrameworkException("Offset or length is invalid."); - } - - bytes[offset] = (byte)((crc32 >> 24) & 0xff); - bytes[offset + 1] = (byte)((crc32 >> 16) & 0xff); - bytes[offset + 2] = (byte)((crc32 >> 8) & 0xff); - bytes[offset + 3] = (byte)(crc32 & 0xff); - } - - internal static int GetCrc32(Stream stream, byte[] code, int length) - { - if (stream == null) - { - throw new GameFrameworkException("Stream is invalid."); - } - - if (code == null) - { - throw new GameFrameworkException("Code is invalid."); - } - - int codeLength = code.Length; - if (codeLength <= 0) - { - throw new GameFrameworkException("Code length is invalid."); - } - - int bytesLength = (int)stream.Length; - if (length < 0 || length > bytesLength) - { - length = bytesLength; - } - - var algorithm = new Crc32(); - int codeIndex = 0; - while (true) - { - int bytesRead = stream.Read(SCachedBytes, 0, CachedBytesLength); - if (bytesRead > 0) - { - if (length > 0) - { - for (int i = 0; i < bytesRead && i < length; i++) - { - SCachedBytes[i] ^= code[codeIndex++]; - codeIndex %= codeLength; - } - - length -= bytesRead; - } - - algorithm.HashCore(SCachedBytes, 0, bytesRead); - } - else - { - break; - } - } - - int result = (int)algorithm.HashFinal(); - Array.Clear(SCachedBytes, 0, CachedBytesLength); - return result; - } - } - } -} \ No newline at end of file diff --git a/Runtime/Utility/Utility.cs.meta b/Runtime/Utility/Utility.cs.meta deleted file mode 100644 index 4dd09e1..0000000 --- a/Runtime/Utility/Utility.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4e420e7a1d92ff743800575c5db5d0f2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Utility/VerifierUtility.Crc32.cs b/Runtime/Utility/VerifierUtility.Crc32.cs new file mode 100644 index 0000000..fe7f085 --- /dev/null +++ b/Runtime/Utility/VerifierUtility.Crc32.cs @@ -0,0 +1,162 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +namespace GameFrameX.Runtime +{ + public static partial class VerifierUtility + { + /// + /// CRC32 算法。 + /// + /// + /// CRC32 algorithm implementation. + /// + [UnityEngine.Scripting.Preserve] + private sealed class Crc32 + { + private const int TableLength = 256; + private const uint DefaultPolynomial = 0xedb88320; + private const uint DefaultSeed = 0xffffffff; + + private readonly uint m_Seed; + private readonly uint[] m_Table; + private uint m_Hash; + + /// + /// 初始化 CRC32 类的新实例。 + /// + /// + /// Initializes a new instance of the CRC32 class. + /// + [UnityEngine.Scripting.Preserve] + public Crc32() + : this(DefaultPolynomial, DefaultSeed) + { + } + + /// + /// 使用指定的多项式和种子初始化 CRC32 类的新实例。 + /// + /// + /// Initializes a new instance of the CRC32 class with the specified polynomial and seed. + /// + /// 用于计算 CRC 的多项式 / The polynomial for CRC calculation + /// 用于初始化哈希值的种子 / The seed for initializing the hash value + [UnityEngine.Scripting.Preserve] + public Crc32(uint polynomial, uint seed) + { + m_Seed = seed; + m_Table = InitializeTable(polynomial); + m_Hash = seed; + } + + /// + /// 初始化 CRC32 计算。 + /// + /// + /// Initializes the CRC32 calculation. + /// + [UnityEngine.Scripting.Preserve] + public void Initialize() + { + m_Hash = m_Seed; + } + + /// + /// 计算给定字节数组的哈希值。 + /// + /// + /// Computes the hash value of the given byte array. + /// + /// 要计算哈希的字节数组 / The byte array to hash + /// 字节数组的起始偏移量 / The starting offset in the byte array + /// 要计算的字节数 / The number of bytes to compute + [UnityEngine.Scripting.Preserve] + public void HashCore(byte[] bytes, int offset, int length) + { + m_Hash = CalculateHash(m_Table, m_Hash, bytes, offset, length); + } + + /// + /// 返回计算的 CRC32 哈希值。 + /// + /// + /// Returns the computed CRC32 hash value. + /// + /// 计算的 CRC32 哈希值 / The computed CRC32 hash value + [UnityEngine.Scripting.Preserve] + public uint HashFinal() + { + return ~m_Hash; + } + + private static uint CalculateHash(uint[] table, uint value, byte[] bytes, int offset, int length) + { + int last = offset + length; + for (int i = offset; i < last; i++) + { + unchecked + { + value = (value >> 8) ^ table[bytes[i] ^ value & 0xff]; + } + } + + return value; + } + + private static uint[] InitializeTable(uint polynomial) + { + uint[] table = new uint[TableLength]; + for (int i = 0; i < TableLength; i++) + { + uint entry = (uint)i; + for (int j = 0; j < 8; j++) + { + if ((entry & 1) == 1) + { + entry = (entry >> 1) ^ polynomial; + } + else + { + entry >>= 1; + } + } + + table[i] = entry; + } + + return table; + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Verifier.Crc32.cs.meta b/Runtime/Utility/VerifierUtility.Crc32.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Verifier.Crc32.cs.meta rename to Runtime/Utility/VerifierUtility.Crc32.cs.meta diff --git a/Runtime/Utility/VerifierUtility.Crc64.cs b/Runtime/Utility/VerifierUtility.Crc64.cs new file mode 100644 index 0000000..3154039 --- /dev/null +++ b/Runtime/Utility/VerifierUtility.Crc64.cs @@ -0,0 +1,643 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.ComponentModel; +using System.IO; +using System.Threading; +using UnityEngine; + +namespace GameFrameX.Runtime +{ + public static partial class VerifierUtility + { + /// + /// 提供了根据 ECMA-182 附录 B 描述的 CRC-64 算法的实现。 + /// + /// + /// + /// 对于返回字节数组或写入字节跨度的方法, + /// 此实现以大端字节顺序发出答案,以便 + /// CRC 残差关系(CRC(消息连接 CRC(消息)))是固定值。 + /// 对于 CRC-64,此稳定输出是字节序列 + /// { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }。 + /// + /// + /// 有多个不兼容的 64 位循环冗余 + /// 检查(CRC)算法的定义。在与另一个系统互操作时,请确保您 + /// 使用相同的定义。此实现使用的定义与 + /// ISO 3309 中描述的循环冗余检查不兼容。 + /// + /// + [UnityEngine.Scripting.Preserve] + public sealed partial class Crc64 : NonCryptographicHashAlgorithm + { + private const ulong InitialState = 0UL; + private const int Size = sizeof(ulong); + + private ulong _crc = InitialState; + + /// + /// 初始化 类的新实例。 + /// + [UnityEngine.Scripting.Preserve] + public Crc64() + : base(Size) + { + } + + /// + /// 将 的内容附加到当前哈希计算中已处理的数据。 + /// + /// 要处理的数据。 + [UnityEngine.Scripting.Preserve] + public override void Append(ReadOnlySpan source) + { + _crc = Update(_crc, source); + } + + /// + /// 将哈希计算重置为初始状态。 + /// + [UnityEngine.Scripting.Preserve] + public override void Reset() + { + _crc = InitialState; + } + + /// + /// 将计算出的哈希值写入 + /// 而不修改累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + [UnityEngine.Scripting.Preserve] + protected override void GetCurrentHashCore(Span destination) + { + BinaryPrimitives.WriteUInt64BigEndian(destination, _crc); + } + + /// + /// 将计算出的哈希值写入 + /// 然后清除累积状态。 + /// + [UnityEngine.Scripting.Preserve] + protected override void GetHashAndResetCore(Span destination) + { + BinaryPrimitives.WriteUInt64BigEndian(destination, _crc); + _crc = InitialState; + } + + /// + /// 获取当前计算的哈希值而不修改累积状态。 + /// + /// 已提供数据的哈希值。 + [UnityEngine.Scripting.Preserve] + public ulong GetCurrentHashAsUInt64() => _crc; + + /// + /// 计算提供数据的 CRC-64 哈希值。 + /// + /// 要哈希的数据。 + /// 提供数据的 CRC-64 哈希值。 + /// + /// 。 + /// + [UnityEngine.Scripting.Preserve] + public static byte[] Hash(byte[] source) + { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + return Hash(new ReadOnlySpan(source)); + } + + /// + /// 计算提供数据的 CRC-64 哈希值。 + /// + /// 要哈希的数据。 + /// 提供数据的 CRC-64 哈希值。 + [UnityEngine.Scripting.Preserve] + public static byte[] Hash(ReadOnlySpan source) + { + byte[] ret = new byte[Size]; + ulong hash = HashToUInt64(source); + BinaryPrimitives.WriteUInt64BigEndian(ret, hash); + return ret; + } + + /// + /// 尝试将提供数据的 CRC-64 哈希值计算到提供的目标中。 + /// + /// 要哈希的数据。 + /// 接收计算哈希值的缓冲区。 + /// + /// 成功时,接收写入 的字节数。 + /// + /// + /// 如果 足够长以接收 + /// 计算的哈希值(8 字节);否则 。 + /// + [UnityEngine.Scripting.Preserve] + public static bool TryHash(ReadOnlySpan source, Span destination, out int bytesWritten) + { + if (destination.Length < Size) + { + bytesWritten = 0; + return false; + } + + ulong hash = HashToUInt64(source); + BinaryPrimitives.WriteUInt64BigEndian(destination, hash); + bytesWritten = Size; + return true; + } + + /// + /// 计算提供数据的 CRC-64 哈希值到提供的目标中。 + /// + /// 要哈希的数据。 + /// 接收计算哈希值的缓冲区。 + /// + /// 写入 的字节数。 + /// + [UnityEngine.Scripting.Preserve] + public static int Hash(ReadOnlySpan source, Span destination) + { + if (destination.Length < Size) + { + ThrowDestinationTooShort(); + } + + ulong hash = HashToUInt64(source); + BinaryPrimitives.WriteUInt64BigEndian(destination, hash); + return Size; + } + + /// 计算提供数据的 CRC-64 哈希值。 + /// 要哈希的数据。 + /// 计算的 CRC-64 哈希值。 + [UnityEngine.Scripting.Preserve] + public static ulong HashToUInt64(ReadOnlySpan source) => + Update(InitialState, source); + + private static ulong Update(ulong crc, ReadOnlySpan source) + { + ReadOnlySpan crcLookup = CrcLookup; + for (int i = 0; i < source.Length; i++) + { + ulong idx = (crc >> 56); + idx ^= source[i]; + crc = crcLookup[(int)idx] ^ (crc << 8); + } + + return crc; + } + + /// CRC-64 过渡表。 + private static ReadOnlySpan CrcLookup => new ulong[256] + { + // Generated by GenerateTable(0x42F0E1EBA9EA3693): + // + // static ulong[] GenerateTable(ulong polynomial) + // { + // var table = new ulong[256]; + // for (int i = 0; i < table.Length; i++) + // { + // ulong val = (ulong)i << 56; + // for (int j = 0; j < 8; j++) + // { + // if ((val & 0x8000_0000_0000_0000) == 0) + // { + // val <<= 1; + // } + // else + // { + // val = (val << 1) ^ polynomial; + // } + // } + // table[i] = val; + // } + // return table; + // } + + 0x0, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF, 0xBC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, + 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4, + 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, + 0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, + 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0xB6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0xA8546D7C558A27, 0x4258B586D5BFBCB4, + 0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, + 0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B, + 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, + 0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645, + 0x4863CE9FF6E9F891, 0xA932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, 0x150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB, + 0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, + 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14, + 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, + 0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x1F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0xA3B7B1923564425, + 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874, + 0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, + 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7, + 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, + 0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648, + 0x2A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, 0x4B9237F0FF14C443, 0x962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6, + 0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879, + 0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7, + 0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96, + 0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x9CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x20905D88D03A2BB, 0x40F9E43324E99428, + 0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288, + 0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36, + 0x4AC29F2A07BFD00D, 0x8327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x3F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767, + 0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9, + 0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956, + 0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8, + 0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x89A2AACD2006CB9, + 0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507, + }; + } + + /// + /// 表示一种非加密哈希算法。 + /// + [UnityEngine.Scripting.Preserve] + public abstract class NonCryptographicHashAlgorithm + { + /// + /// 获取此哈希算法生成的字节数。 + /// + /// 此哈希算法生成的字节数。 + [UnityEngine.Scripting.Preserve] + public int HashLengthInBytes { get; } + + /// + /// 从派生类的构造函数调用以初始化 + /// 类。 + /// + /// + /// 此哈希算法生成的字节数。 + /// + /// + /// 小于 1。 + /// + [UnityEngine.Scripting.Preserve] + protected NonCryptographicHashAlgorithm(int hashLengthInBytes) + { + if (hashLengthInBytes < 1) + throw new ArgumentOutOfRangeException(nameof(hashLengthInBytes)); + + HashLengthInBytes = hashLengthInBytes; + } + + /// + /// 当在派生类中重写时, + /// 将 的内容附加到当前哈希计算中已处理的数据。 + /// + /// 要处理的数据。 + [UnityEngine.Scripting.Preserve] + public abstract void Append(ReadOnlySpan source); + + /// + /// 当在派生类中重写时, + /// 将哈希计算重置为初始状态。 + /// + [UnityEngine.Scripting.Preserve] + public abstract void Reset(); + + /// + /// 当在派生类中重写时, + /// 将计算出的哈希值写入 + /// 而不修改累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// + /// 此方法的实现必须写入 + /// 字节到 。 + /// 不要假设缓冲区已被零初始化。 + /// + /// + /// 类在调用此方法之前验证 + /// 缓冲区的大小,并将切片的跨度 + /// 降至正好 的长度。 + /// + /// + [UnityEngine.Scripting.Preserve] + protected abstract void GetCurrentHashCore(Span destination); + + /// + /// 将 的内容附加到当前哈希计算中已处理的数据。 + /// + /// 要处理的数据。 + /// + /// 。 + /// + [UnityEngine.Scripting.Preserve] + public void Append(byte[] source) + { + if (source is null) + { + throw new ArgumentNullException(nameof(source)); + } + + Append(new ReadOnlySpan(source)); + } + + /// + /// 将 的内容附加到当前哈希计算中已处理的数据。 + /// + /// 要处理的数据。 + /// + /// 。 + /// + /// + [UnityEngine.Scripting.Preserve] + public void Append(Stream stream) + { + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } + + byte[] buffer = ArrayPool.Shared.Rent(4096); + + while (true) + { + int read = stream.Read(buffer, 0, buffer.Length); + + if (read == 0) + { + break; + } + + Append(new ReadOnlySpan(buffer, 0, read)); + } + + ArrayPool.Shared.Return(buffer); + } + + /*/// + /// 异步读取 的内容 + /// 并将其附加到当前哈希计算中已处理的数据。 + /// + /// 要处理的数据。 + /// + /// 用于监视取消请求的令牌。 + /// 默认值为 。 + /// + /// + /// 表示异步附加操作的任务。 + /// + /// + /// 。 + /// + [UnityEngine.Scripting.Preserve] + public Task AppendAsync(Stream stream, CancellationToken cancellationToken = default) + { + if (stream is null) + { + throw new ArgumentNullException(nameof(stream)); + } + + return AppendAsyncCore(stream, cancellationToken); + } + + private async Task AppendAsyncCore(Stream stream, CancellationToken cancellationToken) + { + byte[] buffer = ArrayPool.Shared.Rent(4096); + + while (true) + { +#if NETCOREAPP + int read = await stream.ReadAsync(buffer.AsMemory(), cancellationToken).ConfigureAwait(false); +#else + int read = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); +#endif + + if (read == 0) + { + break; + } + + Append(new ReadOnlySpan(buffer, 0, read)); + } + + ArrayPool.Shared.Return(buffer); + }*/ + + /// + /// 获取当前计算的哈希值而不修改累积状态。 + /// + /// + /// 已提供数据的哈希值。 + /// + [UnityEngine.Scripting.Preserve] + public byte[] GetCurrentHash() + { + byte[] ret = new byte[HashLengthInBytes]; + GetCurrentHashCore(ret); + return ret; + } + + /// + /// 尝试将计算出的哈希值写入 + /// 而不修改累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// 成功时,接收写入 的字节数。 + /// + /// + /// 如果 足够长以接收 + /// 计算的哈希值;否则 。 + /// + [UnityEngine.Scripting.Preserve] + public bool TryGetCurrentHash(Span destination, out int bytesWritten) + { + if (destination.Length < HashLengthInBytes) + { + bytesWritten = 0; + return false; + } + + GetCurrentHashCore(destination.Slice(0, HashLengthInBytes)); + bytesWritten = HashLengthInBytes; + return true; + } + + /// + /// 将计算出的哈希值写入 + /// 而不修改累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// 写入 的字节数, + /// 始终为 。 + /// + /// + /// 短于 。 + /// + [UnityEngine.Scripting.Preserve] + public int GetCurrentHash(Span destination) + { + if (destination.Length < HashLengthInBytes) + { + ThrowDestinationTooShort(); + } + + GetCurrentHashCore(destination.Slice(0, HashLengthInBytes)); + return HashLengthInBytes; + } + + /// + /// 获取当前计算的哈希值并清除累积状态。 + /// + /// + /// 已提供数据的哈希值。 + /// + [UnityEngine.Scripting.Preserve] + public byte[] GetHashAndReset() + { + byte[] ret = new byte[HashLengthInBytes]; + GetHashAndResetCore(ret); + return ret; + } + + /// + /// 尝试将计算出的哈希值写入 。 + /// 如果成功,清除累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// 成功时,接收写入 的字节数。 + /// + /// + /// 并清除累积状态 + /// 如果 足够长以接收 + /// 计算的哈希值;否则 。 + /// + [UnityEngine.Scripting.Preserve] + public bool TryGetHashAndReset(Span destination, out int bytesWritten) + { + if (destination.Length < HashLengthInBytes) + { + bytesWritten = 0; + return false; + } + + GetHashAndResetCore(destination.Slice(0, HashLengthInBytes)); + bytesWritten = HashLengthInBytes; + return true; + } + + /// + /// 将计算出的哈希值写入 + /// 然后清除累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// 写入 的字节数, + /// 始终为 。 + /// + /// + /// 短于 。 + /// + [UnityEngine.Scripting.Preserve] + public int GetHashAndReset(Span destination) + { + if (destination.Length < HashLengthInBytes) + { + ThrowDestinationTooShort(); + } + + GetHashAndResetCore(destination.Slice(0, HashLengthInBytes)); + return HashLengthInBytes; + } + + /// + /// 将计算出的哈希值写入 + /// 然后清除累积状态。 + /// + /// 接收计算哈希值的缓冲区。 + /// + /// + /// 此方法的实现必须写入 + /// 字节到 。 + /// 不要假设缓冲区已被零初始化。 + /// + /// + /// 类在调用此方法之前验证 + /// 缓冲区的大小,并将切片的跨度 + /// 降至正好 的长度。 + /// + /// + /// 此方法的默认实现调用 + /// 然后 。 + /// 此方法的重写不需要调用这两个方法, + /// 但必须确保调用者无法观察到行为的差异。 + /// + /// + [UnityEngine.Scripting.Preserve] + protected virtual void GetHashAndResetCore(Span destination) + { + Debug.Assert(destination.Length == HashLengthInBytes); + + GetCurrentHashCore(destination); + Reset(); + } + + /// + /// 此方法不受支持且不应被调用。 + /// 请改用 + /// 。 + /// + /// 此方法将始终引发 + /// 在所有情况下。 + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use GetCurrentHash() to retrieve the computed hash code.", true)] + [UnityEngine.Scripting.Preserve] +#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member + public override int GetHashCode() +#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member + { + throw new NotSupportedException(); + } + + + private protected static void ThrowDestinationTooShort() => + throw new ArgumentException("destination"); + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Verifier.Crc64.cs.meta b/Runtime/Utility/VerifierUtility.Crc64.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Verifier.Crc64.cs.meta rename to Runtime/Utility/VerifierUtility.Crc64.cs.meta diff --git a/Runtime/Utility/VerifierUtility.cs b/Runtime/Utility/VerifierUtility.cs new file mode 100644 index 0000000..604dfb5 --- /dev/null +++ b/Runtime/Utility/VerifierUtility.cs @@ -0,0 +1,278 @@ +// ========================================================================================== +// GameFrameX 组织及其衍生项目的版权、商标、专利及其他相关权利 +// GameFrameX organization and its derivative projects' copyrights, trademarks, patents, and related rights +// 均受中华人民共和国及相关国际法律法规保护。 +// are protected by the laws of the People's Republic of China and relevant international regulations. +// +// 使用本项目须严格遵守相应法律法规及开源许可证之规定。 +// Usage of this project must strictly comply with applicable laws, regulations, and open-source licenses. +// +// 本项目采用 Apache License 2.0 许可证分发, +// This project is licensed under the Apache License 2.0, +// 完整许可证文本请参见源代码根目录下的 LICENSE 文件。 +// please refer to the LICENSE file in the root directory of the source code for the full license text. +// +// 禁止利用本项目实施任何危害国家安全、破坏社会秩序、 +// It is prohibited to use this project to engage in any activities that endanger national security, disrupt social order, +// 侵犯他人合法权益等法律法规所禁止的行为! +// or infringe upon the legitimate rights and interests of others, as prohibited by laws and regulations! +// 因基于本项目二次开发所产生的一切法律纠纷与责任, +// Any legal disputes and liabilities arising from secondary development based on this project +// 本项目组织与贡献者概不承担。 +// shall be borne solely by the developer; the project organization and contributors assume no responsibility. +// +// GitHub 仓库:https://github.com/GameFrameX +// GitHub Repository: https://github.com/GameFrameX +// Gitee 仓库:https://gitee.com/GameFrameX +// Gitee Repository: https://gitee.com/GameFrameX +// CNB 仓库:https://cnb.cool/GameFrameX +// CNB Repository: https://cnb.cool/GameFrameX +// 官方文档:https://gameframex.doc.alianblank.com/ +// Official Documentation: https://gameframex.doc.alianblank.com/ +// ========================================================================================== + +using System; +using System.IO; +using UnityEngine.Scripting; + +namespace GameFrameX.Runtime +{ + /// + /// 校验相关的实用函数。 + /// + /// + /// Verification related utility functions. + /// + [Preserve] + public static partial class VerifierUtility + { + private const int CachedBytesLength = 0x1000; + private static readonly byte[] SCachedBytes = new byte[CachedBytesLength]; + + /// + /// 计算二进制流的 CRC64。 + /// + /// + /// Computes the CRC64 of the byte array. + /// + /// 要计算的二进制流 / The byte array to compute + /// 计算后的 CRC64 / The computed CRC64 + [Preserve] + public static ulong GetCrc64(byte[] bytes) + { + var algorithm = new Crc64(); + algorithm.Append(bytes); + return algorithm.GetCurrentHashAsUInt64(); + } + + /// + /// 计算流的 CRC64。 + /// + /// + /// Computes the CRC64 of the stream. + /// + /// 要计算的流 / The stream to compute + /// 计算后的 CRC64 / The computed CRC64 + [Preserve] + public static ulong GetCrc64(Stream stream) + { + var algorithm = new Crc64(); + algorithm.Append(stream); + return algorithm.GetCurrentHashAsUInt64(); + } + + /// + /// 计算二进制流的 CRC32。 + /// + /// + /// Computes the CRC32 of the byte array. + /// + /// 指定的二进制流 / The specified byte array + /// 计算后的 CRC32 / The computed CRC32 + [Preserve] + public static int GetCrc32(byte[] bytes) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + return GetCrc32(bytes, 0, bytes.Length); + } + + /// + /// 计算二进制流的 CRC32。 + /// + /// + /// Computes the CRC32 of the byte array with offset and length. + /// + /// 指定的二进制流 / The specified byte array + /// 二进制流的偏移 / The offset of the byte array + /// 二进制流的长度 / The length of the byte array + /// 计算后的 CRC32 / The computed CRC32 + [Preserve] + public static int GetCrc32(byte[] bytes, int offset, int length) + { + if (bytes == null) + { + throw new GameFrameworkException("Bytes is invalid."); + } + + if (offset < 0 || length < 0 || offset + length > bytes.Length) + { + throw new GameFrameworkException("Offset or length is invalid."); + } + + var algorithm = new Crc32(); + algorithm.HashCore(bytes, offset, length); + int result = (int)algorithm.HashFinal(); + return result; + } + + /// + /// 计算二进制流的 CRC32。 + /// + /// + /// Computes the CRC32 of the stream. + /// + /// 指定的二进制流 / The specified stream + /// 计算后的 CRC32 / The computed CRC32 + [Preserve] + public static int GetCrc32(Stream stream) + { + if (stream == null) + { + throw new GameFrameworkException("Stream is invalid."); + } + + var algorithm = new Crc32(); + while (true) + { + int bytesRead = stream.Read(SCachedBytes, 0, CachedBytesLength); + if (bytesRead > 0) + { + algorithm.HashCore(SCachedBytes, 0, bytesRead); + } + else + { + break; + } + } + + int result = (int)algorithm.HashFinal(); + Array.Clear(SCachedBytes, 0, CachedBytesLength); + return result; + } + + /// + /// 获取 CRC32 数值的二进制数组。 + /// + /// + /// Gets the binary array of the CRC32 value. + /// + /// CRC32 数值 / The CRC32 value + /// CRC32 数值的二进制数组 / The binary array of the CRC32 value + [Preserve] + public static byte[] GetCrc32Bytes(int crc32) + { + return new byte[] { (byte)((crc32 >> 24) & 0xff), (byte)((crc32 >> 16) & 0xff), (byte)((crc32 >> 8) & 0xff), (byte)(crc32 & 0xff) }; + } + + /// + /// 获取 CRC32 数值的二进制数组。 + /// + /// + /// Gets the binary array of the CRC32 value. + /// + /// CRC32 数值 / The CRC32 value + /// 要存放结果的数组 / The array to store the result + [Preserve] + public static void GetCrc32Bytes(int crc32, byte[] bytes) + { + GetCrc32Bytes(crc32, bytes, 0); + } + + /// + /// 获取 CRC32 数值的二进制数组。 + /// + /// + /// Gets the binary array of the CRC32 value. + /// + /// CRC32 数值 / The CRC32 value + /// 要存放结果的数组 / The array to store the result + /// CRC32 数值的二进制数组在结果数组内的起始位置 / The starting position in the result array + [Preserve] + public static void GetCrc32Bytes(int crc32, byte[] bytes, int offset) + { + if (bytes == null) + { + throw new GameFrameworkException("Result is invalid."); + } + + if (offset < 0 || offset + 4 > bytes.Length) + { + throw new GameFrameworkException("Offset or length is invalid."); + } + + bytes[offset] = (byte)((crc32 >> 24) & 0xff); + bytes[offset + 1] = (byte)((crc32 >> 16) & 0xff); + bytes[offset + 2] = (byte)((crc32 >> 8) & 0xff); + bytes[offset + 3] = (byte)(crc32 & 0xff); + } + + internal static int GetCrc32(Stream stream, byte[] code, int length) + { + if (stream == null) + { + throw new GameFrameworkException("Stream is invalid."); + } + + if (code == null) + { + throw new GameFrameworkException("Code is invalid."); + } + + int codeLength = code.Length; + if (codeLength <= 0) + { + throw new GameFrameworkException("Code length is invalid."); + } + + int bytesLength = (int)stream.Length; + if (length < 0 || length > bytesLength) + { + length = bytesLength; + } + + var algorithm = new Crc32(); + int codeIndex = 0; + while (true) + { + int bytesRead = stream.Read(SCachedBytes, 0, CachedBytesLength); + if (bytesRead > 0) + { + if (length > 0) + { + for (int i = 0; i < bytesRead && i < length; i++) + { + SCachedBytes[i] ^= code[codeIndex++]; + codeIndex %= codeLength; + } + + length -= bytesRead; + } + + algorithm.HashCore(SCachedBytes, 0, bytesRead); + } + else + { + break; + } + } + + int result = (int)algorithm.HashFinal(); + Array.Clear(SCachedBytes, 0, CachedBytesLength); + return result; + } + } +} \ No newline at end of file diff --git a/Runtime/Utility/Utility.Verifier.cs.meta b/Runtime/Utility/VerifierUtility.cs.meta similarity index 100% rename from Runtime/Utility/Utility.Verifier.cs.meta rename to Runtime/Utility/VerifierUtility.cs.meta diff --git a/Runtime/Helper/ZipHelper.cs b/Runtime/Utility/ZipUtility.cs similarity index 97% rename from Runtime/Helper/ZipHelper.cs rename to Runtime/Utility/ZipUtility.cs index 636a1ad..97dd1e5 100644 --- a/Runtime/Helper/ZipHelper.cs +++ b/Runtime/Utility/ZipUtility.cs @@ -1,378 +1,377 @@ -using System; -using System.Buffers; -using System.IO; -using ICSharpCode.SharpZipLib.Checksum; -using ICSharpCode.SharpZipLib.Zip; -using ICSharpCode.SharpZipLib.Zip.Compression; - -namespace GameFrameX.Runtime -{ - /// - /// 压缩帮助类。 - /// - /// - /// Zip compression helper class. - /// - [UnityEngine.Scripting.Preserve] - public static class ZipHelper - { - - /// - /// 压缩文件夹到流。 - /// - /// - /// Compresses a folder to a stream. - /// - /// 要压缩的文件夹路径 / Folder path to compress - /// 压缩输出流 / Compressed output stream - /// 压缩密码(可选)/ Compression password (optional) - /// 如果成功返回 true;否则返回 false / true if successful; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool CompressDirectoryToStream(string folderToZip, Stream stream, string password = null) - { - return CompressDirectoryToZipStream(folderToZip, stream, password) != null; - } - - - /// - /// 压缩文件夹并返回ZipOutputStream。 - /// - /// - /// Compresses a folder to a stream and returns the ZipOutputStream. - /// - /// 要压缩的文件夹路径 / Folder path to compress - /// 压缩输出流 / Compressed output stream - /// 压缩密码(可选)/ Compression password (optional) - /// 如果成功返回ZipOutputStream;否则返回null / ZipOutputStream if successful; otherwise null - [UnityEngine.Scripting.Preserve] - public static ZipOutputStream CompressDirectoryToZipStream(string folderToZip, Stream stream, string password = null) - { - if (!Directory.Exists(folderToZip)) - { - return null; - } - - ZipOutputStream zipStream = new ZipOutputStream(stream); - zipStream.SetLevel(6); - if (!string.IsNullOrEmpty(password)) - { - zipStream.Password = password; - } - - if (CompressDirectory(folderToZip, zipStream, "")) - { - zipStream.Finish(); - return zipStream; - } - - GC.Collect(1); - return null; - } - - /// - /// 递归压缩文件夹的内部方法。 - /// - /// - /// Internal method for recursively compressing a folder. - /// - /// 要压缩的文件夹路径 / Folder path to compress - /// 压缩输出流 / Zip output stream - /// 此文件夹的上级文件夹名称 / Parent folder name - /// 如果成功返回 true;否则返回 false / true if successful; otherwise false - [UnityEngine.Scripting.Preserve] - private static bool CompressDirectory(string folderToZip, ZipOutputStream zipStream, string parentFolderName) - { - //这段是创建空文件夹,注释掉可以去掉空文件夹(因为在写入文件的时候也会创建文件夹) - if (parentFolderName.IsNotNullOrWhiteSpace()) - { - var ent = new ZipEntry(parentFolderName + "/"); - zipStream.PutNextEntry(ent); - zipStream.Flush(); - } - - var files = Directory.GetFiles(folderToZip); - foreach (string file in files) - { - byte[] buffer = File.ReadAllBytes(file); - var path = Path.GetFileName(file); - if (parentFolderName.IsNotNullOrWhiteSpace()) - { - path = parentFolderName + Path.DirectorySeparatorChar + Path.GetFileName(file); - } - - var ent = new ZipEntry(path) - { - //ent.DateTime = File.GetLastWriteTime(file);//设置文件最后修改时间 - DateTime = DateTime.Now, - Size = buffer.Length, - }; - - var crc = new Crc32(); - crc.Update(buffer); - - ent.Crc = crc.Value; - zipStream.PutNextEntry(ent); - zipStream.Write(buffer, 0, buffer.Length); - } - - var folders = Directory.GetDirectories(folderToZip); - foreach (var folder in folders) - { - var folderName = folder.Substring(folder.LastIndexOf('\\') + 1); - - if (parentFolderName.IsNotNullOrWhiteSpace()) - { - folderName = parentFolderName + "\\" + folder.Substring(folder.LastIndexOf('\\') + 1); - } - - if (!CompressDirectory(folder, zipStream, folderName)) - { - return false; - } - } - - return true; - } - - /// - /// 压缩文件夹到指定文件。 - /// - /// - /// Compresses a folder to a specified zip file. - /// - /// 要压缩的文件夹路径 / Folder path to compress - /// 压缩文件完整路径 / Full path of the zip file to create - /// 压缩密码(可选)/ Compression password (optional) - /// 如果成功返回 true;否则返回 false / true if successful; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool CompressDirectory(string folderToZip, string zipFile, string password = null) - { - if (folderToZip.EndsWithFast(Path.DirectorySeparatorChar.ToString()) || folderToZip.EndsWithFast("/")) - { - folderToZip = folderToZip.Substring(0, folderToZip.Length - 1); - } - - var zipStream = CompressDirectoryToZipStream(folderToZip, new FileStream(zipFile, FileMode.Create, FileAccess.Write, FileShare.Write), password); - if (zipStream == null) - { - return false; - } - - zipStream.Close(); - return true; - } - - /// - /// 压缩单个文件。 - /// - /// - /// Compresses a single file to a zip file. - /// - /// 要压缩的文件完整路径 / Full path of the file to compress - /// 压缩后的文件完整路径 / Full path of the zip file to create - /// 压缩密码(可选)/ Compression password (optional) - /// 如果成功返回 true;否则返回 false / true if successful; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool CompressFile(string fileToZip, string zipFile, string password = null) - { - if (!File.Exists(fileToZip)) - { - return false; - } - - using (var readStream = File.OpenRead(fileToZip)) - { - byte[] buffer = new byte[readStream.Length]; - var read = readStream.Read(buffer, 0, buffer.Length); - using (var writeStream = File.Create(zipFile)) - { - var entry = new ZipEntry(Path.GetFileName(fileToZip)) - { - DateTime = DateTime.Now, - Size = readStream.Length - }; - var crc = new Crc32(); - crc.Update(buffer); - entry.Crc = crc.Value; - using (var zipStream = new ZipOutputStream(writeStream)) - { - if (!string.IsNullOrEmpty(password)) - { - zipStream.Password = password; - } - - zipStream.PutNextEntry(entry); - zipStream.SetLevel(Deflater.BEST_COMPRESSION); - zipStream.Write(buffer, 0, buffer.Length); - } - } - } - - GC.Collect(1); - - return true; - } - - /// - /// 解压压缩文件到指定目录。 - /// - /// - /// Extracts a zip file to the specified directory. - /// - /// 待解压的文件完整路径 / Full path of the zip file to extract - /// 解压目标目录 / Target directory for extraction - /// 解压密码(可选)/ Extraction password (optional) - /// 如果成功返回 true;否则返回 false / true if successful; otherwise false - [UnityEngine.Scripting.Preserve] - public static bool DecompressFile(string fileToUnZip, string zipFolder, string password = null) - { - if (!System.IO.File.Exists(fileToUnZip)) - { - return false; - } - - if (!Directory.Exists(zipFolder)) - { - Directory.CreateDirectory(zipFolder); - } - - if (!zipFolder.EndsWith("\\")) - { - zipFolder += "\\"; - } - - using (var zipStream = new ZipInputStream(System.IO.File.OpenRead(fileToUnZip))) - { - if (!string.IsNullOrEmpty(password)) - { - zipStream.Password = password; - } - - ZipEntry zipEntry = null; - while ((zipEntry = zipStream.GetNextEntry()) != null) - { - if (zipEntry.IsDirectory) - { - continue; - } - - if (string.IsNullOrEmpty(zipEntry.Name)) - { - continue; - } - - string fileName = zipFolder + zipEntry.Name.Replace('/', '\\'); - var index = zipEntry.Name.LastIndexOf('/'); - if (index != -1) - { - string path = zipFolder + zipEntry.Name.Substring(0, index).Replace('/', '\\'); - System.IO.Directory.CreateDirectory(path); - } - - var bytes = new byte[zipEntry.Size]; - var read = zipStream.Read(bytes, 0, bytes.Length); - System.IO.File.WriteAllBytes(fileName, bytes); - } - } - - GC.Collect(1); - return true; - } - - /// - /// 用于压缩和解压缩操作的缓冲区大小(以字节为单位) - /// - private const int BufferSize = 8192; - - /// - /// 压缩数据。使用Deflate算法将原始字节数组压缩成更小的字节数组。 - /// - /// 要压缩的原始字节数组。不能为null。 - /// 压缩后的字节数组。如果输入为空数组,则直接返回该空数组。如果压缩过程中发生异常,则返回原始数组。 - /// 当输入参数content为null时抛出。 - [UnityEngine.Scripting.Preserve] - public static byte[] Compress(byte[] content) - { - content.CheckNull(nameof(content)); - if (content.Length == 0) - { - return content; - } - - var compressor = new Deflater(); - compressor.SetLevel(Deflater.BEST_COMPRESSION); - - compressor.SetInput(content); - compressor.Finish(); - - using (var compressorMemoryStream = new MemoryStream(content.Length)) - { - var buffer = ArrayPool.Shared.Rent(BufferSize); - try - { - while (!compressor.IsFinished) - { - var count = compressor.Deflate(buffer); - compressorMemoryStream.Write(buffer, 0, count); - } - - return compressorMemoryStream.ToArray(); - } - catch (Exception e) - { - Log.Fatal(e); - } - finally - { - ArrayPool.Shared.Return(buffer); - } - - return content; - } - } - - /// - /// 解压数据。使用Inflate算法将压缩的字节数组还原成原始字节数组。 - /// - /// 要解压的压缩字节数组。不能为null。 - /// 解压后的原始字节数组。如果输入为空数组,则直接返回该空数组。如果解压过程中发生异常,则返回原始数组。 - /// 当输入参数content为null时抛出。 - /// 当压缩数据格式无效或已损坏时抛出。 - [UnityEngine.Scripting.Preserve] - public static byte[] Decompress(byte[] content) - { - content.CheckNull(nameof(content)); - if (content.Length == 0) - { - return content; - } - - var decompressor = new Inflater(); - decompressor.SetInput(content, 0, content.Length); - using (var decompressMemoryStream = new MemoryStream(content.Length)) - { - var buffer = ArrayPool.Shared.Rent(BufferSize); - try - { - while (!decompressor.IsFinished) - { - var countLength = decompressor.Inflate(buffer); - decompressMemoryStream.Write(buffer, 0, countLength); - } - - return decompressMemoryStream.ToArray(); - } - catch (Exception e) - { - Log.Fatal(e); - } - finally - { - ArrayPool.Shared.Return(buffer, true); - } - - return content; - } - } - } +using System; +using System.Buffers; +using System.IO; +using ICSharpCode.SharpZipLib.Checksum; +using ICSharpCode.SharpZipLib.Zip; +using ICSharpCode.SharpZipLib.Zip.Compression; + +namespace GameFrameX.Runtime +{ + /// + /// 压缩帮助类。 + /// + /// + /// Zip compression helper class. + /// + [UnityEngine.Scripting.Preserve] + public static class ZipUtility + { + /// + /// 压缩文件夹到流。 + /// + /// + /// Compresses a folder to a stream. + /// + /// 要压缩的文件夹路径 / Folder path to compress + /// 压缩输出流 / Compressed output stream + /// 压缩密码(可选)/ Compression password (optional) + /// 如果成功返回 true;否则返回 false / true if successful; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool CompressDirectoryToStream(string folderToZip, Stream stream, string password = null) + { + return CompressDirectoryToZipStream(folderToZip, stream, password) != null; + } + + + /// + /// 压缩文件夹并返回ZipOutputStream。 + /// + /// + /// Compresses a folder to a stream and returns the ZipOutputStream. + /// + /// 要压缩的文件夹路径 / Folder path to compress + /// 压缩输出流 / Compressed output stream + /// 压缩密码(可选)/ Compression password (optional) + /// 如果成功返回ZipOutputStream;否则返回null / ZipOutputStream if successful; otherwise null + [UnityEngine.Scripting.Preserve] + public static ZipOutputStream CompressDirectoryToZipStream(string folderToZip, Stream stream, string password = null) + { + if (!Directory.Exists(folderToZip)) + { + return null; + } + + ZipOutputStream zipStream = new ZipOutputStream(stream); + zipStream.SetLevel(6); + if (!string.IsNullOrEmpty(password)) + { + zipStream.Password = password; + } + + if (CompressDirectory(folderToZip, zipStream, "")) + { + zipStream.Finish(); + return zipStream; + } + + GC.Collect(1); + return null; + } + + /// + /// 递归压缩文件夹的内部方法。 + /// + /// + /// Internal method for recursively compressing a folder. + /// + /// 要压缩的文件夹路径 / Folder path to compress + /// 压缩输出流 / Zip output stream + /// 此文件夹的上级文件夹名称 / Parent folder name + /// 如果成功返回 true;否则返回 false / true if successful; otherwise false + [UnityEngine.Scripting.Preserve] + private static bool CompressDirectory(string folderToZip, ZipOutputStream zipStream, string parentFolderName) + { + //这段是创建空文件夹,注释掉可以去掉空文件夹(因为在写入文件的时候也会创建文件夹) + if (parentFolderName.IsNotNullOrWhiteSpace()) + { + var ent = new ZipEntry(parentFolderName + "/"); + zipStream.PutNextEntry(ent); + zipStream.Flush(); + } + + var files = Directory.GetFiles(folderToZip); + foreach (string file in files) + { + byte[] buffer = File.ReadAllBytes(file); + var path = Path.GetFileName(file); + if (parentFolderName.IsNotNullOrWhiteSpace()) + { + path = parentFolderName + Path.DirectorySeparatorChar + Path.GetFileName(file); + } + + var ent = new ZipEntry(path) + { + //ent.DateTime = File.GetLastWriteTime(file);//设置文件最后修改时间 + DateTime = DateTime.Now, + Size = buffer.Length, + }; + + var crc = new Crc32(); + crc.Update(buffer); + + ent.Crc = crc.Value; + zipStream.PutNextEntry(ent); + zipStream.Write(buffer, 0, buffer.Length); + } + + var folders = Directory.GetDirectories(folderToZip); + foreach (var folder in folders) + { + var folderName = folder.Substring(folder.LastIndexOf('\\') + 1); + + if (parentFolderName.IsNotNullOrWhiteSpace()) + { + folderName = parentFolderName + "\\" + folder.Substring(folder.LastIndexOf('\\') + 1); + } + + if (!CompressDirectory(folder, zipStream, folderName)) + { + return false; + } + } + + return true; + } + + /// + /// 压缩文件夹到指定文件。 + /// + /// + /// Compresses a folder to a specified zip file. + /// + /// 要压缩的文件夹路径 / Folder path to compress + /// 压缩文件完整路径 / Full path of the zip file to create + /// 压缩密码(可选)/ Compression password (optional) + /// 如果成功返回 true;否则返回 false / true if successful; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool CompressDirectory(string folderToZip, string zipFile, string password = null) + { + if (folderToZip.EndsWithFast(Path.DirectorySeparatorChar.ToString()) || folderToZip.EndsWithFast("/")) + { + folderToZip = folderToZip.Substring(0, folderToZip.Length - 1); + } + + var zipStream = CompressDirectoryToZipStream(folderToZip, new FileStream(zipFile, FileMode.Create, FileAccess.Write, FileShare.Write), password); + if (zipStream == null) + { + return false; + } + + zipStream.Close(); + return true; + } + + /// + /// 压缩单个文件。 + /// + /// + /// Compresses a single file to a zip file. + /// + /// 要压缩的文件完整路径 / Full path of the file to compress + /// 压缩后的文件完整路径 / Full path of the zip file to create + /// 压缩密码(可选)/ Compression password (optional) + /// 如果成功返回 true;否则返回 false / true if successful; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool CompressFile(string fileToZip, string zipFile, string password = null) + { + if (!File.Exists(fileToZip)) + { + return false; + } + + using (var readStream = File.OpenRead(fileToZip)) + { + byte[] buffer = new byte[readStream.Length]; + var read = readStream.Read(buffer, 0, buffer.Length); + using (var writeStream = File.Create(zipFile)) + { + var entry = new ZipEntry(Path.GetFileName(fileToZip)) + { + DateTime = DateTime.Now, + Size = readStream.Length + }; + var crc = new Crc32(); + crc.Update(buffer); + entry.Crc = crc.Value; + using (var zipStream = new ZipOutputStream(writeStream)) + { + if (!string.IsNullOrEmpty(password)) + { + zipStream.Password = password; + } + + zipStream.PutNextEntry(entry); + zipStream.SetLevel(Deflater.BEST_COMPRESSION); + zipStream.Write(buffer, 0, buffer.Length); + } + } + } + + GC.Collect(1); + + return true; + } + + /// + /// 解压压缩文件到指定目录。 + /// + /// + /// Extracts a zip file to the specified directory. + /// + /// 待解压的文件完整路径 / Full path of the zip file to extract + /// 解压目标目录 / Target directory for extraction + /// 解压密码(可选)/ Extraction password (optional) + /// 如果成功返回 true;否则返回 false / true if successful; otherwise false + [UnityEngine.Scripting.Preserve] + public static bool DecompressFile(string fileToUnZip, string zipFolder, string password = null) + { + if (!System.IO.File.Exists(fileToUnZip)) + { + return false; + } + + if (!Directory.Exists(zipFolder)) + { + Directory.CreateDirectory(zipFolder); + } + + if (!zipFolder.EndsWith("\\")) + { + zipFolder += "\\"; + } + + using (var zipStream = new ZipInputStream(System.IO.File.OpenRead(fileToUnZip))) + { + if (!string.IsNullOrEmpty(password)) + { + zipStream.Password = password; + } + + ZipEntry zipEntry = null; + while ((zipEntry = zipStream.GetNextEntry()) != null) + { + if (zipEntry.IsDirectory) + { + continue; + } + + if (string.IsNullOrEmpty(zipEntry.Name)) + { + continue; + } + + string fileName = zipFolder + zipEntry.Name.Replace('/', '\\'); + var index = zipEntry.Name.LastIndexOf('/'); + if (index != -1) + { + string path = zipFolder + zipEntry.Name.Substring(0, index).Replace('/', '\\'); + System.IO.Directory.CreateDirectory(path); + } + + var bytes = new byte[zipEntry.Size]; + var read = zipStream.Read(bytes, 0, bytes.Length); + System.IO.File.WriteAllBytes(fileName, bytes); + } + } + + GC.Collect(1); + return true; + } + + /// + /// 用于压缩和解压缩操作的缓冲区大小(以字节为单位) + /// + private const int BufferSize = 8192; + + /// + /// 压缩数据。使用Deflate算法将原始字节数组压缩成更小的字节数组。 + /// + /// 要压缩的原始字节数组。不能为null。 + /// 压缩后的字节数组。如果输入为空数组,则直接返回该空数组。如果压缩过程中发生异常,则返回原始数组。 + /// 当输入参数content为null时抛出。 + [UnityEngine.Scripting.Preserve] + public static byte[] Compress(byte[] content) + { + content.CheckNull(nameof(content)); + if (content.Length == 0) + { + return content; + } + + var compressor = new Deflater(); + compressor.SetLevel(Deflater.BEST_COMPRESSION); + + compressor.SetInput(content); + compressor.Finish(); + + using (var compressorMemoryStream = new MemoryStream(content.Length)) + { + var buffer = ArrayPool.Shared.Rent(BufferSize); + try + { + while (!compressor.IsFinished) + { + var count = compressor.Deflate(buffer); + compressorMemoryStream.Write(buffer, 0, count); + } + + return compressorMemoryStream.ToArray(); + } + catch (Exception e) + { + Log.Fatal(e); + } + finally + { + ArrayPool.Shared.Return(buffer); + } + + return content; + } + } + + /// + /// 解压数据。使用Inflate算法将压缩的字节数组还原成原始字节数组。 + /// + /// 要解压的压缩字节数组。不能为null。 + /// 解压后的原始字节数组。如果输入为空数组,则直接返回该空数组。如果解压过程中发生异常,则返回原始数组。 + /// 当输入参数content为null时抛出。 + /// 当压缩数据格式无效或已损坏时抛出。 + [UnityEngine.Scripting.Preserve] + public static byte[] Decompress(byte[] content) + { + content.CheckNull(nameof(content)); + if (content.Length == 0) + { + return content; + } + + var decompressor = new Inflater(); + decompressor.SetInput(content, 0, content.Length); + using (var decompressMemoryStream = new MemoryStream(content.Length)) + { + var buffer = ArrayPool.Shared.Rent(BufferSize); + try + { + while (!decompressor.IsFinished) + { + var countLength = decompressor.Inflate(buffer); + decompressMemoryStream.Write(buffer, 0, countLength); + } + + return decompressMemoryStream.ToArray(); + } + catch (Exception e) + { + Log.Fatal(e); + } + finally + { + ArrayPool.Shared.Return(buffer, true); + } + + return content; + } + } + } } \ No newline at end of file diff --git a/Runtime/Helper/ZipHelper.cs.meta b/Runtime/Utility/ZipUtility.cs.meta similarity index 100% rename from Runtime/Helper/ZipHelper.cs.meta rename to Runtime/Utility/ZipUtility.cs.meta diff --git a/Tests/AesEncryptionTests.cs b/Tests/AesEncryptionTests.cs index a17e59f..a960838 100644 --- a/Tests/AesEncryptionTests.cs +++ b/Tests/AesEncryptionTests.cs @@ -18,8 +18,8 @@ public class AesEncryptionTests public void AESEncrypt_Decrypt_String_RoundTrip() { #pragma warning disable CS0618 - string encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintext, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + string encrypted = AesUtils.AESEncrypt(TestPlaintext, TestKey); + string decrypted = AesUtils.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 Assert.AreEqual(TestPlaintext, decrypted); @@ -29,8 +29,8 @@ public void AESEncrypt_Decrypt_String_RoundTrip() public void AESEncrypt_Decrypt_Bytes_RoundTrip() { #pragma warning disable CS0618 - byte[] encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); - byte[] decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + byte[] encrypted = AesUtils.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] decrypted = AesUtils.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); @@ -40,8 +40,8 @@ public void AESEncrypt_Decrypt_Bytes_RoundTrip() public void AESEncrypt_SamePlaintext_ProducesDifferentCiphertext() { #pragma warning disable CS0618 - string encrypted1 = Utility.Encryption.Aes.AESEncrypt(TestPlaintext, TestKey); - string encrypted2 = Utility.Encryption.Aes.AESEncrypt(TestPlaintext, TestKey); + string encrypted1 = AesUtils.AESEncrypt(TestPlaintext, TestKey); + string encrypted2 = AesUtils.AESEncrypt(TestPlaintext, TestKey); #pragma warning restore CS0618 Assert.AreNotEqual(encrypted1, encrypted2, "相同明文应产生不同密文(随机 IV/Salt)"); @@ -51,8 +51,8 @@ public void AESEncrypt_SamePlaintext_ProducesDifferentCiphertext() public void AESEncrypt_Bytes_SamePlaintext_ProducesDifferentCiphertext() { #pragma warning disable CS0618 - byte[] encrypted1 = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); - byte[] encrypted2 = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] encrypted1 = AesUtils.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] encrypted2 = AesUtils.AESEncrypt(TestPlaintextBytes, TestKey); #pragma warning restore CS0618 // 两个密文长度相同但内容不同(因为随机 IV/Salt) @@ -76,7 +76,7 @@ public void AESEncrypt_NullBytes_Throws() #pragma warning disable CS0618 Assert.Throws(() => { - Utility.Encryption.Aes.AESEncrypt(null, TestKey); + AesUtils.AESEncrypt(null, TestKey); }); #pragma warning restore CS0618 } @@ -87,7 +87,7 @@ public void AESEncrypt_EmptyKey_Throws() #pragma warning disable CS0618 Assert.Throws(() => { - Utility.Encryption.Aes.AESEncrypt(TestPlaintext, ""); + AesUtils.AESEncrypt(TestPlaintext, ""); }); #pragma warning restore CS0618 } @@ -99,7 +99,7 @@ public void AESDecrypt_ShortCiphertext_Throws() #pragma warning disable CS0618 Assert.Throws(() => { - Utility.Encryption.Aes.AESDecrypt(shortData, TestKey); + AesUtils.AESDecrypt(shortData, TestKey); }); #pragma warning restore CS0618 } @@ -111,8 +111,8 @@ public void AESDecrypt_ShortCiphertext_Throws() [Test] public void AESEncryptSecure_DecryptSecure_String_RoundTrip() { - string encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + string encrypted = AesUtils.AESEncryptSecure(TestPlaintext, TestKey); + string decrypted = AesUtils.AESDecryptSecure(encrypted, TestKey); Assert.AreEqual(TestPlaintext, decrypted); } @@ -120,8 +120,8 @@ public void AESEncryptSecure_DecryptSecure_String_RoundTrip() [Test] public void AESEncryptSecure_DecryptSecure_Bytes_RoundTrip() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); - byte[] decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + byte[] encrypted = AesUtils.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] decrypted = AesUtils.AESDecryptSecure(encrypted, TestKey); CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); } @@ -129,8 +129,8 @@ public void AESEncryptSecure_DecryptSecure_Bytes_RoundTrip() [Test] public void AESEncryptSecure_SamePlaintext_ProducesDifferentCiphertext() { - string encrypted1 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); - string encrypted2 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); + string encrypted1 = AesUtils.AESEncryptSecure(TestPlaintext, TestKey); + string encrypted2 = AesUtils.AESEncryptSecure(TestPlaintext, TestKey); Assert.AreNotEqual(encrypted1, encrypted2); } @@ -140,7 +140,7 @@ public void AESEncryptSecure_NullBytes_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESEncryptSecure(null, TestKey); + AesUtils.AESEncryptSecure(null, TestKey); }); } @@ -149,7 +149,7 @@ public void AESDecryptSecure_NullBytes_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure(null, TestKey); + AesUtils.AESDecryptSecure(null, TestKey); }); } @@ -159,14 +159,14 @@ public void AESDecryptSecure_TooShort_Throws() byte[] shortData = new byte[32]; Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure(shortData, TestKey); + AesUtils.AESDecryptSecure(shortData, TestKey); }); } [Test] public void AESEncryptSecure_CiphertextFormat_ContainsIVAndSalt() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = AesUtils.AESEncryptSecure(TestPlaintextBytes, TestKey); // 密文格式: [IV(16)][Salt(16)][加密数据] Assert.Greater(encrypted.Length, 32 + TestPlaintextBytes.Length, @@ -181,8 +181,8 @@ public void AESEncryptSecure_CiphertextFormat_ContainsIVAndSalt() public void AESEncrypt_ProducesDataDecryptableBy_AESDecryptSecure() { #pragma warning disable CS0618 - byte[] encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); - byte[] decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + byte[] encrypted = AesUtils.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] decrypted = AesUtils.AESDecryptSecure(encrypted, TestKey); #pragma warning restore CS0618 CollectionAssert.AreEqual(TestPlaintextBytes, decrypted, @@ -192,9 +192,9 @@ public void AESEncrypt_ProducesDataDecryptableBy_AESDecryptSecure() [Test] public void AESEncryptSecure_ProducesDataDecryptableBy_AESDecrypt() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = AesUtils.AESEncryptSecure(TestPlaintextBytes, TestKey); #pragma warning disable CS0618 - byte[] decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + byte[] decrypted = AesUtils.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 CollectionAssert.AreEqual(TestPlaintextBytes, decrypted, diff --git a/Tests/FileUtilityTests.cs b/Tests/FileUtilityTests.cs new file mode 100644 index 0000000..a15d695 --- /dev/null +++ b/Tests/FileUtilityTests.cs @@ -0,0 +1,95 @@ +using System.IO; +using GameFrameX.Runtime; +using NUnit.Framework; + +namespace GameFrameX.Tests +{ + [TestFixture] + public class FileUtilityTests + { + #region GetBytesSize + + [Test] + public void GetBytesSize_Zero_ReturnsPlainBytes() + { + Assert.AreEqual("0B", FileUtility.GetBytesSize(0)); + } + + [Test] + public void GetBytesSize_BelowOneKB_ReturnsBytesWithoutFormatting() + { + Assert.AreEqual("1B", FileUtility.GetBytesSize(1)); + Assert.AreEqual("1000B", FileUtility.GetBytesSize(1000)); + Assert.AreEqual("1023B", FileUtility.GetBytesSize(1023)); + } + + [Test] + public void GetBytesSize_ExactlyOneKB_ReturnsOneKB() + { + Assert.AreEqual("1KB", FileUtility.GetBytesSize(1024)); + } + + [Test] + public void GetBytesSize_FractionalKB_KeepsTwoDecimals() + { + Assert.AreEqual("1.5KB", FileUtility.GetBytesSize(1536)); + Assert.AreEqual("1.25KB", FileUtility.GetBytesSize(1280)); + Assert.AreEqual("10.01KB", FileUtility.GetBytesSize(10250)); + } + + [Test] + public void GetBytesSize_TrailingZerosAreTrimmed() + { + // 10240 / 1024 = 10, "10.00" 去尾零后应为 "10" 而非 "10." 或 "10.00" + Assert.AreEqual("10KB", FileUtility.GetBytesSize(10240)); + } + + [Test] + public void GetBytesSize_HigherUnits() + { + Assert.AreEqual("1MB", FileUtility.GetBytesSize(1024L * 1024)); + Assert.AreEqual("1GB", FileUtility.GetBytesSize(1024L * 1024 * 1024)); + Assert.AreEqual("1TB", FileUtility.GetBytesSize(1024L * 1024 * 1024 * 1024)); + Assert.AreEqual("1PB", FileUtility.GetBytesSize(1024L * 1024 * 1024 * 1024 * 1024)); + } + + [Test] + public void GetBytesSize_AbovePetaByte_CapsAtPetaUnit() + { + // 单位表上限为 PB, 超出后不再进位 + Assert.AreEqual("1024PB", FileUtility.GetBytesSize(1024L * 1024 * 1024 * 1024 * 1024 * 1024)); + } + + [Test] + public void GetBytesSize_NegativeValue_ReturnsNegativeBytes() + { + Assert.AreEqual("-1B", FileUtility.GetBytesSize(-1)); + } + + #endregion + + #region DeleteIfExists + + [Test] + public void DeleteIfExists_NonExistentFile_DoesNotThrow() + { + Assert.DoesNotThrow(() => + { + FileUtility.DeleteIfExists(Path.Combine(Path.GetTempPath(), "gfx_test_no_such_file.tmp")); + }); + } + + [Test] + public void DeleteIfExists_ExistingFile_DeletesFile() + { + string path = Path.Combine(Path.GetTempPath(), "gfx_test_delete_if_exists.tmp"); + File.WriteAllText(path, "x"); + + FileUtility.DeleteIfExists(path); + + Assert.IsFalse(File.Exists(path)); + } + + #endregion + } +} diff --git a/Runtime/Helper/DistinctHelper.cs.meta b/Tests/FileUtilityTests.cs.meta similarity index 83% rename from Runtime/Helper/DistinctHelper.cs.meta rename to Tests/FileUtilityTests.cs.meta index 884c6bb..d56eb93 100644 --- a/Runtime/Helper/DistinctHelper.cs.meta +++ b/Tests/FileUtilityTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1bdecedb0b9290a489c56161046fc164 +guid: 4f1cd83faaf40495fa322a107e8851aa MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Tests/GameFrameX.Tests.asmdef b/Tests/GameFrameX.Tests.asmdef index 2ce8ef9..0ae754d 100644 --- a/Tests/GameFrameX.Tests.asmdef +++ b/Tests/GameFrameX.Tests.asmdef @@ -2,7 +2,8 @@ "name": "GameFrameX.Tests", "references": [ "GameFrameX.Runtime", - "GameFrameX.LitJSON.Runtime" + "GameFrameX.LitJSON.Runtime", + "GameFrameX.Editor" ], "includePlatforms": [ "Editor" @@ -15,4 +16,4 @@ "defineConstraints": [], "versionDefines": [], "noEngineReferences": false -} +} \ No newline at end of file diff --git a/Tests/GameObjectExtensionTests.cs b/Tests/GameObjectExtensionTests.cs new file mode 100644 index 0000000..05301fe --- /dev/null +++ b/Tests/GameObjectExtensionTests.cs @@ -0,0 +1,200 @@ +using GameFrameX.Runtime; +using NUnit.Framework; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace GameFrameX.Tests +{ + [TestFixture] + public class GameObjectExtensionTests + { + private GameObject m_Root; + + [SetUp] + public void SetUp() + { + m_Root = new GameObject("GameObjectExtensionTests_Root"); + } + + [TearDown] + public void TearDown() + { + if (m_Root != null) + { + Object.DestroyImmediate(m_Root); + } + } + + #region SetLayer + + [Test] + public void SetLayer_NonRecursive_OnlyChangesSelf() + { + var child = new GameObject("Child"); + child.transform.SetParent(m_Root.transform); + const int targetLayer = 4; + + m_Root.SetLayer(targetLayer, false); + + Assert.AreEqual(targetLayer, m_Root.layer); + Assert.AreEqual(0, child.layer); + } + + [Test] + public void SetLayer_Recursive_ChangesAllDescendants() + { + var child = new GameObject("Child"); + child.transform.SetParent(m_Root.transform); + var grandChild = new GameObject("GrandChild"); + grandChild.transform.SetParent(child.transform); + const int targetLayer = 4; + + m_Root.SetLayer(targetLayer, true); + + Assert.AreEqual(targetLayer, m_Root.layer); + Assert.AreEqual(targetLayer, child.layer); + Assert.AreEqual(targetLayer, grandChild.layer); + } + + [Test] + public void SetLayer_Recursive_IncludesInactiveDescendants() + { + var child = new GameObject("Child"); + child.transform.SetParent(m_Root.transform); + var inactiveChild = new GameObject("InactiveChild"); + inactiveChild.transform.SetParent(child.transform); + inactiveChild.SetActive(false); + const int targetLayer = 4; + + m_Root.SetLayer(targetLayer, true); + + Assert.AreEqual(targetLayer, inactiveChild.layer); + } + + [Test] + public void SetLayer_AlreadyOnTargetLayer_RemainsUnchanged() + { + const int targetLayer = 4; + m_Root.layer = targetLayer; + + m_Root.SetLayer(targetLayer, true); + + Assert.AreEqual(targetLayer, m_Root.layer); + } + + #endregion + + #region CreateChild / ResetTransform / RemoveChildren + + [Test] + public void CreateChild_CreatesObjectUnderParent() + { + var child = m_Root.CreateChild("NewChild"); + + Assert.IsNotNull(child); + Assert.AreEqual("NewChild", child.name); + Assert.AreSame(m_Root.transform, child.transform.parent); + } + + [Test] + public void ResetTransform_ResetsLocalPositionRotationScale() + { + m_Root.transform.localPosition = new Vector3(5f, 5f, 5f); + m_Root.transform.localRotation = Quaternion.Euler(30f, 30f, 30f); + m_Root.transform.localScale = new Vector3(3f, 3f, 3f); + + m_Root.ResetTransform(); + + Assert.AreEqual(Vector3.zero, m_Root.transform.localPosition); + Assert.AreEqual(Quaternion.identity, m_Root.transform.localRotation); + Assert.AreEqual(Vector3.one, m_Root.transform.localScale); + } + + [Test] + public void RemoveChildren_DestroysAllChildren() + { + var child1 = new GameObject("Child1"); + child1.transform.SetParent(m_Root.transform); + var child2 = new GameObject("Child2"); + child2.transform.SetParent(m_Root.transform); + + m_Root.RemoveChildren(); + + Assert.AreEqual(0, m_Root.transform.childCount); + Assert.IsTrue(child1 == null); + Assert.IsTrue(child2 == null); + } + + [Test] + public void RemoveChildren_NoChildren_KeepsSelf() + { + m_Root.RemoveChildren(); + + Assert.IsTrue(m_Root != null); + Assert.AreEqual(0, m_Root.transform.childCount); + } + + #endregion + + #region FindChildGamObjectByName + + [Test] + public void FindChildGamObjectByName_Instance_FindsDeepDescendant() + { + var child = new GameObject("Level1"); + child.transform.SetParent(m_Root.transform); + var deep = new GameObject("DeepTarget"); + deep.transform.SetParent(child.transform); + + var result = m_Root.FindChildGamObjectByName("DeepTarget"); + + Assert.AreSame(deep, result); + } + + [Test] + public void FindChildGamObjectByName_Instance_MissingName_ReturnsNull() + { + Assert.IsNull(m_Root.FindChildGamObjectByName("NoSuchNode")); + } + + [Test] + public void FindChildGamObjectByName_UnloadedSceneName_ReturnsNull() + { + Assert.IsNull(GameObjectUtility.FindChildGamObjectByName("GameObjectExtensionTests_Root", "NoSuchScene")); + } + + [Test] + public void FindChildGamObjectByName_ActiveScene_FindsRootDescendant() + { + var child = new GameObject("ActiveSceneTarget"); + child.transform.SetParent(m_Root.transform); + + var result = GameObjectUtility.FindChildGamObjectByName("ActiveSceneTarget"); + + Assert.IsNotNull(result); + Assert.AreEqual("ActiveSceneTarget", result.name); + Object.DestroyImmediate(child); + } + + [Test] + public void FindChildGamObjectByName_ActiveScene_MissingNode_ReturnsNull() + { + Assert.IsNull(GameObjectUtility.FindChildGamObjectByName("NoSuchNodeAnywhere")); + } + + [Test] + public void FindChildGamObjectByName_UtilityMatchesExtensionResult() + { + var child = new GameObject("ConsistencyTarget"); + child.transform.SetParent(m_Root.transform); + + var viaUtility = GameObjectUtility.FindChildGamObjectByName("ConsistencyTarget"); + var viaExtension = UnityEngineGameObjectExtension.FindChildGamObjectByName("ConsistencyTarget"); + + Assert.AreSame(viaUtility, viaExtension); + Assert.AreSame(child, viaUtility); + } + + #endregion + } +} diff --git a/Runtime/Helper/FileHelper.cs.meta b/Tests/GameObjectExtensionTests.cs.meta similarity index 83% rename from Runtime/Helper/FileHelper.cs.meta rename to Tests/GameObjectExtensionTests.cs.meta index a85d577..6509840 100644 --- a/Runtime/Helper/FileHelper.cs.meta +++ b/Tests/GameObjectExtensionTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ebd01ea0aaffc2742a0b21b16a66704a +guid: 8dc75e9477f58494eb8f3bc1502ec7ba MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Tests/MathHelperTests.cs b/Tests/MathUtilityTests.cs similarity index 75% rename from Tests/MathHelperTests.cs rename to Tests/MathUtilityTests.cs index 6723cb8..26f9c4e 100644 --- a/Tests/MathHelperTests.cs +++ b/Tests/MathUtilityTests.cs @@ -6,7 +6,7 @@ namespace GameFrameX.Tests { [TestFixture] - public class MathHelperTests + public class MathUtilityTests { #region CheckIntersect (RectInt overload) @@ -16,7 +16,7 @@ public void CheckIntersect_RectInt_OverlappingRectangles_ReturnsTrue() var src = new RectInt(0, 0, 10, 10); var target = new RectInt(5, 5, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsTrue(result); } @@ -26,7 +26,7 @@ public void CheckIntersect_RectInt_IdenticalRectangles_ReturnsTrue() { var rect = new RectInt(0, 0, 10, 10); - bool result = MathHelper.CheckIntersect(rect, rect); + bool result = MathUtility.CheckIntersect(rect, rect); Assert.IsTrue(result); } @@ -37,7 +37,7 @@ public void CheckIntersect_RectInt_OneInsideOther_ReturnsTrue() var outer = new RectInt(0, 0, 20, 20); var inner = new RectInt(5, 5, 5, 5); - bool result = MathHelper.CheckIntersect(outer, inner); + bool result = MathUtility.CheckIntersect(outer, inner); Assert.IsTrue(result); } @@ -48,7 +48,7 @@ public void CheckIntersect_RectInt_CompletelySeparate_ReturnsFalse() var src = new RectInt(0, 0, 10, 10); var target = new RectInt(20, 20, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsFalse(result); } @@ -59,7 +59,7 @@ public void CheckIntersect_RectInt_AdjacentHorizontally_ReturnsFalse() var src = new RectInt(0, 0, 10, 10); var target = new RectInt(10, 0, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsFalse(result); } @@ -70,7 +70,7 @@ public void CheckIntersect_RectInt_AdjacentVertically_ReturnsFalse() var src = new RectInt(0, 0, 10, 10); var target = new RectInt(0, 10, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsFalse(result); } @@ -81,7 +81,7 @@ public void CheckIntersect_RectInt_ZeroSizeRect_ReturnsFalse() var src = new RectInt(0, 0, 0, 0); var target = new RectInt(0, 0, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsFalse(result); } @@ -92,7 +92,7 @@ public void CheckIntersect_RectInt_NegativeCoordinates_ReturnsTrue() var src = new RectInt(-5, -5, 10, 10); var target = new RectInt(0, 0, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsTrue(result); } @@ -103,7 +103,7 @@ public void CheckIntersect_RectInt_NegativeCoordinates_Separate_ReturnsFalse() var src = new RectInt(-20, -20, 10, 10); var target = new RectInt(0, 0, 10, 10); - bool result = MathHelper.CheckIntersect(src, target); + bool result = MathUtility.CheckIntersect(src, target); Assert.IsFalse(result); } @@ -115,7 +115,7 @@ public void CheckIntersect_RectInt_NegativeCoordinates_Separate_ReturnsFalse() [Test] public void CheckIntersect_Coords_Overlapping_ReturnsTrue() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 5, 5, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 5, 5, 10, 10); Assert.IsTrue(result); } @@ -123,7 +123,7 @@ public void CheckIntersect_Coords_Overlapping_ReturnsTrue() [Test] public void CheckIntersect_Coords_SameRectangle_ReturnsTrue() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 0, 0, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 0, 0, 10, 10); Assert.IsTrue(result); } @@ -131,7 +131,7 @@ public void CheckIntersect_Coords_SameRectangle_ReturnsTrue() [Test] public void CheckIntersect_Coords_Separate_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 20, 20, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 20, 20, 10, 10); Assert.IsFalse(result); } @@ -139,7 +139,7 @@ public void CheckIntersect_Coords_Separate_ReturnsFalse() [Test] public void CheckIntersect_Coords_AdjacentRight_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 10, 0, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 10, 0, 10, 10); Assert.IsFalse(result); } @@ -147,7 +147,7 @@ public void CheckIntersect_Coords_AdjacentRight_ReturnsFalse() [Test] public void CheckIntersect_Coords_AdjacentTop_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 0, 10, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 0, 10, 10, 10); Assert.IsFalse(result); } @@ -155,7 +155,7 @@ public void CheckIntersect_Coords_AdjacentTop_ReturnsFalse() [Test] public void CheckIntersect_Coords_ZeroWidth_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 0, 10, 0, 0, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 0, 10, 0, 0, 10, 10); Assert.IsFalse(result); } @@ -163,7 +163,7 @@ public void CheckIntersect_Coords_ZeroWidth_ReturnsFalse() [Test] public void CheckIntersect_Coords_ZeroHeight_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 0, 0, 0, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 0, 0, 0, 10, 10); Assert.IsFalse(result); } @@ -171,7 +171,7 @@ public void CheckIntersect_Coords_ZeroHeight_ReturnsFalse() [Test] public void CheckIntersect_Coords_PartialOverlap_ReturnsTrue() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 8, 8, 10, 10); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 8, 8, 10, 10); Assert.IsTrue(result); } @@ -179,7 +179,7 @@ public void CheckIntersect_Coords_PartialOverlap_ReturnsTrue() [Test] public void CheckIntersect_Coords_CrossShapedOverlap_ReturnsTrue() { - bool result = MathHelper.CheckIntersect(0, 5, 20, 10, 8, 0, 5, 20); + bool result = MathUtility.CheckIntersect(0, 5, 20, 10, 8, 0, 5, 20); Assert.IsTrue(result); } @@ -187,7 +187,7 @@ public void CheckIntersect_Coords_CrossShapedOverlap_ReturnsTrue() [Test] public void CheckIntersect_Coords_JustTouchingCorner_ReturnsFalse() { - bool result = MathHelper.CheckIntersect(0, 0, 10, 10, 10, 10, 5, 5); + bool result = MathUtility.CheckIntersect(0, 0, 10, 10, 10, 10, 5, 5); Assert.IsFalse(result); } @@ -201,7 +201,7 @@ public void CheckIntersectPoints_NoOverlap_ReturnsFalse() { int[] points = new int[100]; - bool result = MathHelper.CheckIntersectPoints(0, 0, 10, 10, 20, 20, 10, 10, points); + bool result = MathUtility.CheckIntersectPoints(0, 0, 10, 10, 20, 20, 10, 10, points); Assert.IsFalse(result); } @@ -215,7 +215,7 @@ public void CheckIntersectPoints_Overlap_MarksIntersectionPoints() points[i] = 1; } - bool result = MathHelper.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); + bool result = MathUtility.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); Assert.IsTrue(result); } @@ -229,7 +229,7 @@ public void CheckIntersectPoints_Overlap_PointsOutsideIntersectionRemainUnchange points[i] = 1; } - MathHelper.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); + MathUtility.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); Assert.AreEqual(0, points[5 * 10 + 5], "Point inside intersection should be cleared"); Assert.AreEqual(0, points[9 * 10 + 9], "Point inside intersection should be cleared"); @@ -246,7 +246,7 @@ public void CheckIntersectPoints_FullOverlap_ClearsAllMarkedPoints() points[i] = 1; } - MathHelper.CheckIntersectPoints(0, 0, 10, 10, 0, 0, 10, 10, points); + MathUtility.CheckIntersectPoints(0, 0, 10, 10, 0, 0, 10, 10, points); for (int i = 0; i < points.Length; i++) { @@ -259,7 +259,7 @@ public void CheckIntersectPoints_AlreadyZeroPoints_StaysZero() { int[] points = new int[100]; - MathHelper.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); + MathUtility.CheckIntersectPoints(0, 0, 10, 10, 5, 5, 10, 10, points); for (int i = 0; i < points.Length; i++) { diff --git a/Tests/MathHelperTests.cs.meta b/Tests/MathUtilityTests.cs.meta similarity index 100% rename from Tests/MathHelperTests.cs.meta rename to Tests/MathUtilityTests.cs.meta diff --git a/Tests/ObjectHelperTests.cs b/Tests/ObjectHelperTests.cs deleted file mode 100644 index 13c36af..0000000 --- a/Tests/ObjectHelperTests.cs +++ /dev/null @@ -1,136 +0,0 @@ -using GameFrameX.Runtime; -using NUnit.Framework; - -namespace GameFrameX.Tests -{ - [TestFixture] - public class ObjectHelperTests - { - #region Swap - - [Test] - public void Swap_IntValues_ExchangesCorrectly() - { - int a = 10; - int b = 20; - - ObjectHelper.Swap(ref a, ref b); - - Assert.AreEqual(20, a); - Assert.AreEqual(10, b); - } - - [Test] - public void Swap_StringValues_ExchangesCorrectly() - { - string a = "hello"; - string b = "world"; - - ObjectHelper.Swap(ref a, ref b); - - Assert.AreEqual("world", a); - Assert.AreEqual("hello", b); - } - - [Test] - public void Swap_SameVariable_NoChange() - { - int x = 42; - - ObjectHelper.Swap(ref x, ref x); - - Assert.AreEqual(42, x); - } - - [Test] - public void Swap_NullReference_ExchangesCorrectly() - { - string a = "not null"; - string b = null; - - ObjectHelper.Swap(ref a, ref b); - - Assert.IsNull(a); - Assert.AreEqual("not null", b); - } - - [Test] - public void Swap_BothNull_NoChange() - { - string a = null; - string b = null; - - ObjectHelper.Swap(ref a, ref b); - - Assert.IsNull(a); - Assert.IsNull(b); - } - - [Test] - public void Swap_ReferenceType_ExchangesCorrectly() - { - var obj1 = new SwapTestClass { Value = 1 }; - var obj2 = new SwapTestClass { Value = 2 }; - - ObjectHelper.Swap(ref obj1, ref obj2); - - Assert.AreEqual(2, obj1.Value); - Assert.AreEqual(1, obj2.Value); - } - - [Test] - public void Swap_FloatValues_ExchangesCorrectly() - { - float a = 1.5f; - float b = 2.5f; - - ObjectHelper.Swap(ref a, ref b); - - Assert.AreEqual(2.5f, a); - Assert.AreEqual(1.5f, b); - } - - [Test] - public void Swap_BoolValues_ExchangesCorrectly() - { - bool a = true; - bool b = false; - - ObjectHelper.Swap(ref a, ref b); - - Assert.IsFalse(a); - Assert.IsTrue(b); - } - - [Test] - public void Swap_NegativeValues_ExchangesCorrectly() - { - int a = -100; - int b = 100; - - ObjectHelper.Swap(ref a, ref b); - - Assert.AreEqual(100, a); - Assert.AreEqual(-100, b); - } - - [Test] - public void Swap_DefaultValues_ExchangesCorrectly() - { - int a = 0; - int b = 0; - - ObjectHelper.Swap(ref a, ref b); - - Assert.AreEqual(0, a); - Assert.AreEqual(0, b); - } - - #endregion - - private class SwapTestClass - { - public int Value; - } - } -} diff --git a/Tests/ObjectHelperTests.cs.meta b/Tests/ObjectHelperTests.cs.meta deleted file mode 100644 index 3f2f2f8..0000000 --- a/Tests/ObjectHelperTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b5064cf1eb54742b5b76b656b22ae71a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Tests/RandomHelperTests.cs b/Tests/RandomHelperTests.cs deleted file mode 100644 index 479862b..0000000 --- a/Tests/RandomHelperTests.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using GameFrameX.Runtime; -using NUnit.Framework; - -namespace GameFrameX.Tests -{ - [TestFixture] - public class RandomHelperTests - { - [SetUp] - public void SetUp() - { - RandomHelper.SetSeed(42); - } - - #region SetSeed - - [Test] - public void SetSeed_ProducesReproducibleSequence() - { - RandomHelper.SetSeed(42); - int first = RandomHelper.Next(0, 1000); - int second = RandomHelper.Next(0, 1000); - - RandomHelper.SetSeed(42); - int firstAgain = RandomHelper.Next(0, 1000); - int secondAgain = RandomHelper.Next(0, 1000); - - Assert.AreEqual(first, firstAgain); - Assert.AreEqual(second, secondAgain); - } - - [Test] - public void SetSeed_DifferentSeeds_ProduceDifferentValues() - { - RandomHelper.SetSeed(1); - int fromSeed1 = RandomHelper.Next(0, int.MaxValue); - - RandomHelper.SetSeed(999); - int fromSeed999 = RandomHelper.Next(0, int.MaxValue); - - Assert.AreNotEqual(fromSeed1, fromSeed999); - } - - #endregion - - #region Next (range) - - [Test] - public void Next_ReturnsValueWithinRange() - { - for (int i = 0; i < 100; i++) - { - int result = RandomHelper.Next(10, 20); - Assert.GreaterOrEqual(result, 10, "Result should be >= lower bound"); - Assert.Less(result, 20, "Result should be < upper bound"); - } - } - - [Test] - public void Next_SingleRange_ReturnsLower() - { - int result = RandomHelper.Next(5, 6); - - Assert.AreEqual(5, result); - } - - [Test] - public void Next_NegativeRange_ReturnsWithinRange() - { - for (int i = 0; i < 100; i++) - { - int result = RandomHelper.Next(-100, -50); - Assert.GreaterOrEqual(result, -100); - Assert.Less(result, -50); - } - } - - [Test] - public void Next_LargeRange_ReturnsWithinRange() - { - for (int i = 0; i < 100; i++) - { - int result = RandomHelper.Next(int.MinValue, int.MaxValue); - Assert.GreaterOrEqual(result, int.MinValue); - Assert.Less(result, int.MaxValue); - } - } - - #endregion - - #region Next (float 0-1) - - [Test] - public void Next_NoArgs_ReturnsFloatBetweenZeroAndOne() - { - for (int i = 0; i < 100; i++) - { - float result = RandomHelper.Next(); - Assert.GreaterOrEqual(result, 0.0f, "Result should be >= 0"); - Assert.Less(result, 1.0f, "Result should be < 1"); - } - } - - [Test] - public void Next_NoArgs_WithSeed_ReturnsReproducibleValue() - { - RandomHelper.SetSeed(123); - float first = RandomHelper.Next(); - - RandomHelper.SetSeed(123); - float second = RandomHelper.Next(); - - Assert.AreEqual(first, second); - } - - #endregion - - #region NextInt64 - - [Test] - public void NextInt64_ReturnsNonZeroOrAnyLongValue() - { - long result = RandomHelper.NextInt64(); - - Assert.That(result, Is.TypeOf()); - } - - [Test] - public void NextInt64_WithSeed_ReturnsReproducibleValue() - { - RandomHelper.SetSeed(77); - long first = RandomHelper.NextInt64(); - - RandomHelper.SetSeed(77); - long second = RandomHelper.NextInt64(); - - Assert.AreEqual(first, second); - } - - [Test] - public void NextInt64_MultipleCalls_ProduceDifferentValues() - { - long a = RandomHelper.NextInt64(); - long b = RandomHelper.NextInt64(); - long c = RandomHelper.NextInt64(); - - Assert.AreNotEqual(a, b, "Two consecutive calls should usually differ"); - Assert.AreNotEqual(b, c, "Three consecutive calls should usually differ"); - } - - #endregion - - #region NextUInt64 - - [Test] - public void NextUInt64_ReturnsULongValue() - { - ulong result = RandomHelper.NextUInt64(); - - Assert.That(result, Is.TypeOf()); - } - - [Test] - public void NextUInt64_WithSeed_ReturnsReproducibleValue() - { - RandomHelper.SetSeed(55); - ulong first = RandomHelper.NextUInt64(); - - RandomHelper.SetSeed(55); - ulong second = RandomHelper.NextUInt64(); - - Assert.AreEqual(first, second); - } - - [Test] - public void NextUInt64_MultipleCalls_ProduceDifferentValues() - { - ulong a = RandomHelper.NextUInt64(); - ulong b = RandomHelper.NextUInt64(); - - Assert.AreNotEqual(a, b); - } - - #endregion - } -} diff --git a/Tests/RandomHelperTests.cs.meta b/Tests/RandomHelperTests.cs.meta deleted file mode 100644 index bf807d5..0000000 --- a/Tests/RandomHelperTests.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 567353aad63c74fbd9b022d05ddc5533 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Tests/ShellUtilityTests.cs b/Tests/ShellUtilityTests.cs new file mode 100644 index 0000000..921fb06 --- /dev/null +++ b/Tests/ShellUtilityTests.cs @@ -0,0 +1,116 @@ +using System.Text; +using GameFrameX.Editor; +using NUnit.Framework; +using UnityEngine; + +namespace GameFrameX.Tests +{ + [TestFixture] + public class ShellUtilityTests + { + #region 测试用监视器 + + private sealed class TestShellMonitor : ShellUtility.IShellMonitor + { + private readonly bool m_AbortRequested; + + public TestShellMonitor(bool abortRequested) + { + m_AbortRequested = abortRequested; + Commands = new StringBuilder(); + Output = new StringBuilder(); + Errors = new StringBuilder(); + } + + public StringBuilder Commands { get; } + + public StringBuilder Output { get; } + + public StringBuilder Errors { get; } + + public bool AbortRequested + { + get { return m_AbortRequested; } + } + + public event ShellUtility.ShellRequestAbortEventHandler RequestAbort; + + public void AppendCommand(string command, string args) + { + Commands.Append(command).Append(' ').AppendLine(args); + } + + public void AppendOutputLine(string line) + { + Output.AppendLine(line); + } + + public void AppendErrorLine(string line) + { + Errors.AppendLine(line); + } + + public void RaiseAbort(bool kill) + { + if (RequestAbort != null) + { + RequestAbort(kill); + } + } + } + + #endregion + + [Test] + public void ExecuteCommand_AbortRequested_ReturnsUserAbortedWithoutStarting() + { + var monitor = new TestShellMonitor(true); + + var result = ShellUtility.ExecuteCommand("echo", "hello", monitor); + + Assert.IsTrue(result.HasErrors); + Assert.AreEqual(ShellUtility.USER_ABORTED_LOG, result.Error.Trim()); + Assert.AreEqual(0, monitor.Commands.Length, "中止时不应下发命令到监视器"); + } + + [Test] + public void ExecuteCommand_UnknownCommand_CapturesErrorWithoutThrowing() + { + var result = ShellUtility.ExecuteCommand("gfx_no_such_command_xyz_12345", ""); + + Assert.IsTrue(result.HasErrors); + Assert.IsNotEmpty(result.Error); + } + + [Test] + public void ExecuteCommand_Echo_ReturnsOutput() + { + if (Application.platform == RuntimePlatform.WindowsEditor) + { + Assert.Ignore("echo 不是 Windows 可执行文件"); + } + + var result = ShellUtility.ExecuteCommand("echo", "hello"); + + Assert.IsFalse(result.HasErrors, result.Error); + Assert.IsTrue(result.Output.Contains("hello")); + } + + [Test] + public void ExecuteCommand_MonitorReceivesCommandAndOutput() + { + if (Application.platform == RuntimePlatform.WindowsEditor) + { + Assert.Ignore("echo 不是 Windows 可执行文件"); + } + + var monitor = new TestShellMonitor(false); + + var result = ShellUtility.ExecuteCommand("echo", "monitored", monitor); + + Assert.IsFalse(result.HasErrors, result.Error); + StringAssert.Contains("echo monitored", monitor.Commands.ToString()); + StringAssert.Contains("monitored", monitor.Output.ToString()); + } + } +} diff --git a/Runtime/Helper/NetworkHelper.cs.meta b/Tests/ShellUtilityTests.cs.meta similarity index 83% rename from Runtime/Helper/NetworkHelper.cs.meta rename to Tests/ShellUtilityTests.cs.meta index 0c525bc..0c89c17 100644 --- a/Runtime/Helper/NetworkHelper.cs.meta +++ b/Tests/ShellUtilityTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d01371fd5daceb549b1620d32dd472c6 +guid: 2543f813f13cb4566bd71f240e541385 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Tests/StringExtensionsConvertTests.cs b/Tests/StringExtensionsConvertTests.cs new file mode 100644 index 0000000..92c4b0f --- /dev/null +++ b/Tests/StringExtensionsConvertTests.cs @@ -0,0 +1,132 @@ +using GameFrameX.Runtime; +using NUnit.Framework; + +namespace GameFrameX.Tests +{ + [TestFixture] + public class StringExtensionsConvertTests + { + private enum TestDay + { + None = 0, + Monday = 1, + Friday = 5, + } + + #region ToInt + + [Test] + public void ToInt_ValidString_ReturnsValue() + { + Assert.AreEqual(42, "42".ToInt()); + Assert.AreEqual(-7, "-7".ToInt()); + Assert.AreEqual(int.MaxValue, int.MaxValue.ToString().ToInt()); + Assert.AreEqual(int.MinValue, int.MinValue.ToString().ToInt()); + } + + [Test] + public void ToInt_InvalidString_ReturnsDefault() + { + Assert.AreEqual(0, "abc".ToInt()); + } + + [Test] + public void ToInt_NullOrEmpty_ReturnsDefault() + { + Assert.AreEqual(0, ((string)null).ToInt()); + Assert.AreEqual(0, string.Empty.ToInt()); + } + + [Test] + public void ToInt_LeadingOrTrailingWhitespace_IsParsed() + { + // NumberStyles.Integer 默认允许首尾空白 + Assert.AreEqual(42, " 42".ToInt()); + Assert.AreEqual(42, "42 ".ToInt()); + } + + [Test] + public void ToInt_InternalWhitespace_ReturnsDefault() + { + Assert.AreEqual(0, "4 2".ToInt()); + } + + [Test] + public void ToInt_OverflowReturnsCustomDefault() + { + Assert.AreEqual(-1, long.MaxValue.ToString().ToInt(-1)); + } + + [Test] + public void ToInt_InvalidReturnsCustomDefault() + { + Assert.AreEqual(99, "not-a-number".ToInt(99)); + } + + #endregion + + #region ToLong / ToFloat / ToDouble + + [Test] + public void ToLong_ValidAndInvalid() + { + Assert.AreEqual(long.MaxValue, long.MaxValue.ToString().ToLong()); + Assert.AreEqual(0L, "xyz".ToLong()); + Assert.AreEqual(5L, ((string)null).ToLong(5L)); + } + + [Test] + public void ToFloat_ValidAndInvalid() + { + Assert.AreEqual(3.5f, "3.5".ToFloat()); + Assert.AreEqual(0f, "abc".ToFloat()); + Assert.AreEqual(1.25f, ((string)null).ToFloat(1.25f)); + } + + [Test] + public void ToDouble_ValidAndInvalid() + { + Assert.AreEqual(2.718281828459045, "2.718281828459045".ToDouble()); + Assert.AreEqual(0d, "abc".ToDouble()); + Assert.AreEqual(-0.5d, string.Empty.ToDouble(-0.5d)); + } + + #endregion + + #region ToEnum + + [Test] + public void ToEnum_ValidName_ReturnsEnum() + { + Assert.AreEqual(TestDay.Monday, "Monday".ToEnum()); + } + + [Test] + public void ToEnum_CaseSensitiveByDefault_ReturnsDefault() + { + Assert.AreEqual(TestDay.None, "monday".ToEnum()); + } + + [Test] + public void ToEnum_IgnoreCase_ReturnsEnum() + { + Assert.AreEqual(TestDay.Friday, "friday".ToEnum(true)); + } + + [Test] + public void ToEnum_InvalidName_ReturnsDefault() + { + Assert.AreEqual(TestDay.None, "Sunday".ToEnum()); + Assert.AreEqual(TestDay.Friday, "Sunday".ToEnum(false, TestDay.Friday)); + } + + [Test] + public void ToEnum_NullOrEmpty_ReturnsDefault() + { + Assert.AreEqual(TestDay.None, ((string)null).ToEnum()); + Assert.AreEqual(TestDay.None, string.Empty.ToEnum()); + } + + #endregion + } +} diff --git a/Runtime/Helper/ObjectHelper.cs.meta b/Tests/StringExtensionsConvertTests.cs.meta similarity index 83% rename from Runtime/Helper/ObjectHelper.cs.meta rename to Tests/StringExtensionsConvertTests.cs.meta index 1955508..68eb585 100644 --- a/Runtime/Helper/ObjectHelper.cs.meta +++ b/Tests/StringExtensionsConvertTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b9e669cbe224b344abf33cd3f9d6e4f4 +guid: 588bcdaab3f4c44d3abaaf73fd5528a5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Tests/UtilityConverterTests.cs b/Tests/UtilityConverterTests.cs index 20a65cf..2ed0e71 100644 --- a/Tests/UtilityConverterTests.cs +++ b/Tests/UtilityConverterTests.cs @@ -13,7 +13,7 @@ public class UtilityConverterTests [Test] public void IsLittleEndian_MatchesBitConverter() { - Assert.AreEqual(BitConverter.IsLittleEndian, Utility.Converter.IsLittleEndian); + Assert.AreEqual(BitConverter.IsLittleEndian, ConverterUtility.IsLittleEndian); } #endregion @@ -23,76 +23,76 @@ public void IsLittleEndian_MatchesBitConverter() [Test] public void GetCentimetersFromPixels_Throws_WhenDpiNotSet() { - Utility.Converter.ScreenDpi = 0; + ConverterUtility.ScreenDpi = 0; Assert.Throws(() => { - Utility.Converter.GetCentimetersFromPixels(100f); + ConverterUtility.GetCentimetersFromPixels(100f); }); } [Test] public void GetPixelsFromCentimeters_Throws_WhenDpiNotSet() { - Utility.Converter.ScreenDpi = 0; + ConverterUtility.ScreenDpi = 0; Assert.Throws(() => { - Utility.Converter.GetPixelsFromCentimeters(10f); + ConverterUtility.GetPixelsFromCentimeters(10f); }); } [Test] public void GetInchesFromPixels_Throws_WhenDpiNotSet() { - Utility.Converter.ScreenDpi = 0; + ConverterUtility.ScreenDpi = 0; Assert.Throws(() => { - Utility.Converter.GetInchesFromPixels(100f); + ConverterUtility.GetInchesFromPixels(100f); }); } [Test] public void GetPixelsFromInches_Throws_WhenDpiNotSet() { - Utility.Converter.ScreenDpi = 0; + ConverterUtility.ScreenDpi = 0; Assert.Throws(() => { - Utility.Converter.GetPixelsFromInches(10f); + ConverterUtility.GetPixelsFromInches(10f); }); } [Test] public void GetCentimetersFromPixels_ReturnsCorrectValue() { - Utility.Converter.ScreenDpi = 96f; - float result = Utility.Converter.GetCentimetersFromPixels(96f); + ConverterUtility.ScreenDpi = 96f; + float result = ConverterUtility.GetCentimetersFromPixels(96f); Assert.AreEqual(2.54f, result, 0.0001f); } [Test] public void GetPixelsFromCentimeters_RoundTrip() { - Utility.Converter.ScreenDpi = 96f; + ConverterUtility.ScreenDpi = 96f; float pixels = 200f; - float cm = Utility.Converter.GetCentimetersFromPixels(pixels); - float back = Utility.Converter.GetPixelsFromCentimeters(cm); + float cm = ConverterUtility.GetCentimetersFromPixels(pixels); + float back = ConverterUtility.GetPixelsFromCentimeters(cm); Assert.AreEqual(pixels, back, 0.001f); } [Test] public void GetInchesFromPixels_ReturnsCorrectValue() { - Utility.Converter.ScreenDpi = 96f; - float result = Utility.Converter.GetInchesFromPixels(96f); + ConverterUtility.ScreenDpi = 96f; + float result = ConverterUtility.GetInchesFromPixels(96f); Assert.AreEqual(1f, result, 0.0001f); } [Test] public void GetPixelsFromInches_RoundTrip() { - Utility.Converter.ScreenDpi = 96f; + ConverterUtility.ScreenDpi = 96f; float inches = 2f; - float px = Utility.Converter.GetPixelsFromInches(inches); - float back = Utility.Converter.GetInchesFromPixels(px); + float px = ConverterUtility.GetPixelsFromInches(inches); + float back = ConverterUtility.GetInchesFromPixels(px); Assert.AreEqual(inches, back, 0.001f); } @@ -103,7 +103,7 @@ public void GetPixelsFromInches_RoundTrip() [Test] public void GetBytes_Bool_True() { - byte[] result = Utility.Converter.GetBytes(true); + byte[] result = ConverterUtility.GetBytes(true); Assert.AreEqual(1, result.Length); Assert.AreEqual(1, result[0]); } @@ -111,7 +111,7 @@ public void GetBytes_Bool_True() [Test] public void GetBytes_Bool_False() { - byte[] result = Utility.Converter.GetBytes(false); + byte[] result = ConverterUtility.GetBytes(false); Assert.AreEqual(1, result.Length); Assert.AreEqual(0, result[0]); } @@ -121,7 +121,7 @@ public void GetBytes_Bool_NullBuffer_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes(true, null, 0); + ConverterUtility.GetBytes(true, null, 0); }); } @@ -131,7 +131,7 @@ public void GetBytes_Bool_InvalidStartIndex_Throws() byte[] buffer = new byte[1]; Assert.Throws(() => { - Utility.Converter.GetBytes(true, buffer, -1); + ConverterUtility.GetBytes(true, buffer, -1); }); } @@ -141,26 +141,26 @@ public void GetBytes_Bool_BufferTooSmall_Throws() byte[] buffer = new byte[1]; Assert.Throws(() => { - Utility.Converter.GetBytes(true, buffer, 1); + ConverterUtility.GetBytes(true, buffer, 1); }); } [Test] public void GetBoolean_RoundTrip() { - byte[] bytes = Utility.Converter.GetBytes(true); - Assert.IsTrue(Utility.Converter.GetBoolean(bytes)); + byte[] bytes = ConverterUtility.GetBytes(true); + Assert.IsTrue(ConverterUtility.GetBoolean(bytes)); - bytes = Utility.Converter.GetBytes(false); - Assert.IsFalse(Utility.Converter.GetBoolean(bytes)); + bytes = ConverterUtility.GetBytes(false); + Assert.IsFalse(ConverterUtility.GetBoolean(bytes)); } [Test] public void GetBoolean_WithOffset() { byte[] buffer = new byte[3]; - Utility.Converter.GetBytes(true, buffer, 1); - Assert.IsTrue(Utility.Converter.GetBoolean(buffer, 1)); + ConverterUtility.GetBytes(true, buffer, 1); + Assert.IsTrue(ConverterUtility.GetBoolean(buffer, 1)); } #endregion @@ -171,9 +171,9 @@ public void GetBoolean_WithOffset() public void GetBytes_Int16_RoundTrip() { short value = -12345; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(2, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetInt16(bytes)); + Assert.AreEqual(value, ConverterUtility.GetInt16(bytes)); } [Test] @@ -181,8 +181,8 @@ public void GetBytes_Int16_WithOffset() { short value = 1234; byte[] buffer = new byte[10]; - Utility.Converter.GetBytes(value, buffer, 4); - Assert.AreEqual(value, Utility.Converter.GetInt16(buffer, 4)); + ConverterUtility.GetBytes(value, buffer, 4); + Assert.AreEqual(value, ConverterUtility.GetInt16(buffer, 4)); } [Test] @@ -190,7 +190,7 @@ public void GetBytes_Int16_NullBuffer_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes((short)1, null, 0); + ConverterUtility.GetBytes((short)1, null, 0); }); } @@ -200,7 +200,7 @@ public void GetBytes_Int16_InvalidStartIndex_Throws() byte[] buffer = new byte[2]; Assert.Throws(() => { - Utility.Converter.GetBytes((short)1, buffer, -1); + ConverterUtility.GetBytes((short)1, buffer, -1); }); } @@ -210,7 +210,7 @@ public void GetBytes_Int16_BufferTooSmall_Throws() byte[] buffer = new byte[1]; Assert.Throws(() => { - Utility.Converter.GetBytes((short)1, buffer, 0); + ConverterUtility.GetBytes((short)1, buffer, 0); }); } @@ -222,8 +222,8 @@ public void GetBytes_Int16_BufferTooSmall_Throws() public void GetBytes_UInt16_RoundTrip() { ushort value = 65000; - byte[] bytes = Utility.Converter.GetBytes(value); - Assert.AreEqual(value, Utility.Converter.GetUInt16(bytes)); + byte[] bytes = ConverterUtility.GetBytes(value); + Assert.AreEqual(value, ConverterUtility.GetUInt16(bytes)); } [Test] @@ -231,8 +231,8 @@ public void GetBytes_UInt16_WithOffset() { ushort value = 54321; byte[] buffer = new byte[10]; - Utility.Converter.GetBytes(value, buffer, 3); - Assert.AreEqual(value, Utility.Converter.GetUInt16(buffer, 3)); + ConverterUtility.GetBytes(value, buffer, 3); + Assert.AreEqual(value, ConverterUtility.GetUInt16(buffer, 3)); } #endregion @@ -243,27 +243,27 @@ public void GetBytes_UInt16_WithOffset() public void GetBytes_Int32_RoundTrip() { int value = -987654; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(4, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetInt32(bytes)); + Assert.AreEqual(value, ConverterUtility.GetInt32(bytes)); } [Test] public void GetBytes_Int32_Zero() { - Assert.AreEqual(0, Utility.Converter.GetInt32(Utility.Converter.GetBytes(0))); + Assert.AreEqual(0, ConverterUtility.GetInt32(ConverterUtility.GetBytes(0))); } [Test] public void GetBytes_Int32_MaxValue() { - Assert.AreEqual(int.MaxValue, Utility.Converter.GetInt32(Utility.Converter.GetBytes(int.MaxValue))); + Assert.AreEqual(int.MaxValue, ConverterUtility.GetInt32(ConverterUtility.GetBytes(int.MaxValue))); } [Test] public void GetBytes_Int32_MinValue() { - Assert.AreEqual(int.MinValue, Utility.Converter.GetInt32(Utility.Converter.GetBytes(int.MinValue))); + Assert.AreEqual(int.MinValue, ConverterUtility.GetInt32(ConverterUtility.GetBytes(int.MinValue))); } [Test] @@ -271,7 +271,7 @@ public void GetBytes_Int32_NullBuffer_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes(1, null, 0); + ConverterUtility.GetBytes(1, null, 0); }); } @@ -281,7 +281,7 @@ public void GetBytes_Int32_BufferTooSmall_Throws() byte[] buffer = new byte[3]; Assert.Throws(() => { - Utility.Converter.GetBytes(1, buffer, 0); + ConverterUtility.GetBytes(1, buffer, 0); }); } @@ -293,8 +293,8 @@ public void GetBytes_Int32_BufferTooSmall_Throws() public void GetBytes_UInt32_RoundTrip() { uint value = 3000000000; - byte[] bytes = Utility.Converter.GetBytes(value); - Assert.AreEqual(value, Utility.Converter.GetUInt32(bytes)); + byte[] bytes = ConverterUtility.GetBytes(value); + Assert.AreEqual(value, ConverterUtility.GetUInt32(bytes)); } #endregion @@ -305,15 +305,15 @@ public void GetBytes_UInt32_RoundTrip() public void GetBytes_Int64_RoundTrip() { long value = -9876543210L; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(8, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetInt64(bytes)); + Assert.AreEqual(value, ConverterUtility.GetInt64(bytes)); } [Test] public void GetBytes_Int64_MaxValue() { - Assert.AreEqual(long.MaxValue, Utility.Converter.GetInt64(Utility.Converter.GetBytes(long.MaxValue))); + Assert.AreEqual(long.MaxValue, ConverterUtility.GetInt64(ConverterUtility.GetBytes(long.MaxValue))); } [Test] @@ -321,7 +321,7 @@ public void GetBytes_Int64_NullBuffer_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes(1L, null, 0); + ConverterUtility.GetBytes(1L, null, 0); }); } @@ -333,8 +333,8 @@ public void GetBytes_Int64_NullBuffer_Throws() public void GetBytes_UInt64_RoundTrip() { ulong value = 18000000000000000UL; - byte[] bytes = Utility.Converter.GetBytes(value); - Assert.AreEqual(value, Utility.Converter.GetUInt64(bytes)); + byte[] bytes = ConverterUtility.GetBytes(value); + Assert.AreEqual(value, ConverterUtility.GetUInt64(bytes)); } #endregion @@ -345,9 +345,9 @@ public void GetBytes_UInt64_RoundTrip() public void GetBytes_Char_RoundTrip() { char value = 'A'; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(2, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetChar(bytes)); + Assert.AreEqual(value, ConverterUtility.GetChar(bytes)); } [Test] @@ -355,8 +355,8 @@ public void GetBytes_Char_WithOffset() { char value = '中'; byte[] buffer = new byte[10]; - Utility.Converter.GetBytes(value, buffer, 5); - Assert.AreEqual(value, Utility.Converter.GetChar(buffer, 5)); + ConverterUtility.GetBytes(value, buffer, 5); + Assert.AreEqual(value, ConverterUtility.GetChar(buffer, 5)); } #endregion @@ -367,29 +367,29 @@ public void GetBytes_Char_WithOffset() public void GetBytes_Single_RoundTrip() { float value = 3.14f; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(4, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetSingle(bytes), 0.0001f); + Assert.AreEqual(value, ConverterUtility.GetSingle(bytes), 0.0001f); } [Test] public void GetBytes_Single_Zero() { - Assert.AreEqual(0f, Utility.Converter.GetSingle(Utility.Converter.GetBytes(0f)), 0.0001f); + Assert.AreEqual(0f, ConverterUtility.GetSingle(ConverterUtility.GetBytes(0f)), 0.0001f); } [Test] public void GetBytes_Single_NegativeInfinity() { float value = float.NegativeInfinity; - Assert.AreEqual(value, Utility.Converter.GetSingle(Utility.Converter.GetBytes(value))); + Assert.AreEqual(value, ConverterUtility.GetSingle(ConverterUtility.GetBytes(value))); } [Test] public void GetBytes_Single_NaN() { float value = float.NaN; - Assert.IsNaN(Utility.Converter.GetSingle(Utility.Converter.GetBytes(value))); + Assert.IsNaN(ConverterUtility.GetSingle(ConverterUtility.GetBytes(value))); } [Test] @@ -397,8 +397,8 @@ public void GetBytes_Single_WithOffset() { float value = -999.5f; byte[] buffer = new byte[10]; - Utility.Converter.GetBytes(value, buffer, 3); - Assert.AreEqual(value, Utility.Converter.GetSingle(buffer, 3), 0.0001f); + ConverterUtility.GetBytes(value, buffer, 3); + Assert.AreEqual(value, ConverterUtility.GetSingle(buffer, 3), 0.0001f); } #endregion @@ -409,9 +409,9 @@ public void GetBytes_Single_WithOffset() public void GetBytes_Double_RoundTrip() { double value = 2.718281828; - byte[] bytes = Utility.Converter.GetBytes(value); + byte[] bytes = ConverterUtility.GetBytes(value); Assert.AreEqual(8, bytes.Length); - Assert.AreEqual(value, Utility.Converter.GetDouble(bytes), 0.0000001); + Assert.AreEqual(value, ConverterUtility.GetDouble(bytes), 0.0000001); } [Test] @@ -419,8 +419,8 @@ public void GetBytes_Double_WithOffset() { double value = -123.456; byte[] buffer = new byte[20]; - Utility.Converter.GetBytes(value, buffer, 5); - Assert.AreEqual(value, Utility.Converter.GetDouble(buffer, 5), 0.0000001); + ConverterUtility.GetBytes(value, buffer, 5); + Assert.AreEqual(value, ConverterUtility.GetDouble(buffer, 5), 0.0000001); } #endregion @@ -431,8 +431,8 @@ public void GetBytes_Double_WithOffset() public void GetBytes_String_UTF8_RoundTrip() { string value = "Hello World"; - byte[] bytes = Utility.Converter.GetBytes(value); - string result = Utility.Converter.GetString(bytes); + byte[] bytes = ConverterUtility.GetBytes(value); + string result = ConverterUtility.GetString(bytes); Assert.AreEqual(value, result); } @@ -440,8 +440,8 @@ public void GetBytes_String_UTF8_RoundTrip() public void GetBytes_String_Unicode_RoundTrip() { string value = "你好世界"; - byte[] bytes = Utility.Converter.GetBytes(value, Encoding.Unicode); - string result = Utility.Converter.GetString(bytes, Encoding.Unicode); + byte[] bytes = ConverterUtility.GetBytes(value, Encoding.Unicode); + string result = ConverterUtility.GetString(bytes, Encoding.Unicode); Assert.AreEqual(value, result); } @@ -450,7 +450,7 @@ public void GetBytes_String_NullValue_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes(null, Encoding.UTF8); + ConverterUtility.GetBytes(null, Encoding.UTF8); }); } @@ -459,7 +459,7 @@ public void GetBytes_String_NullEncoding_Throws() { Assert.Throws(() => { - Utility.Converter.GetBytes("test", (System.Text.Encoding)null); + ConverterUtility.GetBytes("test", (System.Text.Encoding)null); }); } @@ -468,7 +468,7 @@ public void GetString_NullValue_Throws() { Assert.Throws(() => { - Utility.Converter.GetString(null); + ConverterUtility.GetString(null); }); } @@ -477,7 +477,7 @@ public void GetString_NullEncoding_Throws() { Assert.Throws(() => { - Utility.Converter.GetString(new byte[0], null); + ConverterUtility.GetString(new byte[0], null); }); } @@ -485,8 +485,8 @@ public void GetString_NullEncoding_Throws() public void GetString_WithOffsetAndLength() { string value = "ABCDEFGH"; - byte[] bytes = Utility.Converter.GetBytes(value); - string result = Utility.Converter.GetString(bytes, 0, 5); + byte[] bytes = ConverterUtility.GetBytes(value); + string result = ConverterUtility.GetString(bytes, 0, 5); Assert.AreEqual("ABCDE", result); } @@ -495,9 +495,9 @@ public void GetBytes_String_ToBuffer() { string value = "Test"; byte[] buffer = new byte[10]; - int written = Utility.Converter.GetBytes(value, buffer, 0); + int written = ConverterUtility.GetBytes(value, buffer, 0); Assert.AreEqual(Encoding.UTF8.GetByteCount(value), written); - Assert.AreEqual(value, Utility.Converter.GetString(buffer, 0, written)); + Assert.AreEqual(value, ConverterUtility.GetString(buffer, 0, written)); } [Test] @@ -506,7 +506,7 @@ public void GetBytes_String_ToBuffer_NullValue_Throws() byte[] buffer = new byte[10]; Assert.Throws(() => { - Utility.Converter.GetBytes(null, Encoding.UTF8, buffer, 0); + ConverterUtility.GetBytes(null, Encoding.UTF8, buffer, 0); }); } @@ -515,7 +515,7 @@ public void GetString_NullValueWithOffset_Throws() { Assert.Throws(() => { - Utility.Converter.GetString(null, 0, 0, Encoding.UTF8); + ConverterUtility.GetString(null, 0, 0, Encoding.UTF8); }); } @@ -528,15 +528,15 @@ public void MultipleValues_PackedInSingleBuffer() { byte[] buffer = new byte[100]; - Utility.Converter.GetBytes(true, buffer, 0); - Utility.Converter.GetBytes((short)1234, buffer, 1); - Utility.Converter.GetBytes(56789, buffer, 3); - Utility.Converter.GetBytes(3.14f, buffer, 7); + ConverterUtility.GetBytes(true, buffer, 0); + ConverterUtility.GetBytes((short)1234, buffer, 1); + ConverterUtility.GetBytes(56789, buffer, 3); + ConverterUtility.GetBytes(3.14f, buffer, 7); - Assert.IsTrue(Utility.Converter.GetBoolean(buffer, 0)); - Assert.AreEqual((short)1234, Utility.Converter.GetInt16(buffer, 1)); - Assert.AreEqual(56789, Utility.Converter.GetInt32(buffer, 3)); - Assert.AreEqual(3.14f, Utility.Converter.GetSingle(buffer, 7), 0.001f); + Assert.IsTrue(ConverterUtility.GetBoolean(buffer, 0)); + Assert.AreEqual((short)1234, ConverterUtility.GetInt16(buffer, 1)); + Assert.AreEqual(56789, ConverterUtility.GetInt32(buffer, 3)); + Assert.AreEqual(3.14f, ConverterUtility.GetSingle(buffer, 7), 0.001f); } #endregion diff --git a/Tests/UtilityDirectoryTests.cs b/Tests/UtilityDirectoryTests.cs new file mode 100644 index 0000000..fe3251c --- /dev/null +++ b/Tests/UtilityDirectoryTests.cs @@ -0,0 +1,126 @@ +using System.IO; +using GameFrameX.Runtime; +using NUnit.Framework; + +namespace GameFrameX.Tests +{ + [TestFixture] + public class UtilityDirectoryTests + { + #region RemoveEmptyDirectory + + [Test] + public void RemoveEmptyDirectory_NullInput_Throws() + { + Assert.Throws(() => + { + DirectoryUtility.RemoveEmptyDirectory(null); + }); + } + + [Test] + public void RemoveEmptyDirectory_EmptyString_Throws() + { + Assert.Throws(() => + { + DirectoryUtility.RemoveEmptyDirectory(""); + }); + } + + [Test] + public void RemoveEmptyDirectory_NonExistentPath_ReturnsFalse() + { + string nonExistent = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_NonExistent_" + System.Guid.NewGuid()); + bool result = DirectoryUtility.RemoveEmptyDirectory(nonExistent); + Assert.IsFalse(result); + } + + [Test] + public void RemoveEmptyDirectory_EmptyDir_RemovesAndReturnsTrue() + { + string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_Empty_" + System.Guid.NewGuid()); + try + { + Directory.CreateDirectory(tempDir); + Assert.IsTrue(Directory.Exists(tempDir)); + bool result = DirectoryUtility.RemoveEmptyDirectory(tempDir); + Assert.IsTrue(result); + Assert.IsFalse(Directory.Exists(tempDir)); + } + finally + { + if (Directory.Exists(tempDir)) + { + Directory.Delete(tempDir, true); + } + } + } + + [Test] + public void RemoveEmptyDirectory_DirWithFiles_ReturnsFalse() + { + string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_WithFiles_" + System.Guid.NewGuid()); + try + { + Directory.CreateDirectory(tempDir); + File.WriteAllText(Path.Combine(tempDir, "test.txt"), "data"); + bool result = DirectoryUtility.RemoveEmptyDirectory(tempDir); + Assert.IsFalse(result); + Assert.IsTrue(Directory.Exists(tempDir)); + } + finally + { + if (Directory.Exists(tempDir)) + { + Directory.Delete(tempDir, true); + } + } + } + + [Test] + public void RemoveEmptyDirectory_DirWithEmptySubDir_RemovesBoth() + { + string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_Nested_" + System.Guid.NewGuid()); + try + { + Directory.CreateDirectory(tempDir); + string subDir = Path.Combine(tempDir, "empty_sub"); + Directory.CreateDirectory(subDir); + bool result = DirectoryUtility.RemoveEmptyDirectory(tempDir); + Assert.IsTrue(result); + Assert.IsFalse(Directory.Exists(tempDir)); + } + finally + { + if (Directory.Exists(tempDir)) + { + Directory.Delete(tempDir, true); + } + } + } + + [Test] + public void RemoveEmptyDirectory_DirWithNonEmptySubDir_ReturnsFalse() + { + string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_NestedFiles_" + System.Guid.NewGuid()); + try + { + Directory.CreateDirectory(tempDir); + string subDir = Path.Combine(tempDir, "nonempty_sub"); + Directory.CreateDirectory(subDir); + File.WriteAllText(Path.Combine(subDir, "file.txt"), "data"); + bool result = DirectoryUtility.RemoveEmptyDirectory(tempDir); + Assert.IsFalse(result); + } + finally + { + if (Directory.Exists(tempDir)) + { + Directory.Delete(tempDir, true); + } + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Tests/UtilityDirectoryTests.cs.meta b/Tests/UtilityDirectoryTests.cs.meta new file mode 100644 index 0000000..3c84883 --- /dev/null +++ b/Tests/UtilityDirectoryTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ffb17e78a4af448588e9bd33c1151071 +timeCreated: 1786544876 \ No newline at end of file diff --git a/Tests/UtilityEncryptionAesTests.cs b/Tests/UtilityEncryptionAesTests.cs index 33ae3d5..917dad7 100644 --- a/Tests/UtilityEncryptionAesTests.cs +++ b/Tests/UtilityEncryptionAesTests.cs @@ -18,16 +18,16 @@ public class UtilityEncryptionAesTests [Test] public void AESEncryptSecure_DecryptSecure_String_RoundTrip() { - string encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + string encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintext, TestKey); + string decrypted = EncryptionUtility.Aes.AESDecryptSecure(encrypted, TestKey); Assert.AreEqual(TestPlaintext, decrypted); } [Test] public void AESEncryptSecure_DecryptSecure_Bytes_RoundTrip() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); - byte[] decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] decrypted = EncryptionUtility.Aes.AESDecryptSecure(encrypted, TestKey); CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); } @@ -39,8 +39,8 @@ public void AESEncryptSecure_DecryptSecure_Bytes_RoundTrip() public void AESEncrypt_Decrypt_String_RoundTrip() { #pragma warning disable CS0618 - string encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintext, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + string encrypted = EncryptionUtility.Aes.AESEncrypt(TestPlaintext, TestKey); + string decrypted = EncryptionUtility.Aes.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 Assert.AreEqual(TestPlaintext, decrypted); } @@ -49,8 +49,8 @@ public void AESEncrypt_Decrypt_String_RoundTrip() public void AESEncrypt_Decrypt_Bytes_RoundTrip() { #pragma warning disable CS0618 - byte[] encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); - byte[] decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] decrypted = EncryptionUtility.Aes.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); } @@ -62,16 +62,16 @@ public void AESEncrypt_Decrypt_Bytes_RoundTrip() [Test] public void AESEncryptSecure_SamePlaintext_ProducesDifferentCiphertext() { - string encrypted1 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); - string encrypted2 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintext, TestKey); + string encrypted1 = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintext, TestKey); + string encrypted2 = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintext, TestKey); Assert.AreNotEqual(encrypted1, encrypted2); } [Test] public void AESEncryptSecure_Bytes_SamePlaintext_ProducesDifferentCiphertext() { - byte[] encrypted1 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); - byte[] encrypted2 = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted1 = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted2 = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); Assert.AreEqual(encrypted1.Length, encrypted2.Length); bool allSame = true; for (int i = 0; i < encrypted1.Length; i++) @@ -92,7 +92,7 @@ public void AESEncryptSecure_Bytes_SamePlaintext_ProducesDifferentCiphertext() [Test] public void AESEncryptSecure_CiphertextFormat_ContainsIVAndSalt() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); Assert.Greater(encrypted.Length, 32 + TestPlaintextBytes.Length); } @@ -105,7 +105,7 @@ public void AESEncryptSecure_NullBytes_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESEncryptSecure((byte[])null, TestKey); + EncryptionUtility.Aes.AESEncryptSecure((byte[])null, TestKey); }); } @@ -114,7 +114,7 @@ public void AESEncryptSecure_EmptyBytes_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESEncryptSecure(new byte[0], TestKey); + EncryptionUtility.Aes.AESEncryptSecure(new byte[0], TestKey); }); } @@ -123,7 +123,7 @@ public void AESEncryptSecure_NullKey_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, null); + EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, null); }); } @@ -132,7 +132,7 @@ public void AESEncryptSecure_EmptyKey_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, ""); + EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, ""); }); } @@ -141,7 +141,7 @@ public void AESDecryptSecure_NullBytes_Throws() { Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure((byte[])null, TestKey); + EncryptionUtility.Aes.AESDecryptSecure((byte[])null, TestKey); }); } @@ -151,27 +151,27 @@ public void AESDecryptSecure_TooShort_Throws() byte[] shortData = new byte[32]; Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure(shortData, TestKey); + EncryptionUtility.Aes.AESDecryptSecure(shortData, TestKey); }); } [Test] public void AESDecryptSecure_EmptyKey_Throws() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure(encrypted, ""); + EncryptionUtility.Aes.AESDecryptSecure(encrypted, ""); }); } [Test] public void AESDecryptSecure_WrongKey_Throws() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); Assert.Throws(() => { - Utility.Encryption.Aes.AESDecryptSecure(encrypted, "WrongKey1234567890"); + EncryptionUtility.Aes.AESDecryptSecure(encrypted, "WrongKey1234567890"); }); } @@ -183,18 +183,18 @@ public void AESDecryptSecure_WrongKey_Throws() public void AESEncrypt_ProducesDataDecryptableBy_AESDecryptSecure() { #pragma warning disable CS0618 - byte[] encrypted = Utility.Encryption.Aes.AESEncrypt(TestPlaintextBytes, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncrypt(TestPlaintextBytes, TestKey); #pragma warning restore CS0618 - byte[] decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + byte[] decrypted = EncryptionUtility.Aes.AESDecryptSecure(encrypted, TestKey); CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); } [Test] public void AESEncryptSecure_ProducesDataDecryptableBy_AESDecrypt() { - byte[] encrypted = Utility.Encryption.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); + byte[] encrypted = EncryptionUtility.Aes.AESEncryptSecure(TestPlaintextBytes, TestKey); #pragma warning disable CS0618 - byte[] decrypted = Utility.Encryption.Aes.AESDecrypt(encrypted, TestKey); + byte[] decrypted = EncryptionUtility.Aes.AESDecrypt(encrypted, TestKey); #pragma warning restore CS0618 CollectionAssert.AreEqual(TestPlaintextBytes, decrypted); } @@ -207,8 +207,8 @@ public void AESEncryptSecure_ProducesDataDecryptableBy_AESDecrypt() public void AESEncryptSecure_DecryptSecure_Unicode_RoundTrip() { string unicode = "你好世界 🎮"; - string encrypted = Utility.Encryption.Aes.AESEncryptSecure(unicode, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + string encrypted = EncryptionUtility.Aes.AESEncryptSecure(unicode, TestKey); + string decrypted = EncryptionUtility.Aes.AESDecryptSecure(encrypted, TestKey); Assert.AreEqual(unicode, decrypted); } @@ -222,12 +222,12 @@ public void AESEncryptSecure_MultipleRoundTrips() for (int i = 0; i < 10; i++) { string plaintext = "Round trip test " + i; - string encrypted = Utility.Encryption.Aes.AESEncryptSecure(plaintext, TestKey); - string decrypted = Utility.Encryption.Aes.AESDecryptSecure(encrypted, TestKey); + string encrypted = EncryptionUtility.Aes.AESEncryptSecure(plaintext, TestKey); + string decrypted = EncryptionUtility.Aes.AESDecryptSecure(encrypted, TestKey); Assert.AreEqual(plaintext, decrypted, $"Failed at iteration {i}"); } } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityEncryptionRsaTests.cs b/Tests/UtilityEncryptionRsaTests.cs index e2a665d..b415ab5 100644 --- a/Tests/UtilityEncryptionRsaTests.cs +++ b/Tests/UtilityEncryptionRsaTests.cs @@ -16,7 +16,7 @@ public class UtilityEncryptionRsaTests [SetUp] public void SetUp() { - _keys = Utility.Encryption.Rsa.Make(); + _keys = EncryptionUtility.Rsa.Make(); _publicKey = _keys["publicKey"]; _privateKey = _keys["privateKey"]; } @@ -49,8 +49,8 @@ public void Make_PrivateKeyContainsPublicData() public void RSAEncrypt_RSADecrypt_String_RoundTrip() { string plaintext = "Hello RSA!"; - string encrypted = Utility.Encryption.Rsa.RSAEncrypt(_publicKey, plaintext); - string decrypted = Utility.Encryption.Rsa.RSADecrypt(_privateKey, encrypted); + string encrypted = EncryptionUtility.Rsa.RSAEncrypt(_publicKey, plaintext); + string decrypted = EncryptionUtility.Rsa.RSADecrypt(_privateKey, encrypted); Assert.AreEqual(plaintext, decrypted); } @@ -58,8 +58,8 @@ public void RSAEncrypt_RSADecrypt_String_RoundTrip() public void RSAEncrypt_RSADecrypt_Bytes_RoundTrip() { byte[] data = Encoding.UTF8.GetBytes("Byte data test"); - byte[] encrypted = Utility.Encryption.Rsa.RSAEncrypt(_publicKey, data); - byte[] decrypted = Utility.Encryption.Rsa.RSADecrypt(_privateKey, encrypted); + byte[] encrypted = EncryptionUtility.Rsa.RSAEncrypt(_publicKey, data); + byte[] decrypted = EncryptionUtility.Rsa.RSADecrypt(_privateKey, encrypted); CollectionAssert.AreEqual(data, decrypted); } @@ -73,7 +73,7 @@ public void Instance_Encrypt_Decrypt_String_RoundTrip() using (var rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(_privateKey); - var rsaInstance = new Utility.Encryption.Rsa(rsa); + var rsaInstance = new EncryptionUtility.Rsa(rsa); string plaintext = "Instance test"; string encrypted = rsaInstance.Encrypt(plaintext); @@ -88,7 +88,7 @@ public void Instance_Encrypt_Decrypt_Bytes_RoundTrip() using (var rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(_privateKey); - var rsaInstance = new Utility.Encryption.Rsa(rsa); + var rsaInstance = new EncryptionUtility.Rsa(rsa); byte[] data = Encoding.UTF8.GetBytes("Instance bytes"); byte[] encrypted = rsaInstance.Encrypt(data); @@ -104,7 +104,7 @@ public void Instance_Encrypt_Decrypt_Bytes_RoundTrip() [Test] public void Instance_CreateWithKeyString_RoundTrip() { - var rsaInstance = new Utility.Encryption.Rsa(_privateKey); + var rsaInstance = new EncryptionUtility.Rsa(_privateKey); string plaintext = "Key string test"; string encrypted = rsaInstance.Encrypt(plaintext); string decrypted = rsaInstance.Decrypt(encrypted); @@ -119,11 +119,11 @@ public void Instance_CreateWithKeyString_RoundTrip() public void RSASignData_RSAVerifyData_Bytes_RoundTrip() { byte[] data = Encoding.UTF8.GetBytes("Sign this data"); - byte[] signature = Utility.Encryption.Rsa.RSASignData(data, _privateKey); + byte[] signature = EncryptionUtility.Rsa.RSASignData(data, _privateKey); Assert.IsNotNull(signature); Assert.Greater(signature.Length, 0); - bool verified = Utility.Encryption.Rsa.RSAVerifyData(data, signature, _publicKey); + bool verified = EncryptionUtility.Rsa.RSAVerifyData(data, signature, _publicKey); Assert.IsTrue(verified); } @@ -131,10 +131,10 @@ public void RSASignData_RSAVerifyData_Bytes_RoundTrip() public void RSASignData_RSAVerifyData_String_RoundTrip() { string data = "String to sign"; - string signature = Utility.Encryption.Rsa.RSASignData(data, _privateKey); + string signature = EncryptionUtility.Rsa.RSASignData(data, _privateKey); Assert.IsNotNull(signature); - bool verified = Utility.Encryption.Rsa.RSAVerifyData(data, signature, _publicKey); + bool verified = EncryptionUtility.Rsa.RSAVerifyData(data, signature, _publicKey); Assert.IsTrue(verified); } @@ -144,7 +144,7 @@ public void Instance_SignData_VerifyData_RoundTrip() using (var rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(_privateKey); - var rsaInstance = new Utility.Encryption.Rsa(rsa); + var rsaInstance = new EncryptionUtility.Rsa(rsa); byte[] data = Encoding.UTF8.GetBytes("Instance sign"); byte[] signature = rsaInstance.SignData(data); @@ -159,7 +159,7 @@ public void Instance_SignData_VerifyData_String_RoundTrip() using (var rsa = new RSACryptoServiceProvider()) { rsa.FromXmlString(_privateKey); - var rsaInstance = new Utility.Encryption.Rsa(rsa); + var rsaInstance = new EncryptionUtility.Rsa(rsa); string data = "Instance string sign"; string signature = rsaInstance.SignData(data); @@ -172,9 +172,9 @@ public void Instance_SignData_VerifyData_String_RoundTrip() public void RSAVerifyData_WrongData_ReturnsFalse() { byte[] data = Encoding.UTF8.GetBytes("Original data"); - byte[] signature = Utility.Encryption.Rsa.RSASignData(data, _privateKey); + byte[] signature = EncryptionUtility.Rsa.RSASignData(data, _privateKey); byte[] wrongData = Encoding.UTF8.GetBytes("Wrong data"); - bool verified = Utility.Encryption.Rsa.RSAVerifyData(wrongData, signature, _publicKey); + bool verified = EncryptionUtility.Rsa.RSAVerifyData(wrongData, signature, _publicKey); Assert.IsFalse(verified); } @@ -182,9 +182,9 @@ public void RSAVerifyData_WrongData_ReturnsFalse() public void RSAVerifyData_WrongSignature_ReturnsFalse() { byte[] data = Encoding.UTF8.GetBytes("Original data"); - byte[] signature = Utility.Encryption.Rsa.RSASignData(data, _privateKey); + byte[] signature = EncryptionUtility.Rsa.RSASignData(data, _privateKey); signature[0] = (byte)(signature[0] ^ 0xFF); - bool verified = Utility.Encryption.Rsa.RSAVerifyData(data, signature, _publicKey); + bool verified = EncryptionUtility.Rsa.RSAVerifyData(data, signature, _publicKey); Assert.IsFalse(verified); } @@ -198,7 +198,7 @@ public void RSASignData_InvalidKey_Throws() byte[] data = Encoding.UTF8.GetBytes("test"); Assert.Throws(() => { - Utility.Encryption.Rsa.RSASignData(data, "invalid key"); + EncryptionUtility.Rsa.RSASignData(data, "invalid key"); }); } @@ -209,7 +209,7 @@ public void RSAVerifyData_InvalidKey_Throws() byte[] sig = new byte[128]; Assert.Throws(() => { - Utility.Encryption.Rsa.RSAVerifyData(data, sig, "invalid key"); + EncryptionUtility.Rsa.RSAVerifyData(data, sig, "invalid key"); }); } @@ -221,11 +221,11 @@ public void RSAVerifyData_InvalidKey_Throws() public void RSAEncrypt_RSADecrypt_Unicode_RoundTrip() { string plaintext = "你好世界 🌍"; - string encrypted = Utility.Encryption.Rsa.RSAEncrypt(_publicKey, plaintext); - string decrypted = Utility.Encryption.Rsa.RSADecrypt(_privateKey, encrypted); + string encrypted = EncryptionUtility.Rsa.RSAEncrypt(_publicKey, plaintext); + string decrypted = EncryptionUtility.Rsa.RSADecrypt(_privateKey, encrypted); Assert.AreEqual(plaintext, decrypted); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityHashHMACSha256Tests.cs b/Tests/UtilityHashHmacSha256Tests.cs similarity index 65% rename from Tests/UtilityHashHMACSha256Tests.cs rename to Tests/UtilityHashHmacSha256Tests.cs index af456f4..18c5909 100644 --- a/Tests/UtilityHashHMACSha256Tests.cs +++ b/Tests/UtilityHashHmacSha256Tests.cs @@ -4,38 +4,38 @@ namespace GameFrameX.Tests { [TestFixture] - public class UtilityHashHMACSha256Tests + public class UtilityHashHmacSha256Tests { #region Hash basic [Test] public void Hash_SameInput_SameOutput() { - string result1 = Utility.Hash.HMACSha256.Hash("message", "key"); - string result2 = Utility.Hash.HMACSha256.Hash("message", "key"); + string result1 = HashUtility.HmacSha256.Hash("message", "key"); + string result2 = HashUtility.HmacSha256.Hash("message", "key"); Assert.AreEqual(result1, result2); } [Test] public void Hash_DifferentMessage_DifferentOutput() { - string result1 = Utility.Hash.HMACSha256.Hash("message1", "key"); - string result2 = Utility.Hash.HMACSha256.Hash("message2", "key"); + string result1 = HashUtility.HmacSha256.Hash("message1", "key"); + string result2 = HashUtility.HmacSha256.Hash("message2", "key"); Assert.AreNotEqual(result1, result2); } [Test] public void Hash_DifferentKey_DifferentOutput() { - string result1 = Utility.Hash.HMACSha256.Hash("message", "key1"); - string result2 = Utility.Hash.HMACSha256.Hash("message", "key2"); + string result1 = HashUtility.HmacSha256.Hash("message", "key1"); + string result2 = HashUtility.HmacSha256.Hash("message", "key2"); Assert.AreNotEqual(result1, result2); } [Test] public void Hash_ReturnsBase64String() { - string result = Utility.Hash.HMACSha256.Hash("message", "key"); + string result = HashUtility.HmacSha256.Hash("message", "key"); Assert.IsNotNull(result); Assert.Greater(result.Length, 0); byte[] decoded = System.Convert.FromBase64String(result); @@ -45,7 +45,7 @@ public void Hash_ReturnsBase64String() [Test] public void Hash_EmptyMessage() { - string result = Utility.Hash.HMACSha256.Hash("", "key"); + string result = HashUtility.HmacSha256.Hash("", "key"); Assert.IsNotNull(result); Assert.Greater(result.Length, 0); } @@ -53,7 +53,7 @@ public void Hash_EmptyMessage() [Test] public void Hash_EmptyKey() { - string result = Utility.Hash.HMACSha256.Hash("message", ""); + string result = HashUtility.HmacSha256.Hash("message", ""); Assert.IsNotNull(result); Assert.Greater(result.Length, 0); } @@ -61,7 +61,7 @@ public void Hash_EmptyKey() [Test] public void Hash_UnicodeInput() { - string result = Utility.Hash.HMACSha256.Hash("你好", "密钥"); + string result = HashUtility.HmacSha256.Hash("你好", "密钥"); Assert.IsNotNull(result); Assert.Greater(result.Length, 0); } @@ -71,18 +71,18 @@ public void Hash_LongInput() { string longMessage = new string('a', 10000); string longKey = new string('k', 1000); - string result = Utility.Hash.HMACSha256.Hash(longMessage, longKey); + string result = HashUtility.HmacSha256.Hash(longMessage, longKey); Assert.IsNotNull(result); } [Test] public void Hash_KnownVector() { - string result = Utility.Hash.HMACSha256.Hash("Hi There", "key"); + string result = HashUtility.HmacSha256.Hash("Hi There", "key"); Assert.IsNotNull(result); Assert.AreEqual(44, result.Length, "Base64 of 32 bytes should be 44 chars"); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityHashHMACSha256Tests.cs.meta b/Tests/UtilityHashHmacSha256Tests.cs.meta similarity index 100% rename from Tests/UtilityHashHMACSha256Tests.cs.meta rename to Tests/UtilityHashHmacSha256Tests.cs.meta diff --git a/Tests/UtilityHashMd5Tests.cs b/Tests/UtilityHashMd5Tests.cs index 4e5c217..c4574f2 100644 --- a/Tests/UtilityHashMd5Tests.cs +++ b/Tests/UtilityHashMd5Tests.cs @@ -13,28 +13,28 @@ public class UtilityHashMd5Tests [Test] public void Hash_KnownInput_ReturnsExpectedMd5() { - string result = Utility.Hash.MD5.Hash(""); + string result = HashUtility.Md5.Hash(""); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", result); } [Test] public void Hash_HelloWorld_ReturnsExpectedMd5() { - string result = Utility.Hash.MD5.Hash("Hello World"); + string result = HashUtility.Md5.Hash("Hello World"); Assert.AreEqual("b10a8db164e0754105b7a99be72e3fe5", result); } [Test] public void Hash_LowercaseAlphabet() { - string result = Utility.Hash.MD5.Hash("abcdefghijklmnopqrstuvwxyz"); + string result = HashUtility.Md5.Hash("abcdefghijklmnopqrstuvwxyz"); Assert.AreEqual("c3fcd3d76192e4007dfb496cca67e13b", result); } [Test] public void Hash_NumericString() { - string result = Utility.Hash.MD5.Hash("1234567890"); + string result = HashUtility.Md5.Hash("1234567890"); Assert.AreEqual("e807f1fcf82d132f9bb018ca6738a19f", result); } @@ -42,23 +42,23 @@ public void Hash_NumericString() public void Hash_SameInput_SameOutput() { string input = "consistency check"; - string hash1 = Utility.Hash.MD5.Hash(input); - string hash2 = Utility.Hash.MD5.Hash(input); + string hash1 = HashUtility.Md5.Hash(input); + string hash2 = HashUtility.Md5.Hash(input); Assert.AreEqual(hash1, hash2); } [Test] public void Hash_DifferentInput_DifferentOutput() { - string hash1 = Utility.Hash.MD5.Hash("input1"); - string hash2 = Utility.Hash.MD5.Hash("input2"); + string hash1 = HashUtility.Md5.Hash("input1"); + string hash2 = HashUtility.Md5.Hash("input2"); Assert.AreNotEqual(hash1, hash2); } [Test] public void Hash_Returns32CharHexString() { - string result = Utility.Hash.MD5.Hash("test"); + string result = HashUtility.Md5.Hash("test"); Assert.AreEqual(32, result.Length); foreach (char c in result) { @@ -71,7 +71,7 @@ public void Hash_Returns32CharHexString() [Test] public void Hash_UnicodeInput() { - string result = Utility.Hash.MD5.Hash("你好"); + string result = HashUtility.Md5.Hash("你好"); Assert.AreEqual(32, result.Length); Assert.IsNotNull(result); } @@ -84,7 +84,7 @@ public void Hash_LongInput() { sb.Append("a"); } - string result = Utility.Hash.MD5.Hash(sb.ToString()); + string result = HashUtility.Md5.Hash(sb.ToString()); Assert.AreEqual(32, result.Length); } @@ -98,7 +98,7 @@ public void Hash_Stream_ReturnsExpectedMd5() byte[] data = Encoding.UTF8.GetBytes("Hello World"); using (MemoryStream stream = new MemoryStream(data)) { - string result = Utility.Hash.MD5.Hash(stream); + string result = HashUtility.Md5.Hash(stream); Assert.AreEqual("b10a8db164e0754105b7a99be72e3fe5", result); } } @@ -108,7 +108,7 @@ public void Hash_EmptyStream() { using (MemoryStream stream = new MemoryStream()) { - string result = Utility.Hash.MD5.Hash(stream); + string result = HashUtility.Md5.Hash(stream); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", result); } } @@ -120,24 +120,24 @@ public void Hash_EmptyStream() [Test] public void IsVerify_SameHash_ReturnsTrue() { - string hash = Utility.Hash.MD5.Hash("test"); - Assert.IsTrue(Utility.Hash.MD5.IsVerify(hash, hash)); + string hash = HashUtility.Md5.Hash("test"); + Assert.IsTrue(HashUtility.Md5.IsVerify(hash, hash)); } [Test] public void IsVerify_DifferentHash_ReturnsFalse() { - string hash1 = Utility.Hash.MD5.Hash("test1"); - string hash2 = Utility.Hash.MD5.Hash("test2"); - Assert.IsFalse(Utility.Hash.MD5.IsVerify(hash1, hash2)); + string hash1 = HashUtility.Md5.Hash("test1"); + string hash2 = HashUtility.Md5.Hash("test2"); + Assert.IsFalse(HashUtility.Md5.IsVerify(hash1, hash2)); } [Test] public void IsVerify_CaseInsensitive() { - string hash1 = Utility.Hash.MD5.Hash("test"); + string hash1 = HashUtility.Md5.Hash("test"); string hash2 = hash1.ToUpper(); - Assert.IsTrue(Utility.Hash.MD5.IsVerify(hash1, hash2)); + Assert.IsTrue(HashUtility.Md5.IsVerify(hash1, hash2)); } #endregion @@ -151,7 +151,7 @@ public void FileHash_KnownFile_ReturnsExpectedMd5() try { File.WriteAllText(tempFile, "Hello World"); - string result = Utility.Hash.MD5.FileHash(tempFile); + string result = HashUtility.Md5.FileHash(tempFile); Assert.AreEqual("b10a8db164e0754105b7a99be72e3fe5", result); } finally @@ -162,4 +162,4 @@ public void FileHash_KnownFile_ReturnsExpectedMd5() #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityHashMurmurHash3Tests.cs b/Tests/UtilityHashMurmurHash3Tests.cs index f97df68..36278ab 100644 --- a/Tests/UtilityHashMurmurHash3Tests.cs +++ b/Tests/UtilityHashMurmurHash3Tests.cs @@ -11,54 +11,54 @@ public class UtilityHashMurmurHash3Tests [Test] public void Hash_SameInput_SameOutput() { - uint hash1 = Utility.Hash.MurmurHash3.Hash("test"); - uint hash2 = Utility.Hash.MurmurHash3.Hash("test"); + uint hash1 = HashUtility.MurmurHash3.Hash("test"); + uint hash2 = HashUtility.MurmurHash3.Hash("test"); Assert.AreEqual(hash1, hash2); } [Test] public void Hash_DifferentInput_DifferentOutput() { - uint hash1 = Utility.Hash.MurmurHash3.Hash("input1"); - uint hash2 = Utility.Hash.MurmurHash3.Hash("input2"); + uint hash1 = HashUtility.MurmurHash3.Hash("input1"); + uint hash2 = HashUtility.MurmurHash3.Hash("input2"); Assert.AreNotEqual(hash1, hash2); } [Test] public void Hash_EmptyString() { - uint result = Utility.Hash.MurmurHash3.Hash(""); + uint result = HashUtility.MurmurHash3.Hash(""); Assert.AreNotEqual(0u, result); } [Test] public void Hash_SingleChar() { - uint result = Utility.Hash.MurmurHash3.Hash("a"); + uint result = HashUtility.MurmurHash3.Hash("a"); Assert.AreNotEqual(0u, result); } [Test] public void Hash_DefaultSeed_Seed27() { - uint hash1 = Utility.Hash.MurmurHash3.Hash("test", 27); - uint hash2 = Utility.Hash.MurmurHash3.Hash("test"); + uint hash1 = HashUtility.MurmurHash3.Hash("test", 27); + uint hash2 = HashUtility.MurmurHash3.Hash("test"); Assert.AreEqual(hash1, hash2); } [Test] public void Hash_DifferentSeed_DifferentResult() { - uint hash1 = Utility.Hash.MurmurHash3.Hash("test", 0); - uint hash2 = Utility.Hash.MurmurHash3.Hash("test", 1); + uint hash1 = HashUtility.MurmurHash3.Hash("test", 0); + uint hash2 = HashUtility.MurmurHash3.Hash("test", 1); Assert.AreNotEqual(hash1, hash2); } [Test] public void Hash_SameSeed_SameResult() { - uint hash1 = Utility.Hash.MurmurHash3.Hash("test", 42); - uint hash2 = Utility.Hash.MurmurHash3.Hash("test", 42); + uint hash1 = HashUtility.MurmurHash3.Hash("test", 42); + uint hash2 = HashUtility.MurmurHash3.Hash("test", 42); Assert.AreEqual(hash1, hash2); } @@ -68,7 +68,7 @@ public void Hash_MultipleLengths() for (int len = 0; len < 64; len++) { string input = new string('a', len); - uint result = Utility.Hash.MurmurHash3.Hash(input); + uint result = HashUtility.MurmurHash3.Hash(input); Assert.AreNotEqual(0u, result, $"Hash for length {len} should not be zero (but may be)"); } } @@ -77,8 +77,8 @@ public void Hash_MultipleLengths() public void Hash_4ByteAlignedInput() { string input = "abcd"; - uint hash1 = Utility.Hash.MurmurHash3.Hash(input); - uint hash2 = Utility.Hash.MurmurHash3.Hash(input); + uint hash1 = HashUtility.MurmurHash3.Hash(input); + uint hash2 = HashUtility.MurmurHash3.Hash(input); Assert.AreEqual(hash1, hash2); } @@ -86,15 +86,15 @@ public void Hash_4ByteAlignedInput() public void Hash_NonAlignedInput() { string input = "abcde"; - uint hash1 = Utility.Hash.MurmurHash3.Hash(input); - uint hash2 = Utility.Hash.MurmurHash3.Hash(input); + uint hash1 = HashUtility.MurmurHash3.Hash(input); + uint hash2 = HashUtility.MurmurHash3.Hash(input); Assert.AreEqual(hash1, hash2); } [Test] public void Hash_UnicodeInput() { - uint result = Utility.Hash.MurmurHash3.Hash("你好世界"); + uint result = HashUtility.MurmurHash3.Hash("你好世界"); Assert.AreNotEqual(0u, result); } @@ -102,24 +102,24 @@ public void Hash_UnicodeInput() public void Hash_LongInput() { string input = new string('z', 10000); - uint result = Utility.Hash.MurmurHash3.Hash(input); + uint result = HashUtility.MurmurHash3.Hash(input); Assert.AreNotEqual(0u, result); } [Test] public void Hash_SeedZero() { - uint result = Utility.Hash.MurmurHash3.Hash("test", 0); + uint result = HashUtility.MurmurHash3.Hash("test", 0); Assert.AreNotEqual(0u, result); } [Test] public void Hash_LargeSeed() { - uint result = Utility.Hash.MurmurHash3.Hash("test", uint.MaxValue); + uint result = HashUtility.MurmurHash3.Hash("test", uint.MaxValue); Assert.AreNotEqual(0u, result); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityHashSha1Tests.cs b/Tests/UtilityHashSha1Tests.cs index 052cd33..9359ae4 100644 --- a/Tests/UtilityHashSha1Tests.cs +++ b/Tests/UtilityHashSha1Tests.cs @@ -12,44 +12,44 @@ public class UtilityHashSha1Tests [Test] public void Hash_EmptyString_ReturnsExpectedSha1() { - string result = Utility.Hash.Sha1.Hash(""); + string result = HashUtility.Sha1.Hash(""); Assert.AreEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", result); } [Test] public void Hash_KnownInput_ReturnsExpectedSha1() { - string result = Utility.Hash.Sha1.Hash("Hello World"); + string result = HashUtility.Sha1.Hash("Hello World"); Assert.AreEqual("0a4d55a8d778e5022fab701977c5d840bbc486d0", result); } [Test] public void Hash_AnotherKnownInput() { - string result = Utility.Hash.Sha1.Hash("abcdefghijklmnopqrstuvwxyz"); + string result = HashUtility.Sha1.Hash("abcdefghijklmnopqrstuvwxyz"); Assert.AreEqual("32d10c7b8cf96570ca04ce37f2a19d84240d3a89", result); } [Test] public void Hash_SameInput_SameOutput() { - string hash1 = Utility.Hash.Sha1.Hash("deterministic"); - string hash2 = Utility.Hash.Sha1.Hash("deterministic"); + string hash1 = HashUtility.Sha1.Hash("deterministic"); + string hash2 = HashUtility.Sha1.Hash("deterministic"); Assert.AreEqual(hash1, hash2); } [Test] public void Hash_DifferentInput_DifferentOutput() { - string hash1 = Utility.Hash.Sha1.Hash("foo"); - string hash2 = Utility.Hash.Sha1.Hash("bar"); + string hash1 = HashUtility.Sha1.Hash("foo"); + string hash2 = HashUtility.Sha1.Hash("bar"); Assert.AreNotEqual(hash1, hash2); } [Test] public void Hash_Returns40CharHexString() { - string result = Utility.Hash.Sha1.Hash("test"); + string result = HashUtility.Sha1.Hash("test"); Assert.AreEqual(40, result.Length); foreach (char c in result) { @@ -62,7 +62,7 @@ public void Hash_Returns40CharHexString() [Test] public void Hash_UnicodeInput() { - string result = Utility.Hash.Sha1.Hash("中文"); + string result = HashUtility.Sha1.Hash("中文"); Assert.AreEqual(40, result.Length); } @@ -74,7 +74,7 @@ public void Hash_LongInput() { sb.Append("x"); } - string result = Utility.Hash.Sha1.Hash(sb.ToString()); + string result = HashUtility.Sha1.Hash(sb.ToString()); Assert.AreEqual(40, result.Length); } @@ -85,8 +85,8 @@ public void Hash_LongInput() [Test] public void Hash_WithUnicodeEncoding() { - string utf8Hash = Utility.Hash.Sha1.Hash("test", Encoding.UTF8); - string unicodeHash = Utility.Hash.Sha1.Hash("test", Encoding.Unicode); + string utf8Hash = HashUtility.Sha1.Hash("test", Encoding.UTF8); + string unicodeHash = HashUtility.Sha1.Hash("test", Encoding.Unicode); Assert.AreEqual(40, utf8Hash.Length); Assert.AreEqual(40, unicodeHash.Length); Assert.AreNotEqual(utf8Hash, unicodeHash); @@ -96,11 +96,11 @@ public void Hash_WithUnicodeEncoding() public void Hash_WithASCII_SameAsUTF8ForASCII() { string input = "ASCII only"; - string utf8Result = Utility.Hash.Sha1.Hash(input, Encoding.UTF8); - string asciiResult = Utility.Hash.Sha1.Hash(input, Encoding.ASCII); + string utf8Result = HashUtility.Sha1.Hash(input, Encoding.UTF8); + string asciiResult = HashUtility.Sha1.Hash(input, Encoding.ASCII); Assert.AreEqual(utf8Result, asciiResult); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityHashXxHashTests.cs b/Tests/UtilityHashXxHashTests.cs index f94f9a3..fa24e1c 100644 --- a/Tests/UtilityHashXxHashTests.cs +++ b/Tests/UtilityHashXxHashTests.cs @@ -12,7 +12,7 @@ public class UtilityHashXxHashTests [Test] public void Hash32_EmptyArray() { - uint result = Utility.Hash.XXHash.Hash32(new byte[0]); + uint result = HashUtility.XxHash.Hash32(new byte[0]); Assert.AreNotEqual(0u, result); } @@ -20,8 +20,8 @@ public void Hash32_EmptyArray() public void Hash32_SameInput_SameOutput() { byte[] data = new byte[] { 1, 2, 3, 4, 5 }; - uint hash1 = Utility.Hash.XXHash.Hash32(data); - uint hash2 = Utility.Hash.XXHash.Hash32(data); + uint hash1 = HashUtility.XxHash.Hash32(data); + uint hash2 = HashUtility.XxHash.Hash32(data); Assert.AreEqual(hash1, hash2); } @@ -30,8 +30,8 @@ public void Hash32_DifferentInput_DifferentOutput() { byte[] data1 = new byte[] { 1, 2, 3 }; byte[] data2 = new byte[] { 4, 5, 6 }; - uint hash1 = Utility.Hash.XXHash.Hash32(data1); - uint hash2 = Utility.Hash.XXHash.Hash32(data2); + uint hash1 = HashUtility.XxHash.Hash32(data1); + uint hash2 = HashUtility.XxHash.Hash32(data2); Assert.AreNotEqual(hash1, hash2); } @@ -40,7 +40,7 @@ public void Hash32_LargeInput() { byte[] data = new byte[10000]; new Random().NextBytes(data); - uint result = Utility.Hash.XXHash.Hash32(data); + uint result = HashUtility.XxHash.Hash32(data); Assert.AreNotEqual(0u, result); } @@ -51,30 +51,30 @@ public void Hash32_LargeInput() [Test] public void Hash32_EmptyString() { - uint result = Utility.Hash.XXHash.Hash32(""); + uint result = HashUtility.XxHash.Hash32(""); Assert.AreNotEqual(0u, result); } [Test] public void Hash32_SameString_SameOutput() { - uint hash1 = Utility.Hash.XXHash.Hash32("test"); - uint hash2 = Utility.Hash.XXHash.Hash32("test"); + uint hash1 = HashUtility.XxHash.Hash32("test"); + uint hash2 = HashUtility.XxHash.Hash32("test"); Assert.AreEqual(hash1, hash2); } [Test] public void Hash32_DifferentString_DifferentOutput() { - uint hash1 = Utility.Hash.XXHash.Hash32("foo"); - uint hash2 = Utility.Hash.XXHash.Hash32("bar"); + uint hash1 = HashUtility.XxHash.Hash32("foo"); + uint hash2 = HashUtility.XxHash.Hash32("bar"); Assert.AreNotEqual(hash1, hash2); } [Test] public void Hash32_UnicodeString() { - uint result = Utility.Hash.XXHash.Hash32("中文测试"); + uint result = HashUtility.XxHash.Hash32("中文测试"); Assert.AreNotEqual(0u, result); } @@ -85,16 +85,16 @@ public void Hash32_UnicodeString() [Test] public void Hash32_Type_SameType_SameOutput() { - uint hash1 = Utility.Hash.XXHash.Hash32(typeof(string)); - uint hash2 = Utility.Hash.XXHash.Hash32(typeof(string)); + uint hash1 = HashUtility.XxHash.Hash32(typeof(string)); + uint hash2 = HashUtility.XxHash.Hash32(typeof(string)); Assert.AreEqual(hash1, hash2); } [Test] public void Hash32_Type_DifferentType_DifferentOutput() { - uint hash1 = Utility.Hash.XXHash.Hash32(typeof(string)); - uint hash2 = Utility.Hash.XXHash.Hash32(typeof(int)); + uint hash1 = HashUtility.XxHash.Hash32(typeof(string)); + uint hash2 = HashUtility.XxHash.Hash32(typeof(int)); Assert.AreNotEqual(hash1, hash2); } @@ -105,16 +105,16 @@ public void Hash32_Type_DifferentType_DifferentOutput() [Test] public void Hash32_Generic_SameType_SameOutput() { - uint hash1 = Utility.Hash.XXHash.Hash32(); - uint hash2 = Utility.Hash.XXHash.Hash32(); + uint hash1 = HashUtility.XxHash.Hash32(); + uint hash2 = HashUtility.XxHash.Hash32(); Assert.AreEqual(hash1, hash2); } [Test] public void Hash32_Generic_MatchesTypeOverload() { - uint hash1 = Utility.Hash.XXHash.Hash32(typeof(int)); - uint hash2 = Utility.Hash.XXHash.Hash32(); + uint hash1 = HashUtility.XxHash.Hash32(typeof(int)); + uint hash2 = HashUtility.XxHash.Hash32(); Assert.AreEqual(hash1, hash2); } @@ -125,7 +125,7 @@ public void Hash32_Generic_MatchesTypeOverload() [Test] public void Hash64_EmptyArray() { - ulong result = Utility.Hash.XXHash.Hash64(new byte[0]); + ulong result = HashUtility.XxHash.Hash64(new byte[0]); Assert.AreNotEqual(0ul, result); } @@ -133,8 +133,8 @@ public void Hash64_EmptyArray() public void Hash64_SameInput_SameOutput() { byte[] data = new byte[] { 10, 20, 30 }; - ulong hash1 = Utility.Hash.XXHash.Hash64(data); - ulong hash2 = Utility.Hash.XXHash.Hash64(data); + ulong hash1 = HashUtility.XxHash.Hash64(data); + ulong hash2 = HashUtility.XxHash.Hash64(data); Assert.AreEqual(hash1, hash2); } @@ -143,8 +143,8 @@ public void Hash64_DifferentInput_DifferentOutput() { byte[] data1 = new byte[] { 1, 2, 3 }; byte[] data2 = new byte[] { 3, 2, 1 }; - ulong hash1 = Utility.Hash.XXHash.Hash64(data1); - ulong hash2 = Utility.Hash.XXHash.Hash64(data2); + ulong hash1 = HashUtility.XxHash.Hash64(data1); + ulong hash2 = HashUtility.XxHash.Hash64(data2); Assert.AreNotEqual(hash1, hash2); } @@ -153,7 +153,7 @@ public void Hash64_LargeInput() { byte[] data = new byte[10000]; new Random().NextBytes(data); - ulong result = Utility.Hash.XXHash.Hash64(data); + ulong result = HashUtility.XxHash.Hash64(data); Assert.AreNotEqual(0ul, result); } @@ -164,15 +164,15 @@ public void Hash64_LargeInput() [Test] public void Hash64_EmptyString() { - ulong result = Utility.Hash.XXHash.Hash64(""); + ulong result = HashUtility.XxHash.Hash64(""); Assert.AreNotEqual(0ul, result); } [Test] public void Hash64_SameString_SameOutput() { - ulong hash1 = Utility.Hash.XXHash.Hash64("test"); - ulong hash2 = Utility.Hash.XXHash.Hash64("test"); + ulong hash1 = HashUtility.XxHash.Hash64("test"); + ulong hash2 = HashUtility.XxHash.Hash64("test"); Assert.AreEqual(hash1, hash2); } @@ -183,8 +183,8 @@ public void Hash64_SameString_SameOutput() [Test] public void Hash64_Type_SameType_SameOutput() { - ulong hash1 = Utility.Hash.XXHash.Hash64(typeof(string)); - ulong hash2 = Utility.Hash.XXHash.Hash64(typeof(string)); + ulong hash1 = HashUtility.XxHash.Hash64(typeof(string)); + ulong hash2 = HashUtility.XxHash.Hash64(typeof(string)); Assert.AreEqual(hash1, hash2); } @@ -195,8 +195,8 @@ public void Hash64_Type_SameType_SameOutput() [Test] public void Hash64_Generic_MatchesTypeOverload() { - ulong hash1 = Utility.Hash.XXHash.Hash64(typeof(string)); - ulong hash2 = Utility.Hash.XXHash.Hash64(); + ulong hash1 = HashUtility.XxHash.Hash64(typeof(string)); + ulong hash2 = HashUtility.XxHash.Hash64(); Assert.AreEqual(hash1, hash2); } @@ -208,12 +208,12 @@ public void Hash64_Generic_MatchesTypeOverload() public void Hash32_And_Hash64_BothNonZero() { string input = "cross-check"; - uint h32 = Utility.Hash.XXHash.Hash32(input); - ulong h64 = Utility.Hash.XXHash.Hash64(input); + uint h32 = HashUtility.XxHash.Hash32(input); + ulong h64 = HashUtility.XxHash.Hash64(input); Assert.AreNotEqual(0u, h32); Assert.AreNotEqual(0ul, h64); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityIdGeneratorTests.cs b/Tests/UtilityIdGeneratorTests.cs index 80ea17a..49faf81 100644 --- a/Tests/UtilityIdGeneratorTests.cs +++ b/Tests/UtilityIdGeneratorTests.cs @@ -14,10 +14,10 @@ public class UtilityIdGeneratorTests [Test] public void UtcTimeStart_Is2020Jan1() { - Assert.AreEqual(2020, Utility.IdGenerator.UtcTimeStart.Year); - Assert.AreEqual(1, Utility.IdGenerator.UtcTimeStart.Month); - Assert.AreEqual(1, Utility.IdGenerator.UtcTimeStart.Day); - Assert.AreEqual(DateTimeKind.Utc, Utility.IdGenerator.UtcTimeStart.Kind); + Assert.AreEqual(2020, IdGeneratorUtility.UtcTimeStart.Year); + Assert.AreEqual(1, IdGeneratorUtility.UtcTimeStart.Month); + Assert.AreEqual(1, IdGeneratorUtility.UtcTimeStart.Day); + Assert.AreEqual(DateTimeKind.Utc, IdGeneratorUtility.UtcTimeStart.Kind); } #endregion @@ -27,15 +27,15 @@ public void UtcTimeStart_Is2020Jan1() [Test] public void GetNextUniqueId_ReturnsSequential() { - long id1 = Utility.IdGenerator.GetNextUniqueId(); - long id2 = Utility.IdGenerator.GetNextUniqueId(); + long id1 = IdGeneratorUtility.GetNextUniqueId(); + long id2 = IdGeneratorUtility.GetNextUniqueId(); Assert.AreEqual(id1 + 1, id2, "Sequential calls should produce consecutive IDs"); } [Test] public void GetNextUniqueId_ReturnsPositive() { - long id = Utility.IdGenerator.GetNextUniqueId(); + long id = IdGeneratorUtility.GetNextUniqueId(); Assert.Greater(id, 0); } @@ -46,7 +46,7 @@ public void GetNextUniqueId_MultipleCalls_AllUnique() HashSet ids = new HashSet(); for (int i = 0; i < count; i++) { - long id = Utility.IdGenerator.GetNextUniqueId(); + long id = IdGeneratorUtility.GetNextUniqueId(); Assert.IsTrue(ids.Add(id), $"Duplicate ID found: {id}"); } Assert.AreEqual(count, ids.Count); @@ -68,7 +68,7 @@ public void GetNextUniqueId_Concurrent_AllUnique() List localIds = new List(); for (int i = 0; i < perThread; i++) { - localIds.Add(Utility.IdGenerator.GetNextUniqueId()); + localIds.Add(IdGeneratorUtility.GetNextUniqueId()); } lock (lockObj) { @@ -99,8 +99,8 @@ public void GetNextUniqueId_Concurrent_AllUnique() [Test] public void GetNextUniqueIntId_ReturnsSequential() { - int id1 = Utility.IdGenerator.GetNextUniqueIntId(); - int id2 = Utility.IdGenerator.GetNextUniqueIntId(); + int id1 = IdGeneratorUtility.GetNextUniqueIntId(); + int id2 = IdGeneratorUtility.GetNextUniqueIntId(); Assert.AreEqual(id1 + 1, id2); } @@ -111,7 +111,7 @@ public void GetNextUniqueIntId_MultipleCalls_AllUnique() HashSet ids = new HashSet(); for (int i = 0; i < count; i++) { - int id = Utility.IdGenerator.GetNextUniqueIntId(); + int id = IdGeneratorUtility.GetNextUniqueIntId(); Assert.IsTrue(ids.Add(id), $"Duplicate int ID found: {id}"); } Assert.AreEqual(count, ids.Count); diff --git a/Tests/UtilityMarshalTests.cs b/Tests/UtilityMarshalTests.cs index 3104d52..43e13e9 100644 --- a/Tests/UtilityMarshalTests.cs +++ b/Tests/UtilityMarshalTests.cs @@ -20,8 +20,8 @@ private struct TestStruct [Test] public void EnsureCachedHGlobalSize_PositiveSize_SetsSize() { - Utility.Marshal.EnsureCachedHGlobalSize(100); - Assert.Greater(Utility.Marshal.CachedHGlobalSize, 0); + MarshalUtility.EnsureCachedHGlobalSize(100); + Assert.Greater(MarshalUtility.CachedHGlobalSize, 0); } [Test] @@ -29,31 +29,31 @@ public void EnsureCachedHGlobalSize_NegativeSize_Throws() { Assert.Throws(() => { - Utility.Marshal.EnsureCachedHGlobalSize(-1); + MarshalUtility.EnsureCachedHGlobalSize(-1); }); } [Test] public void EnsureCachedHGlobalSize_Zero_IsAllowed() { - Utility.Marshal.EnsureCachedHGlobalSize(0); + MarshalUtility.EnsureCachedHGlobalSize(0); } [Test] public void EnsureCachedHGlobalSize_RoundsUpToBlockSize() { - Utility.Marshal.EnsureCachedHGlobalSize(1); - Assert.GreaterOrEqual(Utility.Marshal.CachedHGlobalSize, 1); - Assert.AreEqual(0, Utility.Marshal.CachedHGlobalSize % 4096); + MarshalUtility.EnsureCachedHGlobalSize(1); + Assert.GreaterOrEqual(MarshalUtility.CachedHGlobalSize, 1); + Assert.AreEqual(0, MarshalUtility.CachedHGlobalSize % 4096); } [Test] public void EnsureCachedHGlobalSize_DoesNotShrink() { - Utility.Marshal.EnsureCachedHGlobalSize(4096); - int size1 = Utility.Marshal.CachedHGlobalSize; - Utility.Marshal.EnsureCachedHGlobalSize(100); - Assert.AreEqual(size1, Utility.Marshal.CachedHGlobalSize); + MarshalUtility.EnsureCachedHGlobalSize(4096); + int size1 = MarshalUtility.CachedHGlobalSize; + MarshalUtility.EnsureCachedHGlobalSize(100); + Assert.AreEqual(size1, MarshalUtility.CachedHGlobalSize); } #endregion @@ -63,18 +63,18 @@ public void EnsureCachedHGlobalSize_DoesNotShrink() [Test] public void FreeCachedHGlobal_SetsSizeToZero() { - Utility.Marshal.EnsureCachedHGlobalSize(100); - Utility.Marshal.FreeCachedHGlobal(); - Assert.AreEqual(0, Utility.Marshal.CachedHGlobalSize); + MarshalUtility.EnsureCachedHGlobalSize(100); + MarshalUtility.FreeCachedHGlobal(); + Assert.AreEqual(0, MarshalUtility.CachedHGlobalSize); } [Test] public void FreeCachedHGlobal_CalledTwice_DoesNotThrow() { - Utility.Marshal.EnsureCachedHGlobalSize(100); - Utility.Marshal.FreeCachedHGlobal(); - Utility.Marshal.FreeCachedHGlobal(); - Assert.AreEqual(0, Utility.Marshal.CachedHGlobalSize); + MarshalUtility.EnsureCachedHGlobalSize(100); + MarshalUtility.FreeCachedHGlobal(); + MarshalUtility.FreeCachedHGlobal(); + Assert.AreEqual(0, MarshalUtility.CachedHGlobalSize); } #endregion @@ -85,11 +85,11 @@ public void FreeCachedHGlobal_CalledTwice_DoesNotThrow() public void StructureToBytes_BytesToStructure_RoundTrip() { TestStruct original = new TestStruct { Id = 42, Value = 3.14f }; - byte[] bytes = Utility.Marshal.StructureToBytes(original); + byte[] bytes = MarshalUtility.StructureToBytes(original); Assert.IsNotNull(bytes); Assert.Greater(bytes.Length, 0); - TestStruct restored = Utility.Marshal.BytesToStructure(bytes); + TestStruct restored = MarshalUtility.BytesToStructure(bytes); Assert.AreEqual(original.Id, restored.Id); Assert.AreEqual(original.Value, restored.Value, 0.0001f); } @@ -100,8 +100,8 @@ public void StructureToBytes_WithBuffer() TestStruct original = new TestStruct { Id = 99, Value = -1.5f }; int structSize = Marshal.SizeOf(typeof(TestStruct)); byte[] buffer = new byte[structSize]; - Utility.Marshal.StructureToBytes(original, buffer); - TestStruct restored = Utility.Marshal.BytesToStructure(buffer); + MarshalUtility.StructureToBytes(original, buffer); + TestStruct restored = MarshalUtility.BytesToStructure(buffer); Assert.AreEqual(original.Id, restored.Id); Assert.AreEqual(original.Value, restored.Value, 0.0001f); } @@ -112,8 +112,8 @@ public void StructureToBytes_WithBufferAndOffset() TestStruct original = new TestStruct { Id = 7, Value = 2.71f }; int structSize = Marshal.SizeOf(typeof(TestStruct)); byte[] buffer = new byte[structSize + 10]; - Utility.Marshal.StructureToBytes(original, buffer, 5); - TestStruct restored = Utility.Marshal.BytesToStructure(buffer, 5); + MarshalUtility.StructureToBytes(original, buffer, 5); + TestStruct restored = MarshalUtility.BytesToStructure(buffer, 5); Assert.AreEqual(original.Id, restored.Id); Assert.AreEqual(original.Value, restored.Value, 0.0001f); } @@ -122,10 +122,10 @@ public void StructureToBytes_WithBufferAndOffset() public void BytesToStructure_WithOffset() { TestStruct original = new TestStruct { Id = 123, Value = 0.5f }; - byte[] bytes = Utility.Marshal.StructureToBytes(original); + byte[] bytes = MarshalUtility.StructureToBytes(original); byte[] padded = new byte[bytes.Length + 20]; Buffer.BlockCopy(bytes, 0, padded, 10, bytes.Length); - TestStruct restored = Utility.Marshal.BytesToStructure(padded, 10); + TestStruct restored = MarshalUtility.BytesToStructure(padded, 10); Assert.AreEqual(original.Id, restored.Id); Assert.AreEqual(original.Value, restored.Value, 0.0001f); } @@ -140,7 +140,7 @@ public void StructureToBytes_NullBuffer_Throws() TestStruct s = new TestStruct(); Assert.Throws(() => { - Utility.Marshal.StructureToBytes(s, null, 0); + MarshalUtility.StructureToBytes(s, null, 0); }); } @@ -151,7 +151,7 @@ public void StructureToBytes_NegativeStartIndex_Throws() byte[] buffer = new byte[100]; Assert.Throws(() => { - Utility.Marshal.StructureToBytes(s, buffer, -1); + MarshalUtility.StructureToBytes(s, buffer, -1); }); } @@ -162,7 +162,7 @@ public void StructureToBytes_BufferTooSmall_Throws() byte[] buffer = new byte[1]; Assert.Throws(() => { - Utility.Marshal.StructureToBytes(s, buffer, 0); + MarshalUtility.StructureToBytes(s, buffer, 0); }); } @@ -176,8 +176,8 @@ public void MultipleStructs_SameRoundTrip() for (int i = 0; i < 50; i++) { TestStruct original = new TestStruct { Id = i, Value = i * 0.1f }; - byte[] bytes = Utility.Marshal.StructureToBytes(original); - TestStruct restored = Utility.Marshal.BytesToStructure(bytes); + byte[] bytes = MarshalUtility.StructureToBytes(original); + TestStruct restored = MarshalUtility.BytesToStructure(bytes); Assert.AreEqual(original.Id, restored.Id, $"Failed at iteration {i}"); } } @@ -189,7 +189,7 @@ public void MultipleStructs_SameRoundTrip() [TearDown] public void TearDown() { - Utility.Marshal.FreeCachedHGlobal(); + MarshalUtility.FreeCachedHGlobal(); } #endregion diff --git a/Tests/UtilityObjectTests.cs b/Tests/UtilityObjectTests.cs index cbe2d3f..d99aee4 100644 --- a/Tests/UtilityObjectTests.cs +++ b/Tests/UtilityObjectTests.cs @@ -13,7 +13,7 @@ public void Swap_Integers() { int a = 10; int b = 20; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.AreEqual(20, a); Assert.AreEqual(10, b); } @@ -23,7 +23,7 @@ public void Swap_Strings() { string a = "hello"; string b = "world"; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.AreEqual("world", a); Assert.AreEqual("hello", b); } @@ -33,7 +33,7 @@ public void Swap_SameValue() { int a = 42; int b = 42; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.AreEqual(42, a); Assert.AreEqual(42, b); } @@ -45,7 +45,7 @@ public void Swap_ReferenceTypes() object b = new object(); object origA = a; object origB = b; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.AreSame(origB, a); Assert.AreSame(origA, b); } @@ -55,7 +55,7 @@ public void Swap_NullValues() { string a = "value"; string b = null; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.IsNull(a); Assert.AreEqual("value", b); } @@ -65,7 +65,7 @@ public void Swap_BothNull() { string a = null; string b = null; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.IsNull(a); Assert.IsNull(b); } @@ -75,7 +75,7 @@ public void Swap_Floats() { float a = 1.5f; float b = -3.14f; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.AreEqual(-3.14f, a, 0.001f); Assert.AreEqual(1.5f, b, 0.001f); } @@ -85,7 +85,7 @@ public void Swap_Bool() { bool a = true; bool b = false; - Utility.Object.Swap(ref a, ref b); + ObjectUtility.Swap(ref a, ref b); Assert.IsFalse(a); Assert.IsTrue(b); } diff --git a/Tests/UtilityPathTests.cs b/Tests/UtilityPathTests.cs index 9178b90..5cd0e0b 100644 --- a/Tests/UtilityPathTests.cs +++ b/Tests/UtilityPathTests.cs @@ -1,4 +1,3 @@ -using System.IO; using GameFrameX.Runtime; using NUnit.Framework; @@ -12,14 +11,14 @@ public class UtilityPathTests [Test] public void GetRegularPath_NullInput_ReturnsNull() { - string result = Utility.Path.GetRegularPath(null); + string result = PathUtility.GetRegularPath(null); Assert.IsNull(result); } [Test] public void GetRegularPath_ConvertsBackslashes() { - string result = Utility.Path.GetRegularPath("folder\\subfolder\\file.txt"); + string result = PathUtility.GetRegularPath("folder\\subfolder\\file.txt"); Assert.AreEqual("folder/subfolder/file.txt", result); } @@ -27,28 +26,28 @@ public void GetRegularPath_ConvertsBackslashes() public void GetRegularPath_NoBackslashes_Unchanged() { string path = "folder/subfolder/file.txt"; - string result = Utility.Path.GetRegularPath(path); + string result = PathUtility.GetRegularPath(path); Assert.AreEqual(path, result); } [Test] public void GetRegularPath_EmptyString() { - string result = Utility.Path.GetRegularPath(""); + string result = PathUtility.GetRegularPath(""); Assert.AreEqual("", result); } [Test] public void GetRegularPath_MixedSlashes() { - string result = Utility.Path.GetRegularPath("folder/sub\\mixed/file"); + string result = PathUtility.GetRegularPath("folder/sub\\mixed/file"); Assert.AreEqual("folder/sub/mixed/file", result); } [Test] public void GetRegularPath_WindowsDrive() { - string result = Utility.Path.GetRegularPath("C:\\Users\\test"); + string result = PathUtility.GetRegularPath("C:\\Users\\test"); Assert.AreEqual("C:/Users/test", result); } @@ -59,14 +58,14 @@ public void GetRegularPath_WindowsDrive() [Test] public void GetRemotePath_NullInput_ReturnsNull() { - string result = Utility.Path.GetRemotePath(null); + string result = PathUtility.GetRemotePath(null); Assert.IsNull(result); } [Test] public void GetRemotePath_RelativePath_PrefixesFileProtocol() { - string result = Utility.Path.GetRemotePath("path/to/file.txt"); + string result = PathUtility.GetRemotePath("path/to/file.txt"); Assert.AreEqual("file:///path/to/file.txt", result); } @@ -74,7 +73,7 @@ public void GetRemotePath_RelativePath_PrefixesFileProtocol() public void GetRemotePath_AlreadyHasProtocol_Unchanged() { string path = "http://example.com/file"; - string result = Utility.Path.GetRemotePath(path); + string result = PathUtility.GetRemotePath(path); Assert.AreEqual(path, result); } @@ -82,7 +81,7 @@ public void GetRemotePath_AlreadyHasProtocol_Unchanged() public void GetRemotePath_HttpsProtocol_Unchanged() { string path = "https://example.com/file"; - string result = Utility.Path.GetRemotePath(path); + string result = PathUtility.GetRemotePath(path); Assert.AreEqual(path, result); } @@ -90,140 +89,24 @@ public void GetRemotePath_HttpsProtocol_Unchanged() public void GetRemotePath_FileProtocol_Unchanged() { string path = "file:///path/to/file.txt"; - string result = Utility.Path.GetRemotePath(path); + string result = PathUtility.GetRemotePath(path); Assert.AreEqual(path, result); } [Test] public void GetRemotePath_WindowsPath_ConvertsAndPrefixes() { - string result = Utility.Path.GetRemotePath("C:\\path\\file.txt"); + string result = PathUtility.GetRemotePath("C:\\path\\file.txt"); Assert.AreEqual("file:///C:/path/file.txt", result); } [Test] public void GetRemotePath_EmptyString() { - string result = Utility.Path.GetRemotePath(""); + string result = PathUtility.GetRemotePath(""); Assert.AreEqual("file:///", result); } #endregion - - #region RemoveEmptyDirectory - - [Test] - public void RemoveEmptyDirectory_NullInput_Throws() - { - Assert.Throws(() => - { - Utility.Path.RemoveEmptyDirectory(null); - }); - } - - [Test] - public void RemoveEmptyDirectory_EmptyString_Throws() - { - Assert.Throws(() => - { - Utility.Path.RemoveEmptyDirectory(""); - }); - } - - [Test] - public void RemoveEmptyDirectory_NonExistentPath_ReturnsFalse() - { - string nonExistent = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_NonExistent_" + System.Guid.NewGuid()); - bool result = Utility.Path.RemoveEmptyDirectory(nonExistent); - Assert.IsFalse(result); - } - - [Test] - public void RemoveEmptyDirectory_EmptyDir_RemovesAndReturnsTrue() - { - string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_Empty_" + System.Guid.NewGuid()); - try - { - Directory.CreateDirectory(tempDir); - Assert.IsTrue(Directory.Exists(tempDir)); - bool result = Utility.Path.RemoveEmptyDirectory(tempDir); - Assert.IsTrue(result); - Assert.IsFalse(Directory.Exists(tempDir)); - } - finally - { - if (Directory.Exists(tempDir)) - { - Directory.Delete(tempDir, true); - } - } - } - - [Test] - public void RemoveEmptyDirectory_DirWithFiles_ReturnsFalse() - { - string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_WithFiles_" + System.Guid.NewGuid()); - try - { - Directory.CreateDirectory(tempDir); - File.WriteAllText(Path.Combine(tempDir, "test.txt"), "data"); - bool result = Utility.Path.RemoveEmptyDirectory(tempDir); - Assert.IsFalse(result); - Assert.IsTrue(Directory.Exists(tempDir)); - } - finally - { - if (Directory.Exists(tempDir)) - { - Directory.Delete(tempDir, true); - } - } - } - - [Test] - public void RemoveEmptyDirectory_DirWithEmptySubDir_RemovesBoth() - { - string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_Nested_" + System.Guid.NewGuid()); - try - { - Directory.CreateDirectory(tempDir); - string subDir = Path.Combine(tempDir, "empty_sub"); - Directory.CreateDirectory(subDir); - bool result = Utility.Path.RemoveEmptyDirectory(tempDir); - Assert.IsTrue(result); - Assert.IsFalse(Directory.Exists(tempDir)); - } - finally - { - if (Directory.Exists(tempDir)) - { - Directory.Delete(tempDir, true); - } - } - } - - [Test] - public void RemoveEmptyDirectory_DirWithNonEmptySubDir_ReturnsFalse() - { - string tempDir = Path.Combine(Path.GetTempPath(), "GameFrameX_Test_NestedFiles_" + System.Guid.NewGuid()); - try - { - Directory.CreateDirectory(tempDir); - string subDir = Path.Combine(tempDir, "nonempty_sub"); - Directory.CreateDirectory(subDir); - File.WriteAllText(Path.Combine(subDir, "file.txt"), "data"); - bool result = Utility.Path.RemoveEmptyDirectory(tempDir); - Assert.IsFalse(result); - } - finally - { - if (Directory.Exists(tempDir)) - { - Directory.Delete(tempDir, true); - } - } - } - - #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityRandomUtilityTests.cs b/Tests/UtilityRandomUtilityTests.cs index 8fe24fc..eb9fbe0 100644 --- a/Tests/UtilityRandomUtilityTests.cs +++ b/Tests/UtilityRandomUtilityTests.cs @@ -12,7 +12,7 @@ public class UtilityRandomUtilityTests [Test] public void GetRandom_ReturnsNonNegative() { - int result = Utility.RandomUtility.GetRandom(); + int result = RandomUtility.GetRandom(); Assert.GreaterOrEqual(result, 0); } @@ -22,7 +22,7 @@ public void GetRandom_MultipleCalls_SomeDifferent() HashSet results = new HashSet(); for (int i = 0; i < 100; i++) { - results.Add(Utility.RandomUtility.GetRandom()); + results.Add(RandomUtility.GetRandom()); } Assert.Greater(results.Count, 1, "100 random calls should produce more than 1 unique value"); } @@ -34,14 +34,14 @@ public void GetRandom_MultipleCalls_SomeDifferent() [Test] public void GetRandom_MaxValue_Zero() { - int result = Utility.RandomUtility.GetRandom(0); + int result = RandomUtility.GetRandom(0); Assert.AreEqual(0, result); } [Test] public void GetRandom_MaxValue_One() { - int result = Utility.RandomUtility.GetRandom(1); + int result = RandomUtility.GetRandom(1); Assert.AreEqual(0, result); } @@ -51,7 +51,7 @@ public void GetRandom_MaxValue_WithinRange() const int max = 100; for (int i = 0; i < 200; i++) { - int result = Utility.RandomUtility.GetRandom(max); + int result = RandomUtility.GetRandom(max); Assert.GreaterOrEqual(result, 0); Assert.Less(result, max); } @@ -63,7 +63,7 @@ public void GetRandom_MaxValue_LargeRange() const int max = 1000000; for (int i = 0; i < 100; i++) { - int result = Utility.RandomUtility.GetRandom(max); + int result = RandomUtility.GetRandom(max); Assert.GreaterOrEqual(result, 0); Assert.Less(result, max); } @@ -76,7 +76,7 @@ public void GetRandom_MaxValue_LargeRange() [Test] public void GetRandom_Range_SameMinAndMax_ReturnsMin() { - int result = Utility.RandomUtility.GetRandom(5, 5); + int result = RandomUtility.GetRandom(5, 5); Assert.AreEqual(5, result); } @@ -87,7 +87,7 @@ public void GetRandom_Range_WithinRange() const int max = 20; for (int i = 0; i < 200; i++) { - int result = Utility.RandomUtility.GetRandom(min, max); + int result = RandomUtility.GetRandom(min, max); Assert.GreaterOrEqual(result, min); Assert.Less(result, max); } @@ -100,7 +100,7 @@ public void GetRandom_Range_NegativeMin() const int max = 50; for (int i = 0; i < 200; i++) { - int result = Utility.RandomUtility.GetRandom(min, max); + int result = RandomUtility.GetRandom(min, max); Assert.GreaterOrEqual(result, min); Assert.Less(result, max); } @@ -109,7 +109,7 @@ public void GetRandom_Range_NegativeMin() [Test] public void GetRandom_Range_SpanIsOne() { - int result = Utility.RandomUtility.GetRandom(42, 43); + int result = RandomUtility.GetRandom(42, 43); Assert.AreEqual(42, result); } @@ -122,7 +122,7 @@ public void GetRandomDouble_WithinRange() { for (int i = 0; i < 100; i++) { - double result = Utility.RandomUtility.GetRandomDouble(); + double result = RandomUtility.GetRandomDouble(); Assert.GreaterOrEqual(result, 0.0); Assert.Less(result, 1.0); } @@ -134,7 +134,7 @@ public void GetRandomDouble_MultipleCalls_SomeDifferent() HashSet results = new HashSet(); for (int i = 0; i < 100; i++) { - results.Add(Utility.RandomUtility.GetRandomDouble()); + results.Add(RandomUtility.GetRandomDouble()); } Assert.Greater(results.Count, 1); } @@ -147,7 +147,7 @@ public void GetRandomDouble_MultipleCalls_SomeDifferent() public void GetRandomBytes_FillsBuffer() { byte[] buffer = new byte[100]; - Utility.RandomUtility.GetRandomBytes(buffer); + RandomUtility.GetRandomBytes(buffer); Assert.AreEqual(100, buffer.Length); } @@ -155,7 +155,7 @@ public void GetRandomBytes_FillsBuffer() public void GetRandomBytes_NotAllZeros() { byte[] buffer = new byte[100]; - Utility.RandomUtility.GetRandomBytes(buffer); + RandomUtility.GetRandomBytes(buffer); bool allZero = true; for (int i = 0; i < buffer.Length; i++) { @@ -172,7 +172,7 @@ public void GetRandomBytes_NotAllZeros() public void GetRandomBytes_SingleByte() { byte[] buffer = new byte[1]; - Utility.RandomUtility.GetRandomBytes(buffer); + RandomUtility.GetRandomBytes(buffer); Assert.AreEqual(1, buffer.Length); } @@ -181,8 +181,8 @@ public void GetRandomBytes_TwoCallsDifferent() { byte[] buffer1 = new byte[1000]; byte[] buffer2 = new byte[1000]; - Utility.RandomUtility.GetRandomBytes(buffer1); - Utility.RandomUtility.GetRandomBytes(buffer2); + RandomUtility.GetRandomBytes(buffer1); + RandomUtility.GetRandomBytes(buffer2); bool allSame = true; for (int i = 0; i < buffer1.Length; i++) { @@ -202,13 +202,13 @@ public void GetRandomBytes_TwoCallsDifferent() [Test] public void SetSeed_DeterministicSequence() { - Utility.RandomUtility.SetSeed(42); - int first1 = Utility.RandomUtility.GetRandom(); - int first2 = Utility.RandomUtility.GetRandom(); + RandomUtility.SetSeed(42); + int first1 = RandomUtility.GetRandom(); + int first2 = RandomUtility.GetRandom(); - Utility.RandomUtility.SetSeed(42); - int second1 = Utility.RandomUtility.GetRandom(); - int second2 = Utility.RandomUtility.GetRandom(); + RandomUtility.SetSeed(42); + int second1 = RandomUtility.GetRandom(); + int second2 = RandomUtility.GetRandom(); Assert.AreEqual(first1, second1); Assert.AreEqual(first2, second2); @@ -217,15 +217,94 @@ public void SetSeed_DeterministicSequence() [Test] public void SetSeed_DifferentSeed_DifferentSequence() { - Utility.RandomUtility.SetSeed(1); - int r1 = Utility.RandomUtility.GetRandom(); + RandomUtility.SetSeed(1); + int r1 = RandomUtility.GetRandom(); - Utility.RandomUtility.SetSeed(2); - int r2 = Utility.RandomUtility.GetRandom(); + RandomUtility.SetSeed(2); + int r2 = RandomUtility.GetRandom(); Assert.AreNotEqual(r1, r2); } #endregion + + #region GetRandomFloat + + [Test] + public void GetRandomFloat_WithinRange() + { + for (int i = 0; i < 100; i++) + { + float result = RandomUtility.GetRandomFloat(); + Assert.GreaterOrEqual(result, 0.0f); + Assert.Less(result, 1.0f); + } + } + + [Test] + public void GetRandomFloat_WithSeed_ReturnsReproducibleValue() + { + RandomUtility.SetSeed(123); + float first = RandomUtility.GetRandomFloat(); + + RandomUtility.SetSeed(123); + float second = RandomUtility.GetRandomFloat(); + + Assert.AreEqual(first, second); + } + + #endregion + + #region GetRandomInt64 + + [Test] + public void GetRandomInt64_WithSeed_ReturnsReproducibleValue() + { + RandomUtility.SetSeed(77); + long first = RandomUtility.GetRandomInt64(); + + RandomUtility.SetSeed(77); + long second = RandomUtility.GetRandomInt64(); + + Assert.AreEqual(first, second); + } + + [Test] + public void GetRandomInt64_MultipleCalls_ProduceDifferentValues() + { + long a = RandomUtility.GetRandomInt64(); + long b = RandomUtility.GetRandomInt64(); + long c = RandomUtility.GetRandomInt64(); + + Assert.AreNotEqual(a, b, "Two consecutive calls should usually differ"); + Assert.AreNotEqual(b, c, "Three consecutive calls should usually differ"); + } + + #endregion + + #region GetRandomUInt64 + + [Test] + public void GetRandomUInt64_WithSeed_ReturnsReproducibleValue() + { + RandomUtility.SetSeed(55); + ulong first = RandomUtility.GetRandomUInt64(); + + RandomUtility.SetSeed(55); + ulong second = RandomUtility.GetRandomUInt64(); + + Assert.AreEqual(first, second); + } + + [Test] + public void GetRandomUInt64_MultipleCalls_ProduceDifferentValues() + { + ulong a = RandomUtility.GetRandomUInt64(); + ulong b = RandomUtility.GetRandomUInt64(); + + Assert.AreNotEqual(a, b); + } + + #endregion } } diff --git a/Tests/UtilityTextTests.cs b/Tests/UtilityTextTests.cs index ab73739..da03651 100644 --- a/Tests/UtilityTextTests.cs +++ b/Tests/UtilityTextTests.cs @@ -6,7 +6,7 @@ namespace GameFrameX.Tests [TestFixture] public class UtilityTextTests { - private class StubTextHelper : Utility.Text.ITextHelper + private class StubTextHelper : GameFrameworkText.ITextHelper { public string Format(string format, params object[] args) { @@ -97,7 +97,7 @@ public string Format(() => { - Utility.Text.Format(null, "arg"); + GameFrameworkText.Format(null, "arg"); }); } @@ -179,7 +179,7 @@ public void Format_NullFormat_SingleArg_Throws() { Assert.Throws(() => { - Utility.Text.Format(null, 1); + GameFrameworkText.Format(null, 1); }); } @@ -188,7 +188,7 @@ public void Format_NullFormat_TwoArgs_Throws() { Assert.Throws(() => { - Utility.Text.Format(null, 1, 2); + GameFrameworkText.Format(null, 1, 2); }); } @@ -199,47 +199,47 @@ public void Format_NullFormat_TwoArgs_Throws() [Test] public void Format_WithHelper_UsesHelper() { - Utility.Text.SetTextHelper(new StubTextHelper()); - string result = Utility.Text.Format("Hello {0}", "World"); + GameFrameworkText.SetTextHelper(new StubTextHelper()); + string result = GameFrameworkText.Format("Hello {0}", "World"); Assert.AreEqual("[STUB]Hello World", result); } [Test] public void Format_SingleArg_WithHelper_UsesHelper() { - Utility.Text.SetTextHelper(new StubTextHelper()); - string result = Utility.Text.Format("Value: {0}", 42); + GameFrameworkText.SetTextHelper(new StubTextHelper()); + string result = GameFrameworkText.Format("Value: {0}", 42); Assert.AreEqual("[STUB]Value: 42", result); } [Test] public void Format_TwoArgs_WithHelper_UsesHelper() { - Utility.Text.SetTextHelper(new StubTextHelper()); - string result = Utility.Text.Format("{0} and {1}", "A", "B"); + GameFrameworkText.SetTextHelper(new StubTextHelper()); + string result = GameFrameworkText.Format("{0} and {1}", "A", "B"); Assert.AreEqual("[STUB]A and B", result); } [Test] public void Format_ThreeArgs_WithHelper_UsesHelper() { - Utility.Text.SetTextHelper(new StubTextHelper()); - string result = Utility.Text.Format("{0}-{1}-{2}", 1, 2, 3); + GameFrameworkText.SetTextHelper(new StubTextHelper()); + string result = GameFrameworkText.Format("{0}-{1}-{2}", 1, 2, 3); Assert.AreEqual("[STUB]1-2-3", result); } [Test] public void SetTextHelper_Null_ResetsHelper() { - Utility.Text.SetTextHelper(new StubTextHelper()); - string stubResult = Utility.Text.Format("{0}", "test"); + GameFrameworkText.SetTextHelper(new StubTextHelper()); + string stubResult = GameFrameworkText.Format("{0}", "test"); Assert.IsTrue(stubResult.StartsWith("[STUB]")); - Utility.Text.SetTextHelper(null); - string defaultResult = Utility.Text.Format("{0}", "test"); + GameFrameworkText.SetTextHelper(null); + string defaultResult = GameFrameworkText.Format("{0}", "test"); Assert.AreEqual("test", defaultResult); } #endregion } -} +} \ No newline at end of file diff --git a/Tests/UtilityVerifierCrc32Tests.cs b/Tests/UtilityVerifierCrc32Tests.cs index 8079f79..7577876 100644 --- a/Tests/UtilityVerifierCrc32Tests.cs +++ b/Tests/UtilityVerifierCrc32Tests.cs @@ -14,7 +14,7 @@ public class UtilityVerifierCrc32Tests public void GetCrc32_KnownVector() { byte[] data = Encoding.ASCII.GetBytes("123456789"); - int result = Utility.Verifier.GetCrc32(data); + int result = VerifierUtility.GetCrc32(data); Assert.AreEqual(unchecked((int)0xCBF43926u), result, "CRC32 of '123456789' should be 0xCBF43926"); } @@ -22,8 +22,8 @@ public void GetCrc32_KnownVector() public void GetCrc32_SameInput_SameOutput() { byte[] data = new byte[] { 1, 2, 3, 4, 5 }; - int hash1 = Utility.Verifier.GetCrc32(data); - int hash2 = Utility.Verifier.GetCrc32(data); + int hash1 = VerifierUtility.GetCrc32(data); + int hash2 = VerifierUtility.GetCrc32(data); Assert.AreEqual(hash1, hash2); } @@ -32,8 +32,8 @@ public void GetCrc32_DifferentInput_DifferentOutput() { byte[] data1 = new byte[] { 1, 2, 3 }; byte[] data2 = new byte[] { 4, 5, 6 }; - int hash1 = Utility.Verifier.GetCrc32(data1); - int hash2 = Utility.Verifier.GetCrc32(data2); + int hash1 = VerifierUtility.GetCrc32(data1); + int hash2 = VerifierUtility.GetCrc32(data2); Assert.AreNotEqual(hash1, hash2); } @@ -42,21 +42,21 @@ public void GetCrc32_NullInput_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32((byte[])null); + VerifierUtility.GetCrc32((byte[])null); }); } [Test] public void GetCrc32_EmptyArray() { - int result = Utility.Verifier.GetCrc32(new byte[0]); + int result = VerifierUtility.GetCrc32(new byte[0]); Assert.AreEqual(0, result); } [Test] public void GetCrc32_SingleByte() { - int result = Utility.Verifier.GetCrc32(new byte[] { 0x00 }); + int result = VerifierUtility.GetCrc32(new byte[] { 0x00 }); Assert.AreNotEqual(0, result); } @@ -68,7 +68,7 @@ public void GetCrc32_LargeInput() { data[i] = (byte)(i & 0xFF); } - int result = Utility.Verifier.GetCrc32(data); + int result = VerifierUtility.GetCrc32(data); Assert.AreNotEqual(0, result); } @@ -81,8 +81,8 @@ public void GetCrc32_WithOffsetAndLength() { byte[] fullData = new byte[] { 0, 0, 0, 1, 2, 3, 0, 0 }; byte[] subData = new byte[] { 1, 2, 3 }; - int hash1 = Utility.Verifier.GetCrc32(fullData, 3, 3); - int hash2 = Utility.Verifier.GetCrc32(subData); + int hash1 = VerifierUtility.GetCrc32(fullData, 3, 3); + int hash2 = VerifierUtility.GetCrc32(subData); Assert.AreEqual(hash1, hash2); } @@ -91,7 +91,7 @@ public void GetCrc32_NullBytes_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32(null, 0, 0); + VerifierUtility.GetCrc32(null, 0, 0); }); } @@ -100,7 +100,7 @@ public void GetCrc32_NegativeOffset_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32(new byte[] { 1 }, -1, 1); + VerifierUtility.GetCrc32(new byte[] { 1 }, -1, 1); }); } @@ -109,7 +109,7 @@ public void GetCrc32_NegativeLength_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32(new byte[] { 1 }, 0, -1); + VerifierUtility.GetCrc32(new byte[] { 1 }, 0, -1); }); } @@ -118,7 +118,7 @@ public void GetCrc32_OffsetPlusLengthExceedsArray_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32(new byte[] { 1, 2, 3 }, 1, 3); + VerifierUtility.GetCrc32(new byte[] { 1, 2, 3 }, 1, 3); }); } @@ -126,12 +126,12 @@ public void GetCrc32_OffsetPlusLengthExceedsArray_Throws() public void GetCrc32_ChunkedVsFull_SameResult() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - int fullHash = Utility.Verifier.GetCrc32(data); + int fullHash = VerifierUtility.GetCrc32(data); - int partialHash = Utility.Verifier.GetCrc32(data, 0, 4); - partialHash ^= Utility.Verifier.GetCrc32(data, 4, 4); + int partialHash = VerifierUtility.GetCrc32(data, 0, 4); + partialHash ^= VerifierUtility.GetCrc32(data, 4, 4); - Assert.AreEqual(fullHash, Utility.Verifier.GetCrc32(data)); + Assert.AreEqual(fullHash, VerifierUtility.GetCrc32(data)); } #endregion @@ -144,7 +144,7 @@ public void GetCrc32_Stream_KnownVector() byte[] data = Encoding.ASCII.GetBytes("123456789"); using (var stream = new MemoryStream(data)) { - int result = Utility.Verifier.GetCrc32(stream); + int result = VerifierUtility.GetCrc32(stream); Assert.AreEqual(unchecked((int)0xCBF43926u), result); } } @@ -154,7 +154,7 @@ public void GetCrc32_Stream_Null_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32((Stream)null); + VerifierUtility.GetCrc32((Stream)null); }); } @@ -162,10 +162,10 @@ public void GetCrc32_Stream_Null_Throws() public void GetCrc32_Stream_MatchesByteArray() { byte[] data = Encoding.UTF8.GetBytes("Stream vs byte array test"); - int fromArray = Utility.Verifier.GetCrc32(data); + int fromArray = VerifierUtility.GetCrc32(data); using (var stream = new MemoryStream(data)) { - int fromStream = Utility.Verifier.GetCrc32(stream); + int fromStream = VerifierUtility.GetCrc32(stream); Assert.AreEqual(fromArray, fromStream); } } @@ -177,8 +177,8 @@ public void GetCrc32_Stream_MatchesByteArray() [Test] public void GetCrc32Bytes_Returns4Bytes() { - int crc32 = Utility.Verifier.GetCrc32(Encoding.ASCII.GetBytes("test")); - byte[] bytes = Utility.Verifier.GetCrc32Bytes(crc32); + int crc32 = VerifierUtility.GetCrc32(Encoding.ASCII.GetBytes("test")); + byte[] bytes = VerifierUtility.GetCrc32Bytes(crc32); Assert.AreEqual(4, bytes.Length); } @@ -187,7 +187,7 @@ public void GetCrc32Bytes_WithBuffer() { int crc32 = 0x12345678; byte[] buffer = new byte[4]; - Utility.Verifier.GetCrc32Bytes(crc32, buffer); + VerifierUtility.GetCrc32Bytes(crc32, buffer); Assert.AreEqual(0x12, buffer[0]); Assert.AreEqual(0x34, buffer[1]); Assert.AreEqual(0x56, buffer[2]); @@ -199,7 +199,7 @@ public void GetCrc32Bytes_WithBufferAndOffset() { int crc32 = unchecked((int)0xAABBCCDDu); byte[] buffer = new byte[10]; - Utility.Verifier.GetCrc32Bytes(crc32, buffer, 3); + VerifierUtility.GetCrc32Bytes(crc32, buffer, 3); Assert.AreEqual(0xAA, buffer[3]); Assert.AreEqual(0xBB, buffer[4]); Assert.AreEqual(0xCC, buffer[5]); @@ -211,7 +211,7 @@ public void GetCrc32Bytes_NullBuffer_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc32Bytes(0, null, 0); + VerifierUtility.GetCrc32Bytes(0, null, 0); }); } @@ -221,7 +221,7 @@ public void GetCrc32Bytes_InvalidOffset_Throws() byte[] buffer = new byte[4]; Assert.Throws(() => { - Utility.Verifier.GetCrc32Bytes(0, buffer, -1); + VerifierUtility.GetCrc32Bytes(0, buffer, -1); }); } @@ -231,7 +231,7 @@ public void GetCrc32Bytes_BufferTooSmall_Throws() byte[] buffer = new byte[3]; Assert.Throws(() => { - Utility.Verifier.GetCrc32Bytes(0, buffer, 0); + VerifierUtility.GetCrc32Bytes(0, buffer, 0); }); } diff --git a/Tests/UtilityVerifierCrc64Tests.cs b/Tests/UtilityVerifierCrc64Tests.cs index 2c664a1..6bdbe02 100644 --- a/Tests/UtilityVerifierCrc64Tests.cs +++ b/Tests/UtilityVerifierCrc64Tests.cs @@ -9,14 +9,14 @@ namespace GameFrameX.Tests [TestFixture] public class UtilityVerifierCrc64Tests { - #region GetCrc64 (byte[] via Utility.Verifier) + #region GetCrc64 (byte[] via VerifierUtility) [Test] public void GetCrc64_SameInput_SameOutput() { byte[] data = Encoding.ASCII.GetBytes("123456789"); - ulong hash1 = Utility.Verifier.GetCrc64(data); - ulong hash2 = Utility.Verifier.GetCrc64(data); + ulong hash1 = VerifierUtility.GetCrc64(data); + ulong hash2 = VerifierUtility.GetCrc64(data); Assert.AreEqual(hash1, hash2); } @@ -25,22 +25,22 @@ public void GetCrc64_DifferentInput_DifferentOutput() { byte[] data1 = Encoding.ASCII.GetBytes("foo"); byte[] data2 = Encoding.ASCII.GetBytes("bar"); - ulong hash1 = Utility.Verifier.GetCrc64(data1); - ulong hash2 = Utility.Verifier.GetCrc64(data2); + ulong hash1 = VerifierUtility.GetCrc64(data1); + ulong hash2 = VerifierUtility.GetCrc64(data2); Assert.AreNotEqual(hash1, hash2); } [Test] public void GetCrc64_EmptyArray() { - ulong result = Utility.Verifier.GetCrc64(new byte[0]); + ulong result = VerifierUtility.GetCrc64(new byte[0]); Assert.AreEqual(0ul, result); } [Test] public void GetCrc64_SingleByte() { - ulong result = Utility.Verifier.GetCrc64(new byte[] { 42 }); + ulong result = VerifierUtility.GetCrc64(new byte[] { 42 }); Assert.AreNotEqual(0ul, result); } @@ -52,7 +52,7 @@ public void GetCrc64_LargeInput() { data[i] = (byte)(i & 0xFF); } - ulong result = Utility.Verifier.GetCrc64(data); + ulong result = VerifierUtility.GetCrc64(data); Assert.AreNotEqual(0ul, result); } @@ -64,10 +64,10 @@ public void GetCrc64_LargeInput() public void GetCrc64_Stream_MatchesByteArray() { byte[] data = Encoding.UTF8.GetBytes("Stream vs byte array test"); - ulong fromArray = Utility.Verifier.GetCrc64(data); + ulong fromArray = VerifierUtility.GetCrc64(data); using (var stream = new MemoryStream(data)) { - ulong fromStream = Utility.Verifier.GetCrc64(stream); + ulong fromStream = VerifierUtility.GetCrc64(stream); Assert.AreEqual(fromArray, fromStream); } } @@ -77,7 +77,7 @@ public void GetCrc64_Stream_Null_Throws() { Assert.Throws(() => { - Utility.Verifier.GetCrc64((Stream)null); + VerifierUtility.GetCrc64((Stream)null); }); } @@ -86,7 +86,7 @@ public void GetCrc64_Stream_EmptyStream() { using (var stream = new MemoryStream()) { - ulong result = Utility.Verifier.GetCrc64(stream); + ulong result = VerifierUtility.GetCrc64(stream); Assert.AreEqual(0ul, result); } } @@ -100,14 +100,14 @@ public void Crc64_Hash_NullInput_Throws() { Assert.Throws(() => { - Utility.Verifier.Crc64.Hash(null); + VerifierUtility.Crc64.Hash(null); }); } [Test] public void Crc64_Hash_EmptyArray() { - byte[] result = Utility.Verifier.Crc64.Hash(new byte[0]); + byte[] result = VerifierUtility.Crc64.Hash(new byte[0]); Assert.AreEqual(8, result.Length); foreach (byte b in result) { @@ -119,8 +119,8 @@ public void Crc64_Hash_EmptyArray() public void Crc64_Hash_SameInput_SameOutput() { byte[] data = new byte[] { 1, 2, 3, 4, 5 }; - byte[] hash1 = Utility.Verifier.Crc64.Hash(data); - byte[] hash2 = Utility.Verifier.Crc64.Hash(data); + byte[] hash1 = VerifierUtility.Crc64.Hash(data); + byte[] hash2 = VerifierUtility.Crc64.Hash(data); CollectionAssert.AreEqual(hash1, hash2); } @@ -128,14 +128,14 @@ public void Crc64_Hash_SameInput_SameOutput() public void Crc64_Hash_Returns8Bytes() { byte[] data = new byte[] { 42 }; - byte[] result = Utility.Verifier.Crc64.Hash(data); + byte[] result = VerifierUtility.Crc64.Hash(data); Assert.AreEqual(8, result.Length); } [Test] public void Crc64_HashToUInt64_EmptyInput_IsZero() { - ulong result = Utility.Verifier.Crc64.HashToUInt64(new byte[0]); + ulong result = VerifierUtility.Crc64.HashToUInt64(new byte[0]); Assert.AreEqual(0ul, result); } @@ -143,15 +143,15 @@ public void Crc64_HashToUInt64_EmptyInput_IsZero() public void Crc64_HashToUInt64_SameInput_SameOutput() { byte[] data = new byte[] { 10, 20, 30 }; - ulong hash1 = Utility.Verifier.Crc64.HashToUInt64(data); - ulong hash2 = Utility.Verifier.Crc64.HashToUInt64(data); + ulong hash1 = VerifierUtility.Crc64.HashToUInt64(data); + ulong hash2 = VerifierUtility.Crc64.HashToUInt64(data); Assert.AreEqual(hash1, hash2); } [Test] public void Crc64_AppendAndGetHash() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); crc.Append(Encoding.ASCII.GetBytes("test data")); byte[] hash = crc.GetCurrentHash(); Assert.AreEqual(8, hash.Length); @@ -160,7 +160,7 @@ public void Crc64_AppendAndGetHash() [Test] public void Crc64_ResetClearsState() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); crc.Append(new byte[] { 1, 2, 3 }); crc.Reset(); Assert.AreEqual(0ul, crc.GetCurrentHashAsUInt64()); @@ -171,10 +171,10 @@ public void Crc64_AppendInChunks_SameAsFull() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; - var crc1 = new Utility.Verifier.Crc64(); + var crc1 = new VerifierUtility.Crc64(); crc1.Append(data); - var crc2 = new Utility.Verifier.Crc64(); + var crc2 = new VerifierUtility.Crc64(); crc2.Append(new byte[] { 1, 2, 3, 4 }); crc2.Append(new byte[] { 5, 6, 7, 8 }); @@ -184,7 +184,7 @@ public void Crc64_AppendInChunks_SameAsFull() [Test] public void Crc64_GetHashAndReset_ClearsState() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); crc.Append(new byte[] { 1, 2, 3 }); byte[] hash = crc.GetHashAndReset(); Assert.AreEqual(8, hash.Length); @@ -194,14 +194,14 @@ public void Crc64_GetHashAndReset_ClearsState() [Test] public void Crc64_HashLengthInBytes_Is8() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); Assert.AreEqual(8, crc.HashLengthInBytes); } [Test] public void Crc64_GetCurrentHashTwice_SameResult() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); crc.Append(new byte[] { 42 }); byte[] hash1 = crc.GetCurrentHash(); byte[] hash2 = crc.GetCurrentHash(); @@ -211,7 +211,7 @@ public void Crc64_GetCurrentHashTwice_SameResult() [Test] public void Crc64_AppendByteArray_Null_Throws() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); Assert.Throws(() => { crc.Append((byte[])null); @@ -221,7 +221,7 @@ public void Crc64_AppendByteArray_Null_Throws() [Test] public void Crc64_AppendStream_Null_Throws() { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); Assert.Throws(() => { crc.Append((Stream)null); @@ -232,7 +232,7 @@ public void Crc64_AppendStream_Null_Throws() public void Crc64_TryHash_DestinationTooSmall_ReturnsFalse() { Span dest = stackalloc byte[4]; - bool result = Utility.Verifier.Crc64.TryHash(new byte[] { 1 }, dest, out int written); + bool result = VerifierUtility.Crc64.TryHash(new byte[] { 1 }, dest, out int written); Assert.IsFalse(result); Assert.AreEqual(0, written); } @@ -242,7 +242,7 @@ public void Crc64_TryHash_DestinationLargeEnough_ReturnsTrue() { Span dest = stackalloc byte[8]; ReadOnlySpan source = new ReadOnlySpan(new byte[] { 1, 2, 3 }); - bool result = Utility.Verifier.Crc64.TryHash(source, dest, out int written); + bool result = VerifierUtility.Crc64.TryHash(source, dest, out int written); Assert.IsTrue(result); Assert.AreEqual(8, written); } @@ -253,7 +253,7 @@ public void Crc64_AppendStream() byte[] data = Encoding.ASCII.GetBytes("stream test"); using (var stream = new MemoryStream(data)) { - var crc = new Utility.Verifier.Crc64(); + var crc = new VerifierUtility.Crc64(); crc.Append(stream); byte[] hash = crc.GetCurrentHash(); Assert.AreEqual(8, hash.Length); @@ -262,4 +262,4 @@ public void Crc64_AppendStream() #endregion } -} +} \ No newline at end of file