From aeb1ff29f3e9269f82cf99e6aa5636f551cb037f Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Sat, 1 Apr 2023 17:22:44 +0800 Subject: [PATCH] Update Update --- Assets/Scenes/main.unity | 12 +- .../Inspector/BaseComponentInspector.cs | 302 +++++++++ .../Inspector/BaseComponentInspector.cs.meta | 3 + Assets/TEngine/Editor/UI/ScriptGenerator.cs | 2 +- Assets/TEngine/Editor/Utility.meta | 3 + .../Editor/Utility/ConfigPathAttribute.cs | 11 + .../Utility/ConfigPathAttribute.cs.meta | 3 + .../TEngine/Editor/Utility/GetAssetHelper.cs | 41 ++ .../Editor/Utility/GetAssetHelper.cs.meta | 3 + .../Utility/LogScriptingDefineSymbols.cs | 172 ++++++ .../Utility/LogScriptingDefineSymbols.cs.meta | 3 + Assets/TEngine/Editor/Utility/OpenFolder.cs | 84 +++ .../TEngine/Editor/Utility/OpenFolder.cs.meta | 3 + .../Editor/Utility/ProfilerDefineSymbols.cs | 41 ++ .../Utility/ProfilerDefineSymbols.cs.meta | 3 + .../Editor/Utility/ScriptingDefineSymbols.cs | 150 +++++ .../Utility/ScriptingDefineSymbols.cs.meta | 3 + Assets/TEngine/Editor/Utility/Type.cs | 129 ++++ Assets/TEngine/Editor/Utility/Type.cs.meta | 3 + Assets/TEngine/Runtime/BaseComponent.cs | 337 ++++++++++ Assets/TEngine/Runtime/BaseComponent.cs.meta | 3 + .../Runtime/GameFramework/GameEntry.cs | 139 +++++ .../Runtime/GameFramework/GameEntry.cs.meta | 3 + .../GameFramework/GameFrameworkComponent.cs | 18 + .../GameFrameworkComponent.cs.meta | 3 + .../GameFramework/Log/GameFrameworkLog.cs | 2 +- .../Runtime/GameFramework/ShutdownType.cs | 23 + .../GameFramework/ShutdownType.cs.meta | 3 + .../Runtime/GameFramework/Utility.meta | 8 + .../Utility/Utility.Assembly.cs | 0 .../Utility/Utility.Assembly.cs.meta | 0 .../Utility.Compression.ICompressionHelper.cs | 0 ...ity.Compression.ICompressionHelper.cs.meta | 0 .../Utility/Utility.Compression.cs | 0 .../Utility/Utility.Compression.cs.meta | 0 .../Utility/Utility.Converter.cs | 0 .../Utility/Utility.Converter.cs.meta | 0 .../Utility/Utility.Encryption.cs | 0 .../Utility/Utility.Encryption.cs.meta | 0 .../Utility/Utility.File.cs | 0 .../Utility/Utility.File.cs.meta | 0 .../Utility/Utility.Folder.cs | 0 .../Utility/Utility.Folder.cs.meta | 0 .../Utility/Utility.Json.IJsonHelper.cs | 0 .../Utility/Utility.Json.IJsonHelper.cs.meta | 0 .../Utility/Utility.Json.cs | 0 .../Utility/Utility.Json.cs.meta | 0 .../Utility/Utility.Marshal.cs | 0 .../Utility/Utility.Marshal.cs.meta | 0 .../Utility/Utility.Path.cs | 0 .../Utility/Utility.Path.cs.meta | 0 .../Utility/Utility.Random.cs | 0 .../Utility/Utility.Random.cs.meta | 0 .../Utility/Utility.Text.ITextHelper.cs | 0 .../Utility/Utility.Text.ITextHelper.cs.meta | 0 .../Utility/Utility.Text.cs | 0 .../Utility/Utility.Text.cs.meta | 0 .../Utility/Utility.Unity.cs | 0 .../Utility/Utility.Unity.cs.meta | 0 .../Utility/Utility.Verifier.Crc32.cs | 0 .../Utility/Utility.Verifier.Crc32.cs.meta | 0 .../Utility/Utility.Verifier.cs | 0 .../Utility/Utility.Verifier.cs.meta | 0 .../{ => GameFramework}/Utility/Utility.cs | 0 .../Utility/Utility.cs.meta | 0 Assets/TEngine/Runtime/Localization.meta | 3 + .../TEngine/Runtime/Localization/Language.cs | 263 ++++++++ .../Runtime/Localization/Language.cs.meta | 3 + Assets/TEngine/Runtime/Utility.meta | 2 +- .../Runtime/Utility/BinaryExtension.cs | 185 ++++++ .../Runtime/Utility/BinaryExtension.cs.meta | 11 + Assets/TEngine/Runtime/Utility/DUnityUtil.cs | 248 ++++++++ .../Runtime/Utility/DUnityUtil.cs.meta | 11 + .../Utility/DefaultCompressionHelper.cs | 204 ++++++ .../Utility/DefaultCompressionHelper.cs.meta | 11 + .../Runtime/Utility/DefaultJsonHelper.cs | 43 ++ .../Runtime/Utility/DefaultJsonHelper.cs.meta | 11 + .../Runtime/Utility/DefaultLogHelper.cs | 40 ++ .../Runtime/Utility/DefaultLogHelper.cs.meta | 11 + .../Runtime/Utility/DefaultTextHelper.cs | 584 ++++++++++++++++++ .../Runtime/Utility/DefaultTextHelper.cs.meta | 11 + .../Runtime/Utility/DefaultVersionHelper.cs | 32 + .../Utility/DefaultVersionHelper.cs.meta | 11 + Assets/TEngine/Runtime/Utility/Helper.cs | 68 ++ Assets/TEngine/Runtime/Utility/Helper.cs.meta | 11 + .../Runtime/Utility/StringExtension.cs | 59 ++ .../Runtime/Utility/StringExtension.cs.meta | 11 + .../TEngine/Runtime/Utility/UnityExtension.cs | 340 ++++++++++ .../Runtime/Utility/UnityExtension.cs.meta | 11 + Assets/TEngine/Runtime/Version.meta | 3 + .../Runtime/Version/Version.IVersionHelper.cs | 27 + .../Version/Version.IVersionHelper.cs.meta | 3 + Assets/TEngine/Runtime/Version/Version.cs | 58 ++ .../TEngine/Runtime/Version/Version.cs.meta | 3 + 94 files changed, 3784 insertions(+), 4 deletions(-) create mode 100644 Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs create mode 100644 Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs.meta create mode 100644 Assets/TEngine/Editor/Utility.meta create mode 100644 Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs create mode 100644 Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/GetAssetHelper.cs create mode 100644 Assets/TEngine/Editor/Utility/GetAssetHelper.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs create mode 100644 Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/OpenFolder.cs create mode 100644 Assets/TEngine/Editor/Utility/OpenFolder.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs create mode 100644 Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs create mode 100644 Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs.meta create mode 100644 Assets/TEngine/Editor/Utility/Type.cs create mode 100644 Assets/TEngine/Editor/Utility/Type.cs.meta create mode 100644 Assets/TEngine/Runtime/BaseComponent.cs create mode 100644 Assets/TEngine/Runtime/BaseComponent.cs.meta create mode 100644 Assets/TEngine/Runtime/GameFramework/GameEntry.cs create mode 100644 Assets/TEngine/Runtime/GameFramework/GameEntry.cs.meta create mode 100644 Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs create mode 100644 Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs.meta create mode 100644 Assets/TEngine/Runtime/GameFramework/ShutdownType.cs create mode 100644 Assets/TEngine/Runtime/GameFramework/ShutdownType.cs.meta create mode 100644 Assets/TEngine/Runtime/GameFramework/Utility.meta rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Assembly.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Assembly.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Compression.ICompressionHelper.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Compression.ICompressionHelper.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Compression.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Compression.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Converter.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Converter.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Encryption.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Encryption.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.File.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.File.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Folder.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Folder.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Json.IJsonHelper.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Json.IJsonHelper.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Json.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Json.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Marshal.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Marshal.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Path.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Path.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Random.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Random.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Text.ITextHelper.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Text.ITextHelper.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Text.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Text.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Unity.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Unity.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Verifier.Crc32.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Verifier.Crc32.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Verifier.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.Verifier.cs.meta (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.cs (100%) rename Assets/TEngine/Runtime/{ => GameFramework}/Utility/Utility.cs.meta (100%) create mode 100644 Assets/TEngine/Runtime/Localization.meta create mode 100644 Assets/TEngine/Runtime/Localization/Language.cs create mode 100644 Assets/TEngine/Runtime/Localization/Language.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/BinaryExtension.cs create mode 100644 Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DUnityUtil.cs create mode 100644 Assets/TEngine/Runtime/Utility/DUnityUtil.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs create mode 100644 Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs create mode 100644 Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs create mode 100644 Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs create mode 100644 Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs create mode 100644 Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/Helper.cs create mode 100644 Assets/TEngine/Runtime/Utility/Helper.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/StringExtension.cs create mode 100644 Assets/TEngine/Runtime/Utility/StringExtension.cs.meta create mode 100644 Assets/TEngine/Runtime/Utility/UnityExtension.cs create mode 100644 Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta create mode 100644 Assets/TEngine/Runtime/Version.meta create mode 100644 Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs create mode 100644 Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs.meta create mode 100644 Assets/TEngine/Runtime/Version/Version.cs create mode 100644 Assets/TEngine/Runtime/Version/Version.cs.meta diff --git a/Assets/Scenes/main.unity b/Assets/Scenes/main.unity index dbe7e2f5..0b0bc483 100644 --- a/Assets/Scenes/main.unity +++ b/Assets/Scenes/main.unity @@ -416,9 +416,19 @@ MonoBehaviour: m_GameObject: {fileID: 2061060681} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9b7cdcfd6cb40fe489faae0b85038cb9, type: 3} + m_Script: {fileID: 11500000, guid: 564a45007d8645cf96d33bb52471acd5, type: 3} m_Name: m_EditorClassIdentifier: + m_EditorLanguage: 0 + m_TextHelperTypeName: TEngine.DefaultTextHelper + m_VersionHelperTypeName: TEngine.DefaultVersionHelper + m_LogHelperTypeName: TEngine.TEngineLogHelper + m_CompressionHelperTypeName: TEngine.DefaultCompressionHelper + m_JsonHelperTypeName: TEngine.DefaultJsonHelper + m_FrameRate: 120 + m_GameSpeed: 1 + m_RunInBackground: 1 + m_NeverSleep: 1 --- !u!1 &2108959335 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs b/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs new file mode 100644 index 00000000..875a283c --- /dev/null +++ b/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs @@ -0,0 +1,302 @@ +using TEngine; +using System.Collections.Generic; +using TEngine.Editor.Inspector; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor +{ + [CustomEditor(typeof(BaseComponent))] + internal sealed class BaseComponentInspector : GameFrameworkInspector + { + private const string NoneOptionName = ""; + private static readonly float[] GameSpeed = new float[] { 0f, 0.01f, 0.1f, 0.25f, 0.5f, 1f, 1.5f, 2f, 4f, 8f }; + private static readonly string[] GameSpeedForDisplay = new string[] { "0x", "0.01x", "0.1x", "0.25x", "0.5x", "1x", "1.5x", "2x", "4x", "8x" }; + + private SerializedProperty m_EditorLanguage = null; + private SerializedProperty m_TextHelperTypeName = null; + private SerializedProperty m_VersionHelperTypeName = null; + private SerializedProperty m_LogHelperTypeName = null; + private SerializedProperty m_CompressionHelperTypeName = null; + private SerializedProperty m_JsonHelperTypeName = null; + private SerializedProperty m_FrameRate = null; + private SerializedProperty m_GameSpeed = null; + private SerializedProperty m_RunInBackground = null; + private SerializedProperty m_NeverSleep = null; + + private string[] m_TextHelperTypeNames = null; + private int m_TextHelperTypeNameIndex = 0; + private string[] m_VersionHelperTypeNames = null; + private int m_VersionHelperTypeNameIndex = 0; + private string[] m_LogHelperTypeNames = null; + private int m_LogHelperTypeNameIndex = 0; + private string[] m_CompressionHelperTypeNames = null; + private int m_CompressionHelperTypeNameIndex = 0; + private string[] m_JsonHelperTypeNames = null; + private int m_JsonHelperTypeNameIndex = 0; + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + serializedObject.Update(); + + BaseComponent t = (BaseComponent)target; + + EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); + { + EditorGUILayout.BeginVertical("box"); + { + EditorGUILayout.LabelField("Global Helpers", EditorStyles.boldLabel); + + int textHelperSelectedIndex = EditorGUILayout.Popup("Text Helper", m_TextHelperTypeNameIndex, m_TextHelperTypeNames); + if (textHelperSelectedIndex != m_TextHelperTypeNameIndex) + { + m_TextHelperTypeNameIndex = textHelperSelectedIndex; + m_TextHelperTypeName.stringValue = textHelperSelectedIndex <= 0 ? null : m_TextHelperTypeNames[textHelperSelectedIndex]; + } + + int versionHelperSelectedIndex = EditorGUILayout.Popup("Version Helper", m_VersionHelperTypeNameIndex, m_VersionHelperTypeNames); + if (versionHelperSelectedIndex != m_VersionHelperTypeNameIndex) + { + m_VersionHelperTypeNameIndex = versionHelperSelectedIndex; + m_VersionHelperTypeName.stringValue = versionHelperSelectedIndex <= 0 ? null : m_VersionHelperTypeNames[versionHelperSelectedIndex]; + } + + int logHelperSelectedIndex = EditorGUILayout.Popup("Log Helper", m_LogHelperTypeNameIndex, m_LogHelperTypeNames); + if (logHelperSelectedIndex != m_LogHelperTypeNameIndex) + { + m_LogHelperTypeNameIndex = logHelperSelectedIndex; + m_LogHelperTypeName.stringValue = logHelperSelectedIndex <= 0 ? null : m_LogHelperTypeNames[logHelperSelectedIndex]; + } + + int compressionHelperSelectedIndex = EditorGUILayout.Popup("Compression Helper", m_CompressionHelperTypeNameIndex, m_CompressionHelperTypeNames); + if (compressionHelperSelectedIndex != m_CompressionHelperTypeNameIndex) + { + m_CompressionHelperTypeNameIndex = compressionHelperSelectedIndex; + m_CompressionHelperTypeName.stringValue = compressionHelperSelectedIndex <= 0 ? null : m_CompressionHelperTypeNames[compressionHelperSelectedIndex]; + } + + int jsonHelperSelectedIndex = EditorGUILayout.Popup("JSON Helper", m_JsonHelperTypeNameIndex, m_JsonHelperTypeNames); + if (jsonHelperSelectedIndex != m_JsonHelperTypeNameIndex) + { + m_JsonHelperTypeNameIndex = jsonHelperSelectedIndex; + m_JsonHelperTypeName.stringValue = jsonHelperSelectedIndex <= 0 ? null : m_JsonHelperTypeNames[jsonHelperSelectedIndex]; + } + } + EditorGUILayout.EndVertical(); + } + EditorGUI.EndDisabledGroup(); + + int frameRate = EditorGUILayout.IntSlider("Frame Rate", m_FrameRate.intValue, 1, 120); + if (frameRate != m_FrameRate.intValue) + { + if (EditorApplication.isPlaying) + { + t.FrameRate = frameRate; + } + else + { + m_FrameRate.intValue = frameRate; + } + } + + EditorGUILayout.BeginVertical("box"); + { + float gameSpeed = EditorGUILayout.Slider("Game Speed", m_GameSpeed.floatValue, 0f, 8f); + int selectedGameSpeed = GUILayout.SelectionGrid(GetSelectedGameSpeed(gameSpeed), GameSpeedForDisplay, 5); + if (selectedGameSpeed >= 0) + { + gameSpeed = GetGameSpeed(selectedGameSpeed); + } + + if (gameSpeed != m_GameSpeed.floatValue) + { + if (EditorApplication.isPlaying) + { + t.GameSpeed = gameSpeed; + } + else + { + m_GameSpeed.floatValue = gameSpeed; + } + } + } + EditorGUILayout.EndVertical(); + + bool runInBackground = EditorGUILayout.Toggle("Run in Background", m_RunInBackground.boolValue); + if (runInBackground != m_RunInBackground.boolValue) + { + if (EditorApplication.isPlaying) + { + t.RunInBackground = runInBackground; + } + else + { + m_RunInBackground.boolValue = runInBackground; + } + } + + bool neverSleep = EditorGUILayout.Toggle("Never Sleep", m_NeverSleep.boolValue); + if (neverSleep != m_NeverSleep.boolValue) + { + if (EditorApplication.isPlaying) + { + t.NeverSleep = neverSleep; + } + else + { + m_NeverSleep.boolValue = neverSleep; + } + } + + serializedObject.ApplyModifiedProperties(); + } + + protected override void OnCompileComplete() + { + base.OnCompileComplete(); + + RefreshTypeNames(); + } + + private void OnEnable() + { + m_EditorLanguage = serializedObject.FindProperty("m_EditorLanguage"); + m_TextHelperTypeName = serializedObject.FindProperty("m_TextHelperTypeName"); + m_VersionHelperTypeName = serializedObject.FindProperty("m_VersionHelperTypeName"); + m_LogHelperTypeName = serializedObject.FindProperty("m_LogHelperTypeName"); + m_CompressionHelperTypeName = serializedObject.FindProperty("m_CompressionHelperTypeName"); + m_JsonHelperTypeName = serializedObject.FindProperty("m_JsonHelperTypeName"); + m_FrameRate = serializedObject.FindProperty("m_FrameRate"); + m_GameSpeed = serializedObject.FindProperty("m_GameSpeed"); + m_RunInBackground = serializedObject.FindProperty("m_RunInBackground"); + m_NeverSleep = serializedObject.FindProperty("m_NeverSleep"); + + RefreshTypeNames(); + } + + private void RefreshTypeNames() + { + List textHelperTypeNames = new List + { + NoneOptionName + }; + + textHelperTypeNames.AddRange(Type.GetRuntimeTypeNames(typeof(Utility.Text.ITextHelper))); + m_TextHelperTypeNames = textHelperTypeNames.ToArray(); + m_TextHelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_TextHelperTypeName.stringValue)) + { + m_TextHelperTypeNameIndex = textHelperTypeNames.IndexOf(m_TextHelperTypeName.stringValue); + if (m_TextHelperTypeNameIndex <= 0) + { + m_TextHelperTypeNameIndex = 0; + m_TextHelperTypeName.stringValue = null; + } + } + + List versionHelperTypeNames = new List + { + NoneOptionName + }; + + versionHelperTypeNames.AddRange(Type.GetRuntimeTypeNames(typeof(Version.IVersionHelper))); + m_VersionHelperTypeNames = versionHelperTypeNames.ToArray(); + m_VersionHelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_VersionHelperTypeName.stringValue)) + { + m_VersionHelperTypeNameIndex = versionHelperTypeNames.IndexOf(m_VersionHelperTypeName.stringValue); + if (m_VersionHelperTypeNameIndex <= 0) + { + m_VersionHelperTypeNameIndex = 0; + m_VersionHelperTypeName.stringValue = null; + } + } + + List logHelperTypeNames = new List + { + NoneOptionName + }; + + logHelperTypeNames.AddRange(Type.GetRuntimeTypeNames(typeof(GameFrameworkLog.ILogHelper))); + m_LogHelperTypeNames = logHelperTypeNames.ToArray(); + m_LogHelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_LogHelperTypeName.stringValue)) + { + m_LogHelperTypeNameIndex = logHelperTypeNames.IndexOf(m_LogHelperTypeName.stringValue); + if (m_LogHelperTypeNameIndex <= 0) + { + m_LogHelperTypeNameIndex = 0; + m_LogHelperTypeName.stringValue = null; + } + } + + List compressionHelperTypeNames = new List + { + NoneOptionName + }; + + compressionHelperTypeNames.AddRange(Type.GetRuntimeTypeNames(typeof(Utility.Compression.ICompressionHelper))); + m_CompressionHelperTypeNames = compressionHelperTypeNames.ToArray(); + m_CompressionHelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_CompressionHelperTypeName.stringValue)) + { + m_CompressionHelperTypeNameIndex = compressionHelperTypeNames.IndexOf(m_CompressionHelperTypeName.stringValue); + if (m_CompressionHelperTypeNameIndex <= 0) + { + m_CompressionHelperTypeNameIndex = 0; + m_CompressionHelperTypeName.stringValue = null; + } + } + + List jsonHelperTypeNames = new List + { + NoneOptionName + }; + + jsonHelperTypeNames.AddRange(Type.GetRuntimeTypeNames(typeof(Utility.Json.IJsonHelper))); + m_JsonHelperTypeNames = jsonHelperTypeNames.ToArray(); + m_JsonHelperTypeNameIndex = 0; + if (!string.IsNullOrEmpty(m_JsonHelperTypeName.stringValue)) + { + m_JsonHelperTypeNameIndex = jsonHelperTypeNames.IndexOf(m_JsonHelperTypeName.stringValue); + if (m_JsonHelperTypeNameIndex <= 0) + { + m_JsonHelperTypeNameIndex = 0; + m_JsonHelperTypeName.stringValue = null; + } + } + + serializedObject.ApplyModifiedProperties(); + } + + private float GetGameSpeed(int selectedGameSpeed) + { + if (selectedGameSpeed < 0) + { + return GameSpeed[0]; + } + + if (selectedGameSpeed >= GameSpeed.Length) + { + return GameSpeed[GameSpeed.Length - 1]; + } + + return GameSpeed[selectedGameSpeed]; + } + + private int GetSelectedGameSpeed(float gameSpeed) + { + for (int i = 0; i < GameSpeed.Length; i++) + { + if (gameSpeed == GameSpeed[i]) + { + return i; + } + } + + return -1; + } + } +} diff --git a/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs.meta b/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs.meta new file mode 100644 index 00000000..978670e3 --- /dev/null +++ b/Assets/TEngine/Editor/Inspector/BaseComponentInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d8acc7d98be34139882c0c02558e8d26 +timeCreated: 1680338392 \ No newline at end of file diff --git a/Assets/TEngine/Editor/UI/ScriptGenerator.cs b/Assets/TEngine/Editor/UI/ScriptGenerator.cs index f7a289dc..16f61aea 100644 --- a/Assets/TEngine/Editor/UI/ScriptGenerator.cs +++ b/Assets/TEngine/Editor/UI/ScriptGenerator.cs @@ -73,7 +73,7 @@ namespace TEngine.Editor.UI strFile.Append("using UnityEngine;\n"); strFile.Append("using UnityEngine.UI;\n"); - strFile.Append("using UnityGameFramework.Runtime;\n\n"); + strFile.Append("using TEngine;\n\n"); strFile.Append("namespace GameMain\n"); strFile.Append("{\n"); strFile.Append("\tclass " + root.name + " : UIFormLogic\n"); diff --git a/Assets/TEngine/Editor/Utility.meta b/Assets/TEngine/Editor/Utility.meta new file mode 100644 index 00000000..e168b730 --- /dev/null +++ b/Assets/TEngine/Editor/Utility.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9336045122f6433da12f0b4cea097333 +timeCreated: 1680338489 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs b/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs new file mode 100644 index 00000000..f65bed2f --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs @@ -0,0 +1,11 @@ +using System; + +namespace TEngine.Editor +{ + /// + /// 配置路径属性。 + /// + public abstract class ConfigPathAttribute : Attribute + { + } +} diff --git a/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs.meta b/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs.meta new file mode 100644 index 00000000..b21fcaf4 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ConfigPathAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6efbdd76bcb94dbf93f8d05c570df909 +timeCreated: 1680340111 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/GetAssetHelper.cs b/Assets/TEngine/Editor/Utility/GetAssetHelper.cs new file mode 100644 index 00000000..c1e72dce --- /dev/null +++ b/Assets/TEngine/Editor/Utility/GetAssetHelper.cs @@ -0,0 +1,41 @@ +using System.Linq; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor +{ + /// + /// 获取资源路径相关的实用函数。 + /// + public static class GetAssetHelper + { + [MenuItem("Assets/Get Asset Path", priority = 3)] + static void GetAssetPath() + { + UnityEngine.Object selObj = Selection.activeObject; + + if (selObj != null) + { + string assetPath = AssetDatabase.GetAssetPath(selObj); + EditorGUIUtility.systemCopyBuffer = assetPath; + Debug.Log($"Asset path is {assetPath}"); + } + } + + [MenuItem("Assets/Get Addressable Path", priority = 3)] + static void GetAddressablePath() + { + UnityEngine.Object selObj = Selection.activeObject; + + if (selObj != null) + { + string assetPath = AssetDatabase.GetAssetPath(selObj); + var split = assetPath.Split('/'); + var name = split.Last(); + assetPath = name.Split('.').First(); + EditorGUIUtility.systemCopyBuffer = assetPath; + Debug.Log($"Addressable path is {assetPath}"); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/GetAssetHelper.cs.meta b/Assets/TEngine/Editor/Utility/GetAssetHelper.cs.meta new file mode 100644 index 00000000..0dbd5baf --- /dev/null +++ b/Assets/TEngine/Editor/Utility/GetAssetHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f55b5ab54785467dbd9bd2b5e46182ea +timeCreated: 1680340111 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs b/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs new file mode 100644 index 00000000..46db70dc --- /dev/null +++ b/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs @@ -0,0 +1,172 @@ +using UnityEditor; + +namespace TEngine.Editor +{ + /// + /// 日志脚本宏定义。 + /// + public static class LogScriptingDefineSymbols + { + private const string EnableLogScriptingDefineSymbol = "ENABLE_LOG"; + private const string EnableDebugAndAboveLogScriptingDefineSymbol = "ENABLE_DEBUG_AND_ABOVE_LOG"; + private const string EnableInfoAndAboveLogScriptingDefineSymbol = "ENABLE_INFO_AND_ABOVE_LOG"; + private const string EnableWarningAndAboveLogScriptingDefineSymbol = "ENABLE_WARNING_AND_ABOVE_LOG"; + private const string EnableErrorAndAboveLogScriptingDefineSymbol = "ENABLE_ERROR_AND_ABOVE_LOG"; + private const string EnableFatalAndAboveLogScriptingDefineSymbol = "ENABLE_FATAL_AND_ABOVE_LOG"; + private const string EnableDebugLogScriptingDefineSymbol = "ENABLE_DEBUG_LOG"; + private const string EnableInfoLogScriptingDefineSymbol = "ENABLE_INFO_LOG"; + private const string EnableWarningLogScriptingDefineSymbol = "ENABLE_WARNING_LOG"; + private const string EnableErrorLogScriptingDefineSymbol = "ENABLE_ERROR_LOG"; + private const string EnableFatalLogScriptingDefineSymbol = "ENABLE_FATAL_LOG"; + + private static readonly string[] AboveLogScriptingDefineSymbols = new string[] + { + EnableDebugAndAboveLogScriptingDefineSymbol, + EnableInfoAndAboveLogScriptingDefineSymbol, + EnableWarningAndAboveLogScriptingDefineSymbol, + EnableErrorAndAboveLogScriptingDefineSymbol, + EnableFatalAndAboveLogScriptingDefineSymbol + }; + + private static readonly string[] SpecifyLogScriptingDefineSymbols = new string[] + { + EnableDebugLogScriptingDefineSymbol, + EnableInfoLogScriptingDefineSymbol, + EnableWarningLogScriptingDefineSymbol, + EnableErrorLogScriptingDefineSymbol, + EnableFatalLogScriptingDefineSymbol + }; + + /// + /// 禁用所有日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Disable All Logs", false, 30)] + public static void DisableAllLogs() + { + ScriptingDefineSymbols.RemoveScriptingDefineSymbol(EnableLogScriptingDefineSymbol); + + foreach (string specifyLogScriptingDefineSymbol in SpecifyLogScriptingDefineSymbols) + { + ScriptingDefineSymbols.RemoveScriptingDefineSymbol(specifyLogScriptingDefineSymbol); + } + + foreach (string aboveLogScriptingDefineSymbol in AboveLogScriptingDefineSymbols) + { + ScriptingDefineSymbols.RemoveScriptingDefineSymbol(aboveLogScriptingDefineSymbol); + } + } + + /// + /// 开启所有日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable All Logs", false, 31)] + public static void EnableAllLogs() + { + DisableAllLogs(); + ScriptingDefineSymbols.AddScriptingDefineSymbol(EnableLogScriptingDefineSymbol); + } + + /// + /// 开启调试及以上级别的日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable Debug And Above Logs", false, 32)] + public static void EnableDebugAndAboveLogs() + { + SetAboveLogScriptingDefineSymbol(EnableDebugAndAboveLogScriptingDefineSymbol); + } + + /// + /// 开启信息及以上级别的日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable Info And Above Logs", false, 33)] + public static void EnableInfoAndAboveLogs() + { + SetAboveLogScriptingDefineSymbol(EnableInfoAndAboveLogScriptingDefineSymbol); + } + + /// + /// 开启警告及以上级别的日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable Warning And Above Logs", false, 34)] + public static void EnableWarningAndAboveLogs() + { + SetAboveLogScriptingDefineSymbol(EnableWarningAndAboveLogScriptingDefineSymbol); + } + + /// + /// 开启错误及以上级别的日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable Error And Above Logs", false, 35)] + public static void EnableErrorAndAboveLogs() + { + SetAboveLogScriptingDefineSymbol(EnableErrorAndAboveLogScriptingDefineSymbol); + } + + /// + /// 开启严重错误及以上级别的日志脚本宏定义。 + /// + [MenuItem("Game Framework/Log Scripting Define Symbols/Enable Fatal And Above Logs", false, 36)] + public static void EnableFatalAndAboveLogs() + { + SetAboveLogScriptingDefineSymbol(EnableFatalAndAboveLogScriptingDefineSymbol); + } + + /// + /// 设置日志脚本宏定义。 + /// + /// 要设置的日志脚本宏定义。 + public static void SetAboveLogScriptingDefineSymbol(string aboveLogScriptingDefineSymbol) + { + if (string.IsNullOrEmpty(aboveLogScriptingDefineSymbol)) + { + return; + } + + foreach (string i in AboveLogScriptingDefineSymbols) + { + if (i == aboveLogScriptingDefineSymbol) + { + DisableAllLogs(); + ScriptingDefineSymbols.AddScriptingDefineSymbol(aboveLogScriptingDefineSymbol); + return; + } + } + } + + /// + /// 设置日志脚本宏定义。 + /// + /// 要设置的日志脚本宏定义。 + public static void SetSpecifyLogScriptingDefineSymbols(string[] specifyLogScriptingDefineSymbols) + { + if (specifyLogScriptingDefineSymbols == null || specifyLogScriptingDefineSymbols.Length <= 0) + { + return; + } + + bool removed = false; + foreach (string specifyLogScriptingDefineSymbol in specifyLogScriptingDefineSymbols) + { + if (string.IsNullOrEmpty(specifyLogScriptingDefineSymbol)) + { + continue; + } + + foreach (string i in SpecifyLogScriptingDefineSymbols) + { + if (i == specifyLogScriptingDefineSymbol) + { + if (!removed) + { + removed = true; + DisableAllLogs(); + } + + ScriptingDefineSymbols.AddScriptingDefineSymbol(specifyLogScriptingDefineSymbol); + break; + } + } + } + } + } +} diff --git a/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs.meta b/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs.meta new file mode 100644 index 00000000..2d428913 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/LogScriptingDefineSymbols.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3e23fe1ee0074f3291860e98b7a6064a +timeCreated: 1680338526 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/OpenFolder.cs b/Assets/TEngine/Editor/Utility/OpenFolder.cs new file mode 100644 index 00000000..1b128b2e --- /dev/null +++ b/Assets/TEngine/Editor/Utility/OpenFolder.cs @@ -0,0 +1,84 @@ +using TEngine; +using System.Diagnostics; +using UnityEditor; +using UnityEngine; + +namespace TEngine.Editor +{ + /// + /// 打开文件夹相关的实用函数。 + /// + public static class OpenFolder + { + /// + /// 打开 Data Path 文件夹。 + /// + [MenuItem("Game Framework/Open Folder/Data Path", false, 10)] + public static void OpenFolderDataPath() + { + Execute(Application.dataPath); + } + + /// + /// 打开 Persistent Data Path 文件夹。 + /// + [MenuItem("Game Framework/Open Folder/Persistent Data Path", false, 11)] + public static void OpenFolderPersistentDataPath() + { + Execute(Application.persistentDataPath); + } + + /// + /// 打开 Streaming Assets Path 文件夹。 + /// + [MenuItem("Game Framework/Open Folder/Streaming Assets Path", false, 12)] + public static void OpenFolderStreamingAssetsPath() + { + Execute(Application.streamingAssetsPath); + } + + /// + /// 打开 Temporary Cache Path 文件夹。 + /// + [MenuItem("Game Framework/Open Folder/Temporary Cache Path", false, 13)] + public static void OpenFolderTemporaryCachePath() + { + Execute(Application.temporaryCachePath); + } + +#if UNITY_2018_3_OR_NEWER + + /// + /// 打开 Console Log Path 文件夹。 + /// + [MenuItem("Game Framework/Open Folder/Console Log Path", false, 14)] + public static void OpenFolderConsoleLogPath() + { + Execute(System.IO.Path.GetDirectoryName(Application.consoleLogPath)); + } + +#endif + + /// + /// 打开指定路径的文件夹。 + /// + /// 要打开的文件夹的路径。 + public static void Execute(string folder) + { + folder = Utility.Text.Format("\"{0}\"", folder); + switch (Application.platform) + { + case RuntimePlatform.WindowsEditor: + Process.Start("Explorer.exe", folder.Replace('/', '\\')); + break; + + case RuntimePlatform.OSXEditor: + Process.Start("open", folder); + break; + + default: + throw new GameFrameworkException(Utility.Text.Format("Not support open folder on '{0}' platform.", Application.platform)); + } + } + } +} diff --git a/Assets/TEngine/Editor/Utility/OpenFolder.cs.meta b/Assets/TEngine/Editor/Utility/OpenFolder.cs.meta new file mode 100644 index 00000000..bf75288d --- /dev/null +++ b/Assets/TEngine/Editor/Utility/OpenFolder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fad1fb9581db4034989ecc847f06ae09 +timeCreated: 1680338526 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs b/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs new file mode 100644 index 00000000..3fdd5cd6 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs @@ -0,0 +1,41 @@ +using UnityEditor; + +namespace TEngine.Editor +{ + public class ProfilerDefineSymbols + { + private const string EnableFirstProfiler = "FIRST_PROFILER"; + private const string EnableDinProFiler = "DIN_PROFILER"; + + private static readonly string[] AllProfilerDefineSymbols = new string[] + { + EnableFirstProfiler, + EnableDinProFiler, + }; + + /// + /// 禁用所有日志脚本宏定义。 + /// + [MenuItem("Game Framework/Profiler Define Symbols/Disable All Logs", false, 30)] + public static void DisableAllLogs() + { + foreach (string aboveLogScriptingDefineSymbol in AllProfilerDefineSymbols) + { + ScriptingDefineSymbols.RemoveScriptingDefineSymbol(aboveLogScriptingDefineSymbol); + } + } + + /// + /// 开启所有日志脚本宏定义。 + /// + [MenuItem("Game Framework/Profiler Define Symbols/Enable All Logs", false, 31)] + public static void EnableAllLogs() + { + DisableAllLogs(); + foreach (string aboveLogScriptingDefineSymbol in AllProfilerDefineSymbols) + { + ScriptingDefineSymbols.AddScriptingDefineSymbol(aboveLogScriptingDefineSymbol); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs.meta b/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs.meta new file mode 100644 index 00000000..edf0de9d --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ProfilerDefineSymbols.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7b42362267f84f2c8926f1c48ddd900a +timeCreated: 1680338526 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs b/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs new file mode 100644 index 00000000..4166cac2 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs @@ -0,0 +1,150 @@ +using System.Collections.Generic; +using UnityEditor; + +namespace TEngine.Editor +{ + /// + /// 脚本宏定义。 + /// + public static class ScriptingDefineSymbols + { + private static readonly BuildTargetGroup[] BuildTargetGroups = new BuildTargetGroup[] + { + BuildTargetGroup.Standalone, + BuildTargetGroup.iOS, + BuildTargetGroup.Android, + BuildTargetGroup.WSA, + BuildTargetGroup.WebGL + }; + + /// + /// 检查指定平台是否存在指定的脚本宏定义。 + /// + /// 要检查脚本宏定义的平台。 + /// 要检查的脚本宏定义。 + /// 指定平台是否存在指定的脚本宏定义。 + public static bool HasScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) + { + if (string.IsNullOrEmpty(scriptingDefineSymbol)) + { + return false; + } + + string[] scriptingDefineSymbols = GetScriptingDefineSymbols(buildTargetGroup); + foreach (string i in scriptingDefineSymbols) + { + if (i == scriptingDefineSymbol) + { + return true; + } + } + + return false; + } + + /// + /// 为指定平台增加指定的脚本宏定义。 + /// + /// 要增加脚本宏定义的平台。 + /// 要增加的脚本宏定义。 + public static void AddScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) + { + if (string.IsNullOrEmpty(scriptingDefineSymbol)) + { + return; + } + + if (HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol)) + { + return; + } + + List scriptingDefineSymbols = new List(GetScriptingDefineSymbols(buildTargetGroup)) + { + scriptingDefineSymbol + }; + + SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray()); + } + + /// + /// 为指定平台移除指定的脚本宏定义。 + /// + /// 要移除脚本宏定义的平台。 + /// 要移除的脚本宏定义。 + public static void RemoveScriptingDefineSymbol(BuildTargetGroup buildTargetGroup, string scriptingDefineSymbol) + { + if (string.IsNullOrEmpty(scriptingDefineSymbol)) + { + return; + } + + if (!HasScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol)) + { + return; + } + + List scriptingDefineSymbols = new List(GetScriptingDefineSymbols(buildTargetGroup)); + while (scriptingDefineSymbols.Contains(scriptingDefineSymbol)) + { + scriptingDefineSymbols.Remove(scriptingDefineSymbol); + } + + SetScriptingDefineSymbols(buildTargetGroup, scriptingDefineSymbols.ToArray()); + } + + /// + /// 为所有平台增加指定的脚本宏定义。 + /// + /// 要增加的脚本宏定义。 + public static void AddScriptingDefineSymbol(string scriptingDefineSymbol) + { + if (string.IsNullOrEmpty(scriptingDefineSymbol)) + { + return; + } + + foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups) + { + AddScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol); + } + } + + /// + /// 为所有平台移除指定的脚本宏定义。 + /// + /// 要移除的脚本宏定义。 + public static void RemoveScriptingDefineSymbol(string scriptingDefineSymbol) + { + if (string.IsNullOrEmpty(scriptingDefineSymbol)) + { + return; + } + + foreach (BuildTargetGroup buildTargetGroup in BuildTargetGroups) + { + RemoveScriptingDefineSymbol(buildTargetGroup, scriptingDefineSymbol); + } + } + + /// + /// 获取指定平台的脚本宏定义。 + /// + /// 要获取脚本宏定义的平台。 + /// 平台的脚本宏定义。 + public static string[] GetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup) + { + return PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup).Split(';'); + } + + /// + /// 设置指定平台的脚本宏定义。 + /// + /// 要设置脚本宏定义的平台。 + /// 要设置的脚本宏定义。 + public static void SetScriptingDefineSymbols(BuildTargetGroup buildTargetGroup, string[] scriptingDefineSymbols) + { + PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Join(";", scriptingDefineSymbols)); + } + } +} diff --git a/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs.meta b/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs.meta new file mode 100644 index 00000000..c7de4e5e --- /dev/null +++ b/Assets/TEngine/Editor/Utility/ScriptingDefineSymbols.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5a472e485b93472b941ca83f2d39181d +timeCreated: 1680338526 \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/Type.cs b/Assets/TEngine/Editor/Utility/Type.cs new file mode 100644 index 00000000..c6d223d4 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/Type.cs @@ -0,0 +1,129 @@ +using System.Collections.Generic; +using System.Reflection; + +namespace TEngine.Editor +{ + /// + /// 类型相关的实用函数。 + /// + internal static class Type + { + private static readonly string[] RuntimeAssemblyNames = + { + "TEngine.Runtime", + "Assembly-CSharp", + "GameMain.Runtime", + + "GameBase", + "GameLogic", + "GameProto", + "BattleCore.Runtime", + }; + + private static readonly string[] RuntimeOrEditorAssemblyNames = + { + "TEngine.Runtime", + "Assembly-CSharp", + "TEngine.Editor", + "Assembly-CSharp-Editor", + "GameMain.Runtime", + "GameMain", + "GameMain.Editor", + "GameBase", + "GameLogic", + "GameProto", + "BattleCore.Runtime", + }; + + /// + /// 获取配置路径。 + /// + /// 配置类型。 + /// 配置路径。 + internal static string GetConfigurationPath() where T : ConfigPathAttribute + { + foreach (System.Type type in Utility.Assembly.GetTypes()) + { + if (!type.IsAbstract || !type.IsSealed) + { + continue; + } + + foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Static | BindingFlags.Public | + BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) + { + if (fieldInfo.FieldType == typeof(string) && fieldInfo.IsDefined(typeof(T), false)) + { + return (string)fieldInfo.GetValue(null); + } + } + + foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Static | BindingFlags.Public | + BindingFlags.NonPublic | + BindingFlags.DeclaredOnly)) + { + if (propertyInfo.PropertyType == typeof(string) && propertyInfo.IsDefined(typeof(T), false)) + { + return (string)propertyInfo.GetValue(null, null); + } + } + } + + return null; + } + + /// + /// 在运行时程序集中获取指定基类的所有子类的名称。 + /// + /// 基类类型。 + /// 指定基类的所有子类的名称。 + internal static string[] GetRuntimeTypeNames(System.Type typeBase) + { + return GetTypeNames(typeBase, RuntimeAssemblyNames); + } + + /// + /// 在运行时或编辑器程序集中获取指定基类的所有子类的名称。 + /// + /// 基类类型。 + /// 指定基类的所有子类的名称。 + internal static string[] GetRuntimeOrEditorTypeNames(System.Type typeBase) + { + return GetTypeNames(typeBase, RuntimeOrEditorAssemblyNames); + } + + private static string[] GetTypeNames(System.Type typeBase, string[] assemblyNames) + { + List typeNames = new List(); + foreach (string assemblyName in assemblyNames) + { + Assembly assembly = null; + try + { + assembly = Assembly.Load(assemblyName); + } + catch + { + continue; + } + + if (assembly == null) + { + continue; + } + + System.Type[] types = assembly.GetTypes(); + foreach (System.Type type in types) + { + if (type.IsClass && !type.IsAbstract && typeBase.IsAssignableFrom(type)) + { + typeNames.Add(type.FullName); + } + } + } + + typeNames.Sort(); + return typeNames.ToArray(); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/Utility/Type.cs.meta b/Assets/TEngine/Editor/Utility/Type.cs.meta new file mode 100644 index 00000000..6250a666 --- /dev/null +++ b/Assets/TEngine/Editor/Utility/Type.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e9e03a1b8db74d8fb809ec83c6e72ca8 +timeCreated: 1680338526 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/BaseComponent.cs b/Assets/TEngine/Runtime/BaseComponent.cs new file mode 100644 index 00000000..f4e3b821 --- /dev/null +++ b/Assets/TEngine/Runtime/BaseComponent.cs @@ -0,0 +1,337 @@ +using System; +using TEngine.Localization; +using UnityEngine; + +namespace TEngine +{ + /// + /// 基础组件。 + /// + [DisallowMultipleComponent] + [AddComponentMenu("Game Framework/Base")] + public sealed class BaseComponent : GameFrameworkComponent + { + private const int DefaultDpi = 96; // default windows dpi + + private float m_GameSpeedBeforePause = 1f; + + [SerializeField] + private Language m_EditorLanguage = Language.Unspecified; + + [SerializeField] + private string m_TextHelperTypeName = "TEngine.DefaultTextHelper"; + + [SerializeField] + private string m_VersionHelperTypeName = "TEngine.DefaultVersionHelper"; + + [SerializeField] + private string m_LogHelperTypeName = "TEngine.DefaultLogHelper"; + + [SerializeField] + private string m_CompressionHelperTypeName = "TEngine.DefaultCompressionHelper"; + + [SerializeField] + private string m_JsonHelperTypeName = "TEngine.DefaultJsonHelper"; + + [SerializeField] + private int m_FrameRate = 30; + + [SerializeField] + private float m_GameSpeed = 1f; + + [SerializeField] + private bool m_RunInBackground = true; + + [SerializeField] + private bool m_NeverSleep = true; + + /// + /// 获取或设置编辑器语言(仅编辑器内有效)。 + /// + public Language EditorLanguage + { + get => m_EditorLanguage; + set => m_EditorLanguage = value; + } + + /// + /// 获取或设置游戏帧率。 + /// + public int FrameRate + { + get => m_FrameRate; + set => Application.targetFrameRate = m_FrameRate = value; + } + + /// + /// 获取或设置游戏速度。 + /// + public float GameSpeed + { + get => m_GameSpeed; + set => Time.timeScale = m_GameSpeed = value >= 0f ? value : 0f; + } + + /// + /// 获取游戏是否暂停。 + /// + public bool IsGamePaused => m_GameSpeed <= 0f; + + /// + /// 获取是否正常游戏速度。 + /// + public bool IsNormalGameSpeed => Math.Abs(m_GameSpeed - 1f) < 0.01f; + + /// + /// 获取或设置是否允许后台运行。 + /// + public bool RunInBackground + { + get => m_RunInBackground; + set => Application.runInBackground = m_RunInBackground = value; + } + + /// + /// 获取或设置是否禁止休眠。 + /// + public bool NeverSleep + { + get => m_NeverSleep; + set + { + m_NeverSleep = value; + Screen.sleepTimeout = value ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; + } + } + + /// + /// 游戏框架组件初始化。 + /// + protected override void Awake() + { + base.Awake(); + + InitTextHelper(); + InitVersionHelper(); + InitLogHelper(); + Log.Info("TEngine Version: {0}", TEngine.Version.GameFrameworkVersion); + Log.Info("Game Version: {0} ({1})", TEngine.Version.GameVersion, TEngine.Version.InternalGameVersion); + Log.Info("Unity Version: {0}", Application.unityVersion); + + InitCompressionHelper(); + InitJsonHelper(); + + Utility.Converter.ScreenDpi = Screen.dpi; + if (Utility.Converter.ScreenDpi <= 0) + { + Utility.Converter.ScreenDpi = DefaultDpi; + } + + Application.targetFrameRate = m_FrameRate; + Time.timeScale = m_GameSpeed; + Application.runInBackground = m_RunInBackground; + Screen.sleepTimeout = m_NeverSleep ? SleepTimeout.NeverSleep : SleepTimeout.SystemSetting; + + Application.lowMemory += OnLowMemory; + } + + private void Start() + { + } + + private void Update() + { + GameFrameworkEntry.Update(Time.deltaTime, Time.unscaledDeltaTime); + } + + private void OnApplicationQuit() + { + Application.lowMemory -= OnLowMemory; + StopAllCoroutines(); + } + + private void OnDestroy() + { + GameFrameworkEntry.Shutdown(); + } + + /// + /// 暂停游戏。 + /// + public void PauseGame() + { + if (IsGamePaused) + { + return; + } + + m_GameSpeedBeforePause = GameSpeed; + GameSpeed = 0f; + } + + /// + /// 恢复游戏。 + /// + public void ResumeGame() + { + if (!IsGamePaused) + { + return; + } + + GameSpeed = m_GameSpeedBeforePause; + } + + /// + /// 重置为正常游戏速度。 + /// + 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; + } + + Type versionHelperType = Utility.Assembly.GetType(m_VersionHelperTypeName); + if (versionHelperType == null) + { + throw new GameFrameworkException(Utility.Text.Format("Can not find version helper type '{0}'.", m_VersionHelperTypeName)); + } + + TEngine.Version.IVersionHelper versionHelper = (TEngine.Version.IVersionHelper)Activator.CreateInstance(versionHelperType); + if (versionHelper == null) + { + throw new GameFrameworkException(Utility.Text.Format("Can not create version helper instance '{0}'.", m_VersionHelperTypeName)); + } + + TEngine.Version.SetVersionHelper(versionHelper); + } + + private void InitLogHelper() + { + if (string.IsNullOrEmpty(m_LogHelperTypeName)) + { + return; + } + + Type logHelperType = Utility.Assembly.GetType(m_LogHelperTypeName); + if (logHelperType == null) + { + throw new GameFrameworkException(Utility.Text.Format("Can not find log helper type '{0}'.", m_LogHelperTypeName)); + } + + GameFrameworkLog.ILogHelper 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; + } + + Type compressionHelperType = Utility.Assembly.GetType(m_CompressionHelperTypeName); + if (compressionHelperType == null) + { + Log.Error("Can not find compression helper type '{0}'.", m_CompressionHelperTypeName); + return; + } + + Utility.Compression.ICompressionHelper 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; + } + + Type jsonHelperType = Utility.Assembly.GetType(m_JsonHelperTypeName); + if (jsonHelperType == null) + { + Log.Error("Can not find JSON helper type '{0}'.", m_JsonHelperTypeName); + return; + } + + Utility.Json.IJsonHelper 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..."); + + //TODO + /*ObjectPoolComponent objectPoolComponent = GameEntry.GetComponent(); + if (objectPoolComponent != null) + { + objectPoolComponent.ReleaseAllUnused(); + } + + ResourceComponent resourceComponent = GameEntry.GetComponent(); + if (resourceComponent != null) + { + resourceComponent.ForceUnloadUnusedAssets(true); + }*/ + } + } +} diff --git a/Assets/TEngine/Runtime/BaseComponent.cs.meta b/Assets/TEngine/Runtime/BaseComponent.cs.meta new file mode 100644 index 00000000..e6d0fa4b --- /dev/null +++ b/Assets/TEngine/Runtime/BaseComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 564a45007d8645cf96d33bb52471acd5 +timeCreated: 1680337824 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/GameEntry.cs b/Assets/TEngine/Runtime/GameFramework/GameEntry.cs new file mode 100644 index 00000000..378bc550 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameEntry.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace TEngine +{ + /// + /// 游戏入口。 + /// + public static class GameEntry + { + private static readonly GameFrameworkLinkedList s_GameFrameworkComponents = new GameFrameworkLinkedList(); + + /// + /// 游戏框架所在的场景编号。 + /// + internal const int GameFrameworkSceneId = 0; + + /// + /// 获取游戏框架组件。 + /// + /// 要获取的游戏框架组件类型。 + /// 要获取的游戏框架组件。 + public static T GetComponent() where T : GameFrameworkComponent + { + return (T)GetComponent(typeof(T)); + } + + /// + /// 获取游戏框架组件。 + /// + /// 要获取的游戏框架组件类型。 + /// 要获取的游戏框架组件。 + public static GameFrameworkComponent GetComponent(Type type) + { + LinkedListNode current = s_GameFrameworkComponents.First; + while (current != null) + { + if (current.Value.GetType() == type) + { + return current.Value; + } + + current = current.Next; + } + + return null; + } + + /// + /// 获取游戏框架组件。 + /// + /// 要获取的游戏框架组件类型名称。 + /// 要获取的游戏框架组件。 + public static GameFrameworkComponent GetComponent(string typeName) + { + LinkedListNode current = s_GameFrameworkComponents.First; + while (current != null) + { + Type type = current.Value.GetType(); + if (type.FullName == typeName || type.Name == typeName) + { + return current.Value; + } + + current = current.Next; + } + + return null; + } + + /// + /// 关闭游戏框架。 + /// + /// 关闭游戏框架类型。 + public static void Shutdown(ShutdownType shutdownType) + { + Log.Info("Shutdown Game Framework ({0})...", shutdownType); + Utility.Unity.Release(); + BaseComponent baseComponent = GetComponent(); + if (baseComponent != null) + { + baseComponent.Shutdown(); + baseComponent = null; + } + + s_GameFrameworkComponents.Clear(); + + if (shutdownType == ShutdownType.None) + { + return; + } + + if (shutdownType == ShutdownType.Restart) + { + SceneManager.LoadScene(GameFrameworkSceneId); + return; + } + + if (shutdownType == ShutdownType.Quit) + { + Application.Quit(); +#if UNITY_EDITOR + UnityEditor.EditorApplication.isPlaying = false; +#endif + } + } + + /// + /// 注册游戏框架组件。 + /// + /// 要注册的游戏框架组件。 + internal static void RegisterComponent(GameFrameworkComponent gameFrameworkComponent) + { + if (gameFrameworkComponent == null) + { + Log.Error("Game Framework component is invalid."); + return; + } + + Type type = gameFrameworkComponent.GetType(); + + LinkedListNode current = s_GameFrameworkComponents.First; + while (current != null) + { + if (current.Value.GetType() == type) + { + Log.Error("Game Framework component type '{0}' is already exist.", type.FullName); + return; + } + + current = current.Next; + } + + s_GameFrameworkComponents.AddLast(gameFrameworkComponent); + } + } +} diff --git a/Assets/TEngine/Runtime/GameFramework/GameEntry.cs.meta b/Assets/TEngine/Runtime/GameFramework/GameEntry.cs.meta new file mode 100644 index 00000000..354e78ec --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameEntry.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6d39a8de0dec418eba1ee81fefd4d5a5 +timeCreated: 1680338130 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs b/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs new file mode 100644 index 00000000..2c61e3dd --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs @@ -0,0 +1,18 @@ +using UnityEngine; + +namespace TEngine +{ + /// + /// 游戏框架组件抽象类。 + /// + public abstract class GameFrameworkComponent : MonoBehaviour + { + /// + /// 游戏框架组件初始化。 + /// + protected virtual void Awake() + { + GameEntry.RegisterComponent(this); + } + } +} diff --git a/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs.meta b/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs.meta new file mode 100644 index 00000000..0affa1f0 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/GameFrameworkComponent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 98aa729dea5649998b96191597d5af36 +timeCreated: 1680338130 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Log/GameFrameworkLog.cs b/Assets/TEngine/Runtime/GameFramework/Log/GameFrameworkLog.cs index 9c168c01..4ef8adaf 100644 --- a/Assets/TEngine/Runtime/GameFramework/Log/GameFrameworkLog.cs +++ b/Assets/TEngine/Runtime/GameFramework/Log/GameFrameworkLog.cs @@ -5,7 +5,7 @@ /// public static partial class GameFrameworkLog { - private static ILogHelper s_LogHelper = new TEngineLogHelper(); + private static ILogHelper s_LogHelper; /// /// 设置游戏框架日志辅助器。 diff --git a/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs b/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs new file mode 100644 index 00000000..9e6ab52b --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs @@ -0,0 +1,23 @@ +namespace TEngine +{ + /// + /// 关闭游戏框架类型。 + /// + public enum ShutdownType : byte + { + /// + /// 仅关闭游戏框架。 + /// + None = 0, + + /// + /// 关闭游戏框架并重启游戏。 + /// + Restart, + + /// + /// 关闭游戏框架并退出游戏。 + /// + Quit, + } +} diff --git a/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs.meta b/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs.meta new file mode 100644 index 00000000..8682dba2 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/ShutdownType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a91e41b944ca4ac986dbf17b39ac44db +timeCreated: 1680337945 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility.meta b/Assets/TEngine/Runtime/GameFramework/Utility.meta new file mode 100644 index 00000000..1e906228 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4768a00bcf9cf9d4197da234b968867c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/Utility.Assembly.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Assembly.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Assembly.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Assembly.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Assembly.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Assembly.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Assembly.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Assembly.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Compression.ICompressionHelper.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.ICompressionHelper.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Compression.ICompressionHelper.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.ICompressionHelper.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Compression.ICompressionHelper.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.ICompressionHelper.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Compression.ICompressionHelper.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.ICompressionHelper.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Compression.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Compression.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Compression.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Compression.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Compression.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Converter.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Converter.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Converter.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Converter.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Converter.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Converter.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Converter.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Converter.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Encryption.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Encryption.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Encryption.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Encryption.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Encryption.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Encryption.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Encryption.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Encryption.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.File.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.File.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.File.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.File.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.File.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.File.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.File.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.File.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Folder.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Folder.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Folder.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Folder.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Folder.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Folder.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Folder.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Folder.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Json.IJsonHelper.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.IJsonHelper.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Json.IJsonHelper.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.IJsonHelper.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Json.IJsonHelper.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.IJsonHelper.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Json.IJsonHelper.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.IJsonHelper.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Json.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Json.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Json.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Json.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Json.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Marshal.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Marshal.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Marshal.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Marshal.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Marshal.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Marshal.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Marshal.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Marshal.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Path.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Path.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Path.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Path.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Path.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Path.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Path.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Path.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Random.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Random.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Random.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Random.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Random.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Random.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Random.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Random.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Text.ITextHelper.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.ITextHelper.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Text.ITextHelper.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.ITextHelper.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Text.ITextHelper.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.ITextHelper.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Text.ITextHelper.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.ITextHelper.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Text.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Text.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Text.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Text.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Text.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Unity.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Unity.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Unity.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Unity.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Unity.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Unity.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Unity.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Unity.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Verifier.Crc32.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.Crc32.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Verifier.Crc32.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.Crc32.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Verifier.Crc32.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.Crc32.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Verifier.Crc32.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.Crc32.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.Verifier.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Verifier.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.Verifier.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.Verifier.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.Verifier.cs.meta diff --git a/Assets/TEngine/Runtime/Utility/Utility.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.cs similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.cs rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.cs diff --git a/Assets/TEngine/Runtime/Utility/Utility.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.cs.meta similarity index 100% rename from Assets/TEngine/Runtime/Utility/Utility.cs.meta rename to Assets/TEngine/Runtime/GameFramework/Utility/Utility.cs.meta diff --git a/Assets/TEngine/Runtime/Localization.meta b/Assets/TEngine/Runtime/Localization.meta new file mode 100644 index 00000000..5d2bc6e1 --- /dev/null +++ b/Assets/TEngine/Runtime/Localization.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 93974dec76d94627817ea711a60ef9c4 +timeCreated: 1680337861 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Localization/Language.cs b/Assets/TEngine/Runtime/Localization/Language.cs new file mode 100644 index 00000000..d612b3ab --- /dev/null +++ b/Assets/TEngine/Runtime/Localization/Language.cs @@ -0,0 +1,263 @@ +namespace TEngine.Localization +{ + /// + /// 本地化语言。 + /// + public enum Language : byte + { + /// + /// 未指定。 + /// + Unspecified = 0, + + /// + /// 南非荷兰语。 + /// + Afrikaans, + + /// + /// 阿尔巴尼亚语。 + /// + Albanian, + + /// + /// 阿拉伯语。 + /// + Arabic, + + /// + /// 巴斯克语。 + /// + Basque, + + /// + /// 白俄罗斯语。 + /// + Belarusian, + + /// + /// 保加利亚语。 + /// + Bulgarian, + + /// + /// 加泰罗尼亚语。 + /// + Catalan, + + /// + /// 简体中文。 + /// + ChineseSimplified, + + /// + /// 繁体中文。 + /// + ChineseTraditional, + + /// + /// 克罗地亚语。 + /// + Croatian, + + /// + /// 捷克语。 + /// + Czech, + + /// + /// 丹麦语。 + /// + Danish, + + /// + /// 荷兰语。 + /// + Dutch, + + /// + /// 英语。 + /// + English, + + /// + /// 爱沙尼亚语。 + /// + Estonian, + + /// + /// 法罗语。 + /// + Faroese, + + /// + /// 芬兰语。 + /// + Finnish, + + /// + /// 法语。 + /// + French, + + /// + /// 格鲁吉亚语。 + /// + Georgian, + + /// + /// 德语。 + /// + German, + + /// + /// 希腊语。 + /// + Greek, + + /// + /// 希伯来语。 + /// + Hebrew, + + /// + /// 匈牙利语。 + /// + Hungarian, + + /// + /// 冰岛语。 + /// + Icelandic, + + /// + /// 印尼语。 + /// + Indonesian, + + /// + /// 意大利语。 + /// + Italian, + + /// + /// 日语。 + /// + Japanese, + + /// + /// 韩语。 + /// + Korean, + + /// + /// 拉脱维亚语。 + /// + Latvian, + + /// + /// 立陶宛语。 + /// + Lithuanian, + + /// + /// 马其顿语。 + /// + Macedonian, + + /// + /// 马拉雅拉姆语。 + /// + Malayalam, + + /// + /// 挪威语。 + /// + Norwegian, + + /// + /// 波斯语。 + /// + Persian, + + /// + /// 波兰语。 + /// + Polish, + + /// + /// 巴西葡萄牙语。 + /// + PortugueseBrazil, + + /// + /// 葡萄牙语。 + /// + PortuguesePortugal, + + /// + /// 罗马尼亚语。 + /// + Romanian, + + /// + /// 俄语。 + /// + Russian, + + /// + /// 塞尔维亚克罗地亚语。 + /// + SerboCroatian, + + /// + /// 塞尔维亚西里尔语。 + /// + SerbianCyrillic, + + /// + /// 塞尔维亚拉丁语。 + /// + SerbianLatin, + + /// + /// 斯洛伐克语。 + /// + Slovak, + + /// + /// 斯洛文尼亚语。 + /// + Slovenian, + + /// + /// 西班牙语。 + /// + Spanish, + + /// + /// 瑞典语。 + /// + Swedish, + + /// + /// 泰语。 + /// + Thai, + + /// + /// 土耳其语。 + /// + Turkish, + + /// + /// 乌克兰语。 + /// + Ukrainian, + + /// + /// 越南语。 + /// + Vietnamese + } +} diff --git a/Assets/TEngine/Runtime/Localization/Language.cs.meta b/Assets/TEngine/Runtime/Localization/Language.cs.meta new file mode 100644 index 00000000..6a8fde72 --- /dev/null +++ b/Assets/TEngine/Runtime/Localization/Language.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b84caf139f3426a9e3adb7f015982c4 +timeCreated: 1680337879 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Utility.meta b/Assets/TEngine/Runtime/Utility.meta index 1e906228..f565d83f 100644 --- a/Assets/TEngine/Runtime/Utility.meta +++ b/Assets/TEngine/Runtime/Utility.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4768a00bcf9cf9d4197da234b968867c +guid: a8abc344e7b1e7040b2979eda41978e1 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/TEngine/Runtime/Utility/BinaryExtension.cs b/Assets/TEngine/Runtime/Utility/BinaryExtension.cs new file mode 100644 index 00000000..3e802b79 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/BinaryExtension.cs @@ -0,0 +1,185 @@ +using System; +using System.IO; +using TEngine; + +/// +/// 对 BinaryReader 和 BinaryWriter 的扩展方法。 +/// +public static class BinaryExtension +{ + private static readonly byte[] s_CachedBytes = new byte[byte.MaxValue + 1]; + + /// + /// 从二进制流读取编码后的 32 位有符号整数。 + /// + /// 要读取的二进制流。 + /// 读取的 32 位有符号整数。 + public static int Read7BitEncodedInt32(this BinaryReader binaryReader) + { + int value = 0; + int shift = 0; + byte b; + do + { + if (shift >= 35) + { + throw new GameFrameworkException("7 bit encoded int is invalid."); + } + + b = binaryReader.ReadByte(); + value |= (b & 0x7f) << shift; + shift += 7; + } while ((b & 0x80) != 0); + + return value; + } + + /// + /// 向二进制流写入编码后的 32 位有符号整数。 + /// + /// 要写入的二进制流。 + /// 要写入的 32 位有符号整数。 + public static void Write7BitEncodedInt32(this BinaryWriter binaryWriter, int value) + { + uint num = (uint)value; + while (num >= 0x80) + { + binaryWriter.Write((byte)(num | 0x80)); + num >>= 7; + } + + binaryWriter.Write((byte)num); + } + + /// + /// 从二进制流读取编码后的 32 位无符号整数。 + /// + /// 要读取的二进制流。 + /// 读取的 32 位无符号整数。 + public static uint Read7BitEncodedUInt32(this BinaryReader binaryReader) + { + return (uint)Read7BitEncodedInt32(binaryReader); + } + + /// + /// 向二进制流写入编码后的 32 位无符号整数。 + /// + /// 要写入的二进制流。 + /// 要写入的 32 位无符号整数。 + public static void Write7BitEncodedUInt32(this BinaryWriter binaryWriter, uint value) + { + Write7BitEncodedInt32(binaryWriter, (int)value); + } + + /// + /// 从二进制流读取编码后的 64 位有符号整数。 + /// + /// 要读取的二进制流。 + /// 读取的 64 位有符号整数。 + public static long Read7BitEncodedInt64(this BinaryReader binaryReader) + { + long value = 0L; + int shift = 0; + byte b; + do + { + if (shift >= 70) + { + throw new GameFrameworkException("7 bit encoded int is invalid."); + } + + b = binaryReader.ReadByte(); + value |= (b & 0x7fL) << shift; + shift += 7; + } while ((b & 0x80) != 0); + + return value; + } + + /// + /// 向二进制流写入编码后的 64 位有符号整数。 + /// + /// 要写入的二进制流。 + /// 要写入的 64 位有符号整数。 + public static void Write7BitEncodedInt64(this BinaryWriter binaryWriter, long value) + { + ulong num = (ulong)value; + while (num >= 0x80) + { + binaryWriter.Write((byte)(num | 0x80)); + num >>= 7; + } + + binaryWriter.Write((byte)num); + } + + /// + /// 从二进制流读取编码后的 64 位无符号整数。 + /// + /// 要读取的二进制流。 + /// 读取的 64 位无符号整数。 + public static ulong Read7BitEncodedUInt64(this BinaryReader binaryReader) + { + return (ulong)Read7BitEncodedInt64(binaryReader); + } + + /// + /// 向二进制流写入编码后的 64 位无符号整数。 + /// + /// 要写入的二进制流。 + /// 要写入的 64 位无符号整数。 + public static void Write7BitEncodedUInt64(this BinaryWriter binaryWriter, ulong value) + { + Write7BitEncodedInt64(binaryWriter, (long)value); + } + + /// + /// 从二进制流读取加密字符串。 + /// + /// 要读取的二进制流。 + /// 密钥数组。 + /// 读取的字符串。 + public static string ReadEncryptedString(this BinaryReader binaryReader, byte[] encryptBytes) + { + byte length = binaryReader.ReadByte(); + if (length <= 0) + { + return null; + } + + for (byte i = 0; i < length; i++) + { + s_CachedBytes[i] = binaryReader.ReadByte(); + } + + Utility.Encryption.GetSelfXorBytes(s_CachedBytes, 0, length, encryptBytes); + string value = Utility.Converter.GetString(s_CachedBytes, 0, length); + Array.Clear(s_CachedBytes, 0, length); + return value; + } + + /// + /// 向二进制流写入加密字符串。 + /// + /// 要写入的二进制流。 + /// 要写入的字符串。 + /// 密钥数组。 + public static void WriteEncryptedString(this BinaryWriter binaryWriter, string value, byte[] encryptBytes) + { + if (string.IsNullOrEmpty(value)) + { + binaryWriter.Write((byte)0); + return; + } + + int length = Utility.Converter.GetBytes(value, s_CachedBytes); + if (length > byte.MaxValue) + { + throw new GameFrameworkException(Utility.Text.Format("String '{0}' is too long.", value)); + } + + Utility.Encryption.GetSelfXorBytes(s_CachedBytes, encryptBytes); + binaryWriter.Write((byte)length); + binaryWriter.Write(s_CachedBytes, 0, length); + } +} diff --git a/Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta b/Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta new file mode 100644 index 00000000..4411e388 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/BinaryExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb8959e3dd580774a9d8e581c16ed6ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DUnityUtil.cs b/Assets/TEngine/Runtime/Utility/DUnityUtil.cs new file mode 100644 index 00000000..771a3247 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DUnityUtil.cs @@ -0,0 +1,248 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngineInternal; + +namespace TEngine +{ + /// + /// Unity关的实用函数。 + /// + public static class DUnityUtil + { + [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] + public static Component AddMonoBehaviour(Type type, GameObject go) + { + var comp = go.GetComponent(type); + if (comp == null) + { + comp = go.AddComponent(type); + } + + return comp; + } + + public static T AddMonoBehaviour(Component comp) where T : Component + { + + var ret = comp.GetComponent(); + if (ret == null) + { + ret = comp.gameObject.AddComponent(); + } + + return ret; + } + + public static T AddMonoBehaviour(GameObject go) where T : Component + { + var comp = go.GetComponent(); + if (comp == null) + { + comp = go.AddComponent(); + } + + return comp; + } + + [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] + public static void RmvMonoBehaviour(Type type, GameObject go) + { + var comp = go.GetComponent(type); + if (comp != null) + { + UnityEngine.Object.Destroy(comp); + } + } + + public static void RmvMonoBehaviour(GameObject go) where T : Component + { + var comp = go.GetComponent(); + if (comp != null) + { + UnityEngine.Object.Destroy(comp); + } + } + + + public static Transform FindChild(Transform transform, string path) + { + var findTrans = transform.Find(path); + if (findTrans != null) + { + return findTrans; + } + + return null; + } + + /// + /// 根据名字找到子节点,主要用于dummy接口 + /// + /// + /// + /// + public static Transform FindChildByName(Transform transform, string name) + { + if (transform == null) + { + return null; + } + + for (int i = 0; i < transform.childCount; i++) + { + var childTrans = transform.GetChild(i); + if (childTrans.name == name) + { + return childTrans; + } + + var find = FindChildByName(childTrans, name); + if (find != null) + { + return find; + } + } + + return null; + } + + [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] + public static Component FindChildComponent(Type type, Transform transform, string path) + { + var findTrans = transform.Find(path); + if (findTrans != null) + { + return findTrans.gameObject.GetComponent(type); + } + + return null; + } + + public static T FindChildComponent(Transform transform, string path) where T : Component + { + var findTrans = transform.Find(path); + if (findTrans != null) + { + return findTrans.gameObject.GetComponent(); + } + + return null; + } + + public static void SetLayer(GameObject go, int layer) + { + if (go == null) + { + return; + } + SetLayer(go.transform, layer); + } + + public static void SetLayer(Transform trans, int layer) + { + if (trans == null) + { + return; + } + trans.gameObject.layer = layer; + for (int i = 0, imax = trans.childCount; i < imax; ++i) + { + Transform child = trans.GetChild(i); + SetLayer(child, layer); + } + } + + public static int RandomRangeInt(int min, int max) + { + return UnityEngine.Random.Range(min, max); + } + + public static float RandomRangeFloat(float min, float max) + { + return UnityEngine.Random.Range(min, max); + } + + public static Vector2 RandomInsideCircle(float radius) + { + return UnityEngine.Random.insideUnitCircle * radius; + } + + [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] + public static Array CreateUnityArray(Type type, int length) + { + return Array.CreateInstance(type, length); + } + + public static T[] CreateUnityArray(int length) + { + return new T[length]; + } + + + public static GameObject Instantiate(GameObject go) + { + if (go != null) + { + return UnityEngine.Object.Instantiate(go); + } + + return null; + } + + public static bool Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) + { + return Physics.Raycast(ray, out hitInfo, maxDistance, layerMask); + } + + public static List GetRegexMatchGroups(string pattern,string input) + { + List list=new List(); + var regexLink = new Regex(pattern); + var links = regexLink.Match(input); + for (var i = 0; i < links.Groups.Count; ++i) + { + list.Add(links.Groups[i].Value); + } + return list; + } + + public static void SetMaterialVector3(Material mat, int nameId, Vector3 val) + { + mat.SetVector(nameId, val); + } + + public static void GetVectorData(Vector3 val, out float x, out float y, out float z) + { + x = val.x; + y = val.y; + z = val.z; + } + public static void GetVector2Data(Vector2 val, out float x, out float y) + { + x = val.x; + y = val.y; + } + + public static bool GetTouchByFingerId(int fingerId, out Touch findTouch) + { + var find = false; + var touchCnt = Input.touchCount; + + findTouch = new Touch(); + for (int i = 0; i < touchCnt; i++) + { + var touch = Input.GetTouch(i); + if (touch.fingerId == fingerId) + { + findTouch = touch; + find = true; + break; + } + } + + return find; + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DUnityUtil.cs.meta b/Assets/TEngine/Runtime/Utility/DUnityUtil.cs.meta new file mode 100644 index 00000000..f474308a --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DUnityUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 611c6fdc692b48645b80bf4aa915be32 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs b/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs new file mode 100644 index 00000000..6402cc05 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs @@ -0,0 +1,204 @@ +using ICSharpCode.SharpZipLib.GZip; +using System; +using System.IO; + +namespace TEngine +{ + /// + /// 默认压缩解压缩辅助器。 + /// + public class DefaultCompressionHelper : Utility.Compression.ICompressionHelper + { + private const int CachedBytesLength = 0x1000; + private readonly byte[] m_CachedBytes = new byte[CachedBytesLength]; + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 要压缩的数据的二进制流的偏移。 + /// 要压缩的数据的二进制流的长度。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + public bool Compress(byte[] bytes, int offset, int length, Stream compressedStream) + { + if (bytes == null) + { + return false; + } + + if (offset < 0 || length < 0 || offset + length > bytes.Length) + { + return false; + } + + if (compressedStream == null) + { + return false; + } + + try + { + GZipOutputStream gZipOutputStream = new GZipOutputStream(compressedStream); + gZipOutputStream.Write(bytes, offset, length); + gZipOutputStream.Finish(); + ProcessHeader(compressedStream); + return true; + } + catch + { + return false; + } + } + + /// + /// 压缩数据。 + /// + /// 要压缩的数据的二进制流。 + /// 压缩后的数据的二进制流。 + /// 是否压缩数据成功。 + public bool Compress(Stream stream, Stream compressedStream) + { + if (stream == null) + { + return false; + } + + if (compressedStream == null) + { + return false; + } + + try + { + GZipOutputStream gZipOutputStream = new GZipOutputStream(compressedStream); + int bytesRead = 0; + while ((bytesRead = stream.Read(m_CachedBytes, 0, CachedBytesLength)) > 0) + { + gZipOutputStream.Write(m_CachedBytes, 0, bytesRead); + } + + gZipOutputStream.Finish(); + ProcessHeader(compressedStream); + return true; + } + catch + { + return false; + } + finally + { + Array.Clear(m_CachedBytes, 0, CachedBytesLength); + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 要解压缩的数据的二进制流的偏移。 + /// 要解压缩的数据的二进制流的长度。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + public bool Decompress(byte[] bytes, int offset, int length, Stream decompressedStream) + { + if (bytes == null) + { + return false; + } + + if (offset < 0 || length < 0 || offset + length > bytes.Length) + { + return false; + } + + if (decompressedStream == null) + { + return false; + } + + MemoryStream memoryStream = null; + try + { + memoryStream = new MemoryStream(bytes, offset, length, false); + using (GZipInputStream gZipInputStream = new GZipInputStream(memoryStream)) + { + int bytesRead = 0; + while ((bytesRead = gZipInputStream.Read(m_CachedBytes, 0, CachedBytesLength)) > 0) + { + decompressedStream.Write(m_CachedBytes, 0, bytesRead); + } + } + + return true; + } + catch + { + return false; + } + finally + { + if (memoryStream != null) + { + memoryStream.Dispose(); + memoryStream = null; + } + + Array.Clear(m_CachedBytes, 0, CachedBytesLength); + } + } + + /// + /// 解压缩数据。 + /// + /// 要解压缩的数据的二进制流。 + /// 解压缩后的数据的二进制流。 + /// 是否解压缩数据成功。 + public bool Decompress(Stream stream, Stream decompressedStream) + { + if (stream == null) + { + return false; + } + + if (decompressedStream == null) + { + return false; + } + + try + { + GZipInputStream gZipInputStream = new GZipInputStream(stream); + int bytesRead = 0; + while ((bytesRead = gZipInputStream.Read(m_CachedBytes, 0, CachedBytesLength)) > 0) + { + decompressedStream.Write(m_CachedBytes, 0, bytesRead); + } + + return true; + } + catch + { + return false; + } + finally + { + Array.Clear(m_CachedBytes, 0, CachedBytesLength); + } + } + + private static void ProcessHeader(Stream compressedStream) + { + if (compressedStream.Length >= 8L) + { + long current = compressedStream.Position; + compressedStream.Position = 4L; + compressedStream.WriteByte(25); + compressedStream.WriteByte(134); + compressedStream.WriteByte(2); + compressedStream.WriteByte(32); + compressedStream.Position = current; + } + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs.meta b/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs.meta new file mode 100644 index 00000000..8334ab67 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultCompressionHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1d184e46fc6573c4abb31c8039d407b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs b/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs new file mode 100644 index 00000000..0fe39fa5 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs @@ -0,0 +1,43 @@ +using System; +using UnityEngine; + +namespace TEngine +{ + /// + /// 默认 JSON 函数集辅助器。 + /// + public class DefaultJsonHelper : Utility.Json.IJsonHelper + { + /// + /// 将对象序列化为 JSON 字符串。 + /// + /// 要序列化的对象。 + /// 序列化后的 JSON 字符串。 + public string ToJson(object obj) + { + return JsonUtility.ToJson(obj); + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + public T ToObject(string json) + { + return JsonUtility.FromJson(json); + } + + /// + /// 将 JSON 字符串反序列化为对象。 + /// + /// 对象类型。 + /// 要反序列化的 JSON 字符串。 + /// 反序列化后的对象。 + public object ToObject(Type objectType, string json) + { + return JsonUtility.FromJson(json, objectType); + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs.meta b/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs.meta new file mode 100644 index 00000000..6b81fa48 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultJsonHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 124edaf04e2d94b4eaeec913cc6b2bf3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs b/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs new file mode 100644 index 00000000..ae23bbb7 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +namespace TEngine +{ + /// + /// 默认游戏框架日志辅助器。 + /// + public class DefaultLogHelper : GameFrameworkLog.ILogHelper + { + /// + /// 记录日志。 + /// + /// 日志等级。 + /// 日志内容。 + public void Log(GameFrameworkLogLevel level, object message) + { + switch (level) + { + case GameFrameworkLogLevel.Debug: + Debug.Log(Utility.Text.Format("{0}", message)); + break; + + case GameFrameworkLogLevel.Info: + Debug.Log(message.ToString()); + break; + + case GameFrameworkLogLevel.Warning: + Debug.LogWarning(message.ToString()); + break; + + case GameFrameworkLogLevel.Error: + Debug.LogError(message.ToString()); + break; + + default: + throw new GameFrameworkException(message.ToString()); + } + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs.meta b/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs.meta new file mode 100644 index 00000000..b97d22f5 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultLogHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5cc7992e02f878541bfc9ee9ae7b92aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs b/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs new file mode 100644 index 00000000..5866f453 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs @@ -0,0 +1,584 @@ +using System; +using System.Text; + +namespace TEngine +{ + /// + /// 默认字符辅助器。 + /// + public class DefaultTextHelper : Utility.Text.ITextHelper + { + private const int StringBuilderCapacity = 1024; + + [ThreadStatic] + private static StringBuilder s_CachedStringBuilder = null; + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数的类型。 + /// 字符串格式。 + /// 字符串参数。 + /// 格式化后的字符串。 + public string Format(string format, T arg) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 格式化后的字符串。 + public string Format(string format, T1 arg1, T2 arg2) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 格式化后的字符串。 + public string Format(string format, T1 arg1, T2 arg2, T3 arg3) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 格式化后的字符串。 + public string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 格式化后的字符串。 + public string Format(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) + { + if (format == null) + { + throw new GameFrameworkException("Format is invalid."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 1 的类型。 + /// 字符串参数 2 的类型。 + /// 字符串参数 3 的类型。 + /// 字符串参数 4 的类型。 + /// 字符串参数 5 的类型。 + /// 字符串参数 6 的类型。 + /// 字符串参数 7 的类型。 + /// 字符串参数 8 的类型。 + /// 字符串参数 9 的类型。 + /// 字符串参数 10 的类型。 + /// 字符串参数 11 的类型。 + /// 字符串格式。 + /// 字符串参数 1。 + /// 字符串参数 2。 + /// 字符串参数 3。 + /// 字符串参数 4。 + /// 字符串参数 5。 + /// 字符串参数 6。 + /// 字符串参数 7。 + /// 字符串参数 8。 + /// 字符串参数 9。 + /// 字符串参数 10。 + /// 字符串参数 11。 + /// 格式化后的字符串。 + public 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 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 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 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 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 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 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 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 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + return s_CachedStringBuilder.ToString(); + } + + /// + /// 获取格式化字符串。 + /// + /// 字符串参数 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 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."); + } + + CheckCachedStringBuilder(); + s_CachedStringBuilder.Length = 0; + s_CachedStringBuilder.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + return s_CachedStringBuilder.ToString(); + } + + private static void CheckCachedStringBuilder() + { + if (s_CachedStringBuilder == null) + { + s_CachedStringBuilder = new StringBuilder(StringBuilderCapacity); + } + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs.meta b/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs.meta new file mode 100644 index 00000000..bf76b766 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultTextHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cda9d41dd292f9049b948679c8784657 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs b/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs new file mode 100644 index 00000000..11cfe63b --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +namespace TEngine +{ + /// + /// 默认版本号辅助器。 + /// + public class DefaultVersionHelper : Version.IVersionHelper + { + /// + /// 获取游戏版本号。 + /// + public string GameVersion + { + get + { + return Application.version; + } + } + + /// + /// 获取内部游戏版本号。 + /// + public int InternalGameVersion + { + get + { + return 0; + } + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs.meta b/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs.meta new file mode 100644 index 00000000..d70b2ab6 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/DefaultVersionHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6a351c5e9718e3040ae02cf488d57641 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/Helper.cs b/Assets/TEngine/Runtime/Utility/Helper.cs new file mode 100644 index 00000000..3e2f1261 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/Helper.cs @@ -0,0 +1,68 @@ +using TEngine; +using UnityEngine; + +namespace TEngine +{ + /// + /// 辅助器创建器相关的实用函数。 + /// + public static class Helper + { + /// + /// 创建辅助器。 + /// + /// 要创建的辅助器类型。 + /// 要创建的辅助器类型名称。 + /// 若要创建的辅助器类型为空时,使用的自定义辅助器类型。 + /// 创建的辅助器。 + public static T CreateHelper(string helperTypeName, T customHelper) where T : MonoBehaviour + { + return CreateHelper(helperTypeName, customHelper, 0); + } + + /// + /// 创建辅助器。 + /// + /// 要创建的辅助器类型。 + /// 要创建的辅助器类型名称。 + /// 若要创建的辅助器类型为空时,使用的自定义辅助器类型。 + /// 要创建的辅助器索引。 + /// 创建的辅助器。 + public static T CreateHelper(string helperTypeName, T customHelper, int index) where T : MonoBehaviour + { + T helper = null; + if (!string.IsNullOrEmpty(helperTypeName)) + { + System.Type helperType = Utility.Assembly.GetType(helperTypeName); + if (helperType == null) + { + Log.Warning("Can not find helper type '{0}'.", helperTypeName); + return null; + } + + if (!typeof(T).IsAssignableFrom(helperType)) + { + Log.Warning("Type '{0}' is not assignable from '{1}'.", typeof(T).FullName, helperType.FullName); + return null; + } + + helper = (T)new GameObject().AddComponent(helperType); + } + else if (customHelper == null) + { + Log.Warning("You must set custom helper with '{0}' type first.", typeof(T).FullName); + return null; + } + else if (customHelper.gameObject.InScene()) + { + helper = index > 0 ? Object.Instantiate(customHelper) : customHelper; + } + else + { + helper = Object.Instantiate(customHelper); + } + + return helper; + } + } +} diff --git a/Assets/TEngine/Runtime/Utility/Helper.cs.meta b/Assets/TEngine/Runtime/Utility/Helper.cs.meta new file mode 100644 index 00000000..a3e708ed --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/Helper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 30e8ce1cbe85414488bd7a209e01e33e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/StringExtension.cs b/Assets/TEngine/Runtime/Utility/StringExtension.cs new file mode 100644 index 00000000..91bb6dec --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/StringExtension.cs @@ -0,0 +1,59 @@ +/// +/// 对 string 的扩展方法。 +/// +public static class StringExtension +{ + /// + /// 从指定字符串中的指定位置处开始读取一行。 + /// + /// 指定的字符串。 + /// 从指定位置处开始读取一行,读取后将返回下一行开始的位置。 + /// 读取的一行字符串。 + public static string ReadLine(this string rawString, ref int position) + { + if (position < 0) + { + return null; + } + + int length = rawString.Length; + int offset = position; + while (offset < length) + { + char ch = rawString[offset]; + switch (ch) + { + case '\r': + case '\n': + if (offset > position) + { + string line = rawString.Substring(position, offset - position); + position = offset + 1; + if ((ch == '\r') && (position < length) && (rawString[position] == '\n')) + { + position++; + } + + return line; + } + + offset++; + position++; + break; + + default: + offset++; + break; + } + } + + if (offset > position) + { + string line = rawString.Substring(position, offset - position); + position = offset; + return line; + } + + return null; + } +} diff --git a/Assets/TEngine/Runtime/Utility/StringExtension.cs.meta b/Assets/TEngine/Runtime/Utility/StringExtension.cs.meta new file mode 100644 index 00000000..2f53bb67 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/StringExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf3c6e399e5abde4e8b867e4dc5ca9ee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Utility/UnityExtension.cs b/Assets/TEngine/Runtime/Utility/UnityExtension.cs new file mode 100644 index 00000000..c413abdb --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/UnityExtension.cs @@ -0,0 +1,340 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 对 Unity 的扩展方法。 +/// +public static class UnityExtension +{ + private static readonly List s_CachedTransforms = new List(); + + /// + /// 获取或增加组件。 + /// + /// 要获取或增加的组件。 + /// 目标对象。 + /// 获取或增加的组件。 + public static T GetOrAddComponent(this GameObject gameObject) where T : Component + { + T component = gameObject.GetComponent(); + if (component == null) + { + component = gameObject.AddComponent(); + } + + return component; + } + + /// + /// 获取或增加组件。 + /// + /// 目标对象。 + /// 要获取或增加的组件类型。 + /// 获取或增加的组件。 + public static Component GetOrAddComponent(this GameObject gameObject, Type type) + { + Component component = gameObject.GetComponent(type); + if (component == null) + { + component = gameObject.AddComponent(type); + } + + return component; + } + + /// + /// 获取 GameObject 是否在场景中。 + /// + /// 目标对象。 + /// GameObject 是否在场景中。 + /// 若返回 true,表明此 GameObject 是一个场景中的实例对象;若返回 false,表明此 GameObject 是一个 Prefab。 + public static bool InScene(this GameObject gameObject) + { + return gameObject.scene.name != null; + } + + /// + /// 递归设置游戏对象的层次。 + /// + /// 对象。 + /// 目标层次的编号。 + public static void SetLayerRecursively(this GameObject gameObject, int layer) + { + gameObject.GetComponentsInChildren(true, s_CachedTransforms); + for (int i = 0; i < s_CachedTransforms.Count; i++) + { + s_CachedTransforms[i].gameObject.layer = layer; + } + + s_CachedTransforms.Clear(); + } + + /// + /// 取 的 (x, y, z) 转换为 的 (x, z)。 + /// + /// 要转换的 Vector3。 + /// 转换后的 Vector2。 + public static Vector2 ToVector2(this Vector3 vector3) + { + return new Vector2(vector3.x, vector3.z); + } + + /// + /// 取 的 (x, y) 转换为 的 (x, 0, y)。 + /// + /// 要转换的 Vector2。 + /// 转换后的 Vector3。 + public static Vector3 ToVector3(this Vector2 vector2) + { + return new Vector3(vector2.x, 0f, vector2.y); + } + + /// + /// 取 的 (x, y) 和给定参数 y 转换为 的 (x, 参数 y, y)。 + /// + /// 要转换的 Vector2。 + /// Vector3 的 y 值。 + /// 转换后的 Vector3。 + public static Vector3 ToVector3(this Vector2 vector2, float y) + { + return new Vector3(vector2.x, y, vector2.y); + } + + #region Transform + + /// + /// 设置绝对位置的 x 坐标。 + /// + /// 对象。 + /// x 坐标值。 + public static void SetPositionX(this Transform transform, float newValue) + { + Vector3 v = transform.position; + v.x = newValue; + transform.position = v; + } + + /// + /// 设置绝对位置的 y 坐标。 + /// + /// 对象。 + /// y 坐标值。 + public static void SetPositionY(this Transform transform, float newValue) + { + Vector3 v = transform.position; + v.y = newValue; + transform.position = v; + } + + /// + /// 设置绝对位置的 z 坐标。 + /// + /// 对象。 + /// z 坐标值。 + public static void SetPositionZ(this Transform transform, float newValue) + { + Vector3 v = transform.position; + v.z = newValue; + transform.position = v; + } + + /// + /// 增加绝对位置的 x 坐标。 + /// + /// 对象。 + /// x 坐标值增量。 + public static void AddPositionX(this Transform transform, float deltaValue) + { + Vector3 v = transform.position; + v.x += deltaValue; + transform.position = v; + } + + /// + /// 增加绝对位置的 y 坐标。 + /// + /// 对象。 + /// y 坐标值增量。 + public static void AddPositionY(this Transform transform, float deltaValue) + { + Vector3 v = transform.position; + v.y += deltaValue; + transform.position = v; + } + + /// + /// 增加绝对位置的 z 坐标。 + /// + /// 对象。 + /// z 坐标值增量。 + public static void AddPositionZ(this Transform transform, float deltaValue) + { + Vector3 v = transform.position; + v.z += deltaValue; + transform.position = v; + } + + /// + /// 设置相对位置的 x 坐标。 + /// + /// 对象。 + /// x 坐标值。 + public static void SetLocalPositionX(this Transform transform, float newValue) + { + Vector3 v = transform.localPosition; + v.x = newValue; + transform.localPosition = v; + } + + /// + /// 设置相对位置的 y 坐标。 + /// + /// 对象。 + /// y 坐标值。 + public static void SetLocalPositionY(this Transform transform, float newValue) + { + Vector3 v = transform.localPosition; + v.y = newValue; + transform.localPosition = v; + } + + /// + /// 设置相对位置的 z 坐标。 + /// + /// 对象。 + /// z 坐标值。 + public static void SetLocalPositionZ(this Transform transform, float newValue) + { + Vector3 v = transform.localPosition; + v.z = newValue; + transform.localPosition = v; + } + + /// + /// 增加相对位置的 x 坐标。 + /// + /// 对象。 + /// x 坐标值。 + public static void AddLocalPositionX(this Transform transform, float deltaValue) + { + Vector3 v = transform.localPosition; + v.x += deltaValue; + transform.localPosition = v; + } + + /// + /// 增加相对位置的 y 坐标。 + /// + /// 对象。 + /// y 坐标值。 + public static void AddLocalPositionY(this Transform transform, float deltaValue) + { + Vector3 v = transform.localPosition; + v.y += deltaValue; + transform.localPosition = v; + } + + /// + /// 增加相对位置的 z 坐标。 + /// + /// 对象。 + /// z 坐标值。 + public static void AddLocalPositionZ(this Transform transform, float deltaValue) + { + Vector3 v = transform.localPosition; + v.z += deltaValue; + transform.localPosition = v; + } + + /// + /// 设置相对尺寸的 x 分量。 + /// + /// 对象。 + /// x 分量值。 + public static void SetLocalScaleX(this Transform transform, float newValue) + { + Vector3 v = transform.localScale; + v.x = newValue; + transform.localScale = v; + } + + /// + /// 设置相对尺寸的 y 分量。 + /// + /// 对象。 + /// y 分量值。 + public static void SetLocalScaleY(this Transform transform, float newValue) + { + Vector3 v = transform.localScale; + v.y = newValue; + transform.localScale = v; + } + + /// + /// 设置相对尺寸的 z 分量。 + /// + /// 对象。 + /// z 分量值。 + public static void SetLocalScaleZ(this Transform transform, float newValue) + { + Vector3 v = transform.localScale; + v.z = newValue; + transform.localScale = v; + } + + /// + /// 增加相对尺寸的 x 分量。 + /// + /// 对象。 + /// x 分量增量。 + public static void AddLocalScaleX(this Transform transform, float deltaValue) + { + Vector3 v = transform.localScale; + v.x += deltaValue; + transform.localScale = v; + } + + /// + /// 增加相对尺寸的 y 分量。 + /// + /// 对象。 + /// y 分量增量。 + public static void AddLocalScaleY(this Transform transform, float deltaValue) + { + Vector3 v = transform.localScale; + v.y += deltaValue; + transform.localScale = v; + } + + /// + /// 增加相对尺寸的 z 分量。 + /// + /// 对象。 + /// z 分量增量。 + public static void AddLocalScaleZ(this Transform transform, float deltaValue) + { + Vector3 v = transform.localScale; + v.z += deltaValue; + transform.localScale = v; + } + + /// + /// 二维空间下使 指向指向目标点的算法,使用世界坐标。 + /// + /// 对象。 + /// 要朝向的二维坐标点。 + /// 假定其 forward 向量为 + public static void LookAt2D(this Transform transform, Vector2 lookAtPoint2D) + { + Vector3 vector = lookAtPoint2D.ToVector3() - transform.position; + vector.y = 0f; + + if (vector.magnitude > 0f) + { + transform.rotation = Quaternion.LookRotation(vector.normalized, Vector3.up); + } + } + + #endregion Transform +} diff --git a/Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta b/Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta new file mode 100644 index 00000000..dcbc27d2 --- /dev/null +++ b/Assets/TEngine/Runtime/Utility/UnityExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1a3443e3fec16542b5f5c354803bcd4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Runtime/Version.meta b/Assets/TEngine/Runtime/Version.meta new file mode 100644 index 00000000..497644b5 --- /dev/null +++ b/Assets/TEngine/Runtime/Version.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 27d9499af68549ca973bcb5af278018f +timeCreated: 1680338287 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs b/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs new file mode 100644 index 00000000..951ea16d --- /dev/null +++ b/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs @@ -0,0 +1,27 @@ +namespace TEngine +{ + public static partial class Version + { + /// + /// 版本号辅助器接口。 + /// + public interface IVersionHelper + { + /// + /// 获取游戏版本号。 + /// + string GameVersion + { + get; + } + + /// + /// 获取内部游戏版本号。 + /// + int InternalGameVersion + { + get; + } + } + } +} diff --git a/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs.meta b/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs.meta new file mode 100644 index 00000000..727feb19 --- /dev/null +++ b/Assets/TEngine/Runtime/Version/Version.IVersionHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 80f76c740d32479986a4a4eb04a8a9da +timeCreated: 1680338288 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Version/Version.cs b/Assets/TEngine/Runtime/Version/Version.cs new file mode 100644 index 00000000..4aab9985 --- /dev/null +++ b/Assets/TEngine/Runtime/Version/Version.cs @@ -0,0 +1,58 @@ +namespace TEngine +{ + /// + /// 版本号类。 + /// + public static partial class Version + { + private const string GameFrameworkVersionString = "2023.04.31"; + + private static IVersionHelper s_VersionHelper = null; + + /// + /// 获取游戏框架版本号。 + /// + public static string GameFrameworkVersion => GameFrameworkVersionString; + + /// + /// 获取游戏版本号。 + /// + public static string GameVersion + { + get + { + if (s_VersionHelper == null) + { + return string.Empty; + } + + return s_VersionHelper.GameVersion; + } + } + + /// + /// 获取内部游戏版本号。 + /// + public static int InternalGameVersion + { + get + { + if (s_VersionHelper == null) + { + return 0; + } + + return s_VersionHelper.InternalGameVersion; + } + } + + /// + /// 设置版本号辅助器。 + /// + /// 要设置的版本号辅助器。 + public static void SetVersionHelper(IVersionHelper versionHelper) + { + s_VersionHelper = versionHelper; + } + } +} diff --git a/Assets/TEngine/Runtime/Version/Version.cs.meta b/Assets/TEngine/Runtime/Version/Version.cs.meta new file mode 100644 index 00000000..bb4ccca5 --- /dev/null +++ b/Assets/TEngine/Runtime/Version/Version.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 145aad75d48e46af9099829684014934 +timeCreated: 1680338287 \ No newline at end of file