diff --git a/Assets/Scenes/main.unity b/Assets/Scenes/main.unity index 93ff9444..407730cd 100644 --- a/Assets/Scenes/main.unity +++ b/Assets/Scenes/main.unity @@ -857,9 +857,18 @@ MonoBehaviour: m_GameObject: {fileID: 2049602905} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 77d67944806247f99024bf5307adc918, type: 3} + m_Script: {fileID: 11500000, guid: 6e9edd9af2004f138ce8c543a2509393, type: 3} m_Name: m_EditorClassIdentifier: + packageName: DefaultPackage + playMode: 0 + verifyLevel: 1 + readWritePathType: 0 + minUnloadUnusedAssetsInterval: 60 + maxUnloadUnusedAssetsInterval: 300 + milliseconds: 30 + downloadingMaxNum: 3 + failedTryAgain: 3 --- !u!1 &2061060681 GameObject: m_ObjectHideFlags: 0 @@ -871,7 +880,7 @@ GameObject: - component: {fileID: 2061060682} - component: {fileID: 2061060683} m_Layer: 0 - m_Name: RootModule + m_Name: Root m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs b/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs new file mode 100644 index 00000000..bcbdabfb --- /dev/null +++ b/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs @@ -0,0 +1,247 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; +using YooAsset.Editor; + +namespace TEngine.Editor.Inspector +{ + [CustomEditor(typeof(ResourceModule))] + internal sealed class ResourceModuleInspector : GameFrameworkInspector + { + private static readonly string[] ResourceModeNames = new string[] { "EditorSimulateMode (编辑器下的模拟模式)", "OfflinePlayMode (单机模式)", "HostPlayMode (联机运行模式)" }; + private static readonly string[] VerifyLevelNames = new string[] { "Low (验证文件存在)", "Middle (验证文件大小)", "High (验证文件大小和CRC)" }; + + private SerializedProperty m_PackageName = null; + private SerializedProperty m_PlayMode = null; + private SerializedProperty m_ReadWritePathType = null; + private SerializedProperty m_VerifyLevel = null; + private SerializedProperty m_Milliseconds = null; + private SerializedProperty m_MinUnloadUnusedAssetsInterval = null; + private SerializedProperty m_MaxUnloadUnusedAssetsInterval = null; + private SerializedProperty m_DownloadingMaxNum = null; + private SerializedProperty m_FailedTryAgain = null; + + private int m_ResourceModeIndex = 0; + private int m_PackageIndex = 0; + private int m_VerifyIndex = 0; + + private PopupField _buildPackageField; + private List _buildPackageNames; + + private void OnEnable() + { + m_PackageName = serializedObject.FindProperty("packageName"); + m_PlayMode = serializedObject.FindProperty("playMode"); + m_VerifyLevel = serializedObject.FindProperty("verifyLevel"); + m_Milliseconds = serializedObject.FindProperty("milliseconds"); + + m_ReadWritePathType = serializedObject.FindProperty("readWritePathType"); + m_MinUnloadUnusedAssetsInterval = serializedObject.FindProperty("minUnloadUnusedAssetsInterval"); + m_MaxUnloadUnusedAssetsInterval = serializedObject.FindProperty("maxUnloadUnusedAssetsInterval"); + m_DownloadingMaxNum = serializedObject.FindProperty("downloadingMaxNum"); + m_FailedTryAgain = serializedObject.FindProperty("failedTryAgain"); + + RefreshModes(); + RefreshTypeNames(); + } + + private void RefreshModes() + { + m_ResourceModeIndex = m_PlayMode.enumValueIndex > 0 ? m_PlayMode.enumValueIndex : 0; + m_VerifyIndex = m_VerifyLevel.enumValueIndex > 0 ? m_VerifyLevel.enumValueIndex : 0; + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + serializedObject.Update(); + + ResourceModule t = (ResourceModule)target; + + EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); + { + if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) + { + EditorGUILayout.EnumPopup("Resource Mode", t.playMode); + + EditorGUILayout.EnumPopup("VerifyLevel", t.verifyLevel); + + _buildPackageNames = GetBuildPackageNames(); + if (_buildPackageNames.Count > 0) + { + GUILayout.Label(_buildPackageNames[0]); + } + } + else + { + // 资源模式 + int selectedIndex = EditorGUILayout.Popup("Resource Mode", m_ResourceModeIndex, ResourceModeNames); + if (selectedIndex != m_ResourceModeIndex) + { + m_ResourceModeIndex = selectedIndex; + m_PlayMode.enumValueIndex = selectedIndex; + } + + int selectedVerifyIndex = EditorGUILayout.Popup("VerifyLevel", m_VerifyIndex, VerifyLevelNames); + if (selectedVerifyIndex != m_VerifyIndex) + { + m_VerifyIndex = selectedVerifyIndex; + m_VerifyLevel.enumValueIndex = selectedVerifyIndex; + } + + // 包裹名称列表 + _buildPackageNames = GetBuildPackageNames(); + if (_buildPackageNames.Count > 0) + { + int selectedPackageIndex = EditorGUILayout.Popup("Used Packages", m_PackageIndex, _buildPackageNames.ToArray()); + if (selectedPackageIndex != m_PackageIndex) + { + m_PackageIndex = selectedPackageIndex; + m_PlayMode.enumValueIndex = selectedIndex + 1; + } + + int defaultIndex = GetDefaultPackageIndex(AssetBundleBuilderSettingData.Setting.BuildPackage); + _buildPackageField = new PopupField(_buildPackageNames, defaultIndex); + _buildPackageField.label = "Build Package"; + _buildPackageField.style.width = 350; + _buildPackageField.RegisterValueChangedCallback(evt => + { + AssetBundleBuilderSettingData.IsDirty = true; + AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageField.value; + }); + } + else + { + GUILayout.Label("Please Create Packages with YooAssets ...!"); + } + } + + m_ReadWritePathType.enumValueIndex = (int)(ReadWritePathType)EditorGUILayout.EnumPopup("Read-Write Path Type", t.ReadWritePathType); + } + EditorGUI.EndDisabledGroup(); + + int milliseconds = EditorGUILayout.DelayedIntField("Milliseconds", m_Milliseconds.intValue); + if (milliseconds != m_Milliseconds.intValue) + { + if (EditorApplication.isPlaying) + { + t.milliseconds = milliseconds; + } + else + { + m_Milliseconds.longValue = milliseconds; + } + } + + float minUnloadUnusedAssetsInterval = EditorGUILayout.Slider("Min Unload Unused Assets Interval", m_MinUnloadUnusedAssetsInterval.floatValue, 0f, 3600f); + if (Math.Abs(minUnloadUnusedAssetsInterval - m_MinUnloadUnusedAssetsInterval.floatValue) > 0.001f) + { + if (EditorApplication.isPlaying) + { + t.MinUnloadUnusedAssetsInterval = minUnloadUnusedAssetsInterval; + } + else + { + m_MinUnloadUnusedAssetsInterval.floatValue = minUnloadUnusedAssetsInterval; + } + } + + float maxUnloadUnusedAssetsInterval = EditorGUILayout.Slider("Max Unload Unused Assets Interval", m_MaxUnloadUnusedAssetsInterval.floatValue, 0f, 3600f); + if (Math.Abs(maxUnloadUnusedAssetsInterval - m_MaxUnloadUnusedAssetsInterval.floatValue) > 0.001f) + { + if (EditorApplication.isPlaying) + { + t.MaxUnloadUnusedAssetsInterval = maxUnloadUnusedAssetsInterval; + } + else + { + m_MaxUnloadUnusedAssetsInterval.floatValue = maxUnloadUnusedAssetsInterval; + } + } + + float downloadingMaxNum = EditorGUILayout.Slider("Max Downloading Num", m_DownloadingMaxNum.intValue, 1f, 48f); + if (Math.Abs(downloadingMaxNum - m_DownloadingMaxNum.intValue) > 0.001f) + { + if (EditorApplication.isPlaying) + { + t.downloadingMaxNum = (int)downloadingMaxNum; + } + else + { + m_DownloadingMaxNum.intValue = (int)downloadingMaxNum; + } + } + + float failedTryAgain = EditorGUILayout.Slider("Max FailedTryAgain Count", m_FailedTryAgain.intValue, 1f, 48f); + if (Math.Abs(failedTryAgain - m_FailedTryAgain.intValue) > 0.001f) + { + if (EditorApplication.isPlaying) + { + t.failedTryAgain = (int)failedTryAgain; + } + else + { + m_FailedTryAgain.intValue = (int)failedTryAgain; + } + } + + + if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) + { + EditorGUILayout.LabelField("Unload Unused Assets", + Utility.Text.Format("{0:F2} / {1:F2}", t.LastUnloadUnusedAssetsOperationElapseSeconds, t.MaxUnloadUnusedAssetsInterval)); + EditorGUILayout.LabelField("Read-Only Path", t.ReadOnlyPath.ToString()); + EditorGUILayout.LabelField("Read-Write Path", t.ReadWritePath.ToString()); + EditorGUILayout.LabelField("Applicable Game Version", t.ApplicableGameVersion ?? ""); + EditorGUILayout.LabelField("Internal Resource Version", t.InternalResourceVersion.ToString()); + } + + serializedObject.ApplyModifiedProperties(); + + Repaint(); + } + + protected override void OnCompileComplete() + { + base.OnCompileComplete(); + + RefreshTypeNames(); + } + + private void RefreshTypeNames() + { + serializedObject.ApplyModifiedProperties(); + } + + // 构建包裹相关 + private int GetDefaultPackageIndex(string packageName) + { + for (int index = 0; index < _buildPackageNames.Count; index++) + { + if (_buildPackageNames[index] == packageName) + { + return index; + } + } + + AssetBundleBuilderSettingData.IsDirty = true; + AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageNames[0]; + return 0; + } + + private List GetBuildPackageNames() + { + List result = new List(); + foreach (var package in AssetBundleCollectorSettingData.Setting.Packages) + { + result.Add(package.PackageName); + } + + return result; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs.meta b/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs.meta new file mode 100644 index 00000000..a91fd9fa --- /dev/null +++ b/Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 78be88e0b69747ffbbcf360389dd4d4b +timeCreated: 1680590523 \ No newline at end of file diff --git a/Assets/TEngine/Editor/TEngine.Editor.asmdef b/Assets/TEngine/Editor/TEngine.Editor.asmdef index 1d755b1d..a1b7c605 100644 --- a/Assets/TEngine/Editor/TEngine.Editor.asmdef +++ b/Assets/TEngine/Editor/TEngine.Editor.asmdef @@ -2,7 +2,8 @@ "name": "TEngine.Editor", "rootNamespace": "", "references": [ - "TEngine.Runtime" + "TEngine.Runtime", + "YooAsset.Editor" ], "includePlatforms": [ "Editor" diff --git a/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.EnvironmentInformationWindow.cs b/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.EnvironmentInformationWindow.cs index 163cf2c6..966bebec 100644 --- a/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.EnvironmentInformationWindow.cs +++ b/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.EnvironmentInformationWindow.cs @@ -11,7 +11,7 @@ namespace TEngine { private RootModule _mRootModule = null; - private ResourceModuleBase _mResourceModuleBase = null; + private ResourceModule _mResourceModule = null; public override void Initialize(params object[] args) { @@ -22,8 +22,8 @@ namespace TEngine return; } - _mResourceModuleBase = GameEntry.GetModule(); - if (_mResourceModuleBase == null) + _mResourceModule = GameEntry.GetModule(); + if (_mResourceModule == null) { Log.Fatal("Resource component is invalid."); return; @@ -44,7 +44,7 @@ namespace TEngine #endif DrawItem("Game Framework Version", Version.GameFrameworkVersion); DrawItem("Game Version", Utility.Text.Format("{0} ({1})", Version.GameVersion, Version.InternalGameVersion)); - DrawItem("Resource Version", (string.IsNullOrEmpty(_mResourceModuleBase.ApplicableGameVersion) ? "Unknown" : Utility.Text.Format("{0} ({1})", _mResourceModuleBase.ApplicableGameVersion, _mResourceModuleBase.InternalResourceVersion))); + DrawItem("Resource Version", (string.IsNullOrEmpty(_mResourceModule.ApplicableGameVersion) ? "Unknown" : Utility.Text.Format("{0} ({1})", _mResourceModule.ApplicableGameVersion, _mResourceModule.InternalResourceVersion))); DrawItem("Application Version", Application.version); DrawItem("Unity Version", Application.unityVersion); DrawItem("Platform", Application.platform.ToString()); diff --git a/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.OperationsWindow.cs b/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.OperationsWindow.cs index 8a0eb064..cab0b61c 100644 --- a/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.OperationsWindow.cs +++ b/Assets/TEngine/Runtime/GameFramework/Debugger/Component/DebuggerModule.OperationsWindow.cs @@ -25,7 +25,7 @@ namespace TEngine } } - ResourceModuleBase resourceCompoent = GameEntry.GetModule(); + ResourceModule resourceCompoent = GameEntry.GetModule(); if (resourceCompoent != null) { if (GUILayout.Button("Unload Unused Assets", GUILayout.Height(30f))) diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/IResourceManager.cs b/Assets/TEngine/Runtime/GameFramework/Resource/IResourceManager.cs index c06ca3ae..1e66d407 100644 --- a/Assets/TEngine/Runtime/GameFramework/Resource/IResourceManager.cs +++ b/Assets/TEngine/Runtime/GameFramework/Resource/IResourceManager.cs @@ -106,19 +106,21 @@ namespace TEngine /// /// 同步加载资源。 /// + /// 资源操作句柄。 /// 要加载资源的名称。 /// 要加载资源的类型。 /// 资源实例。 - T LoadAsset(string assetName) where T : UnityEngine.Object; + T LoadAsset(string assetName,out AssetOperationHandle handle) where T : UnityEngine.Object; /// /// 同步加载资源。 /// /// 要加载资源的名称。 + /// 资源操作句柄。 /// 父节点位置。 /// 要加载资源的类型。 /// 资源实例。 - T LoadAsset(string assetName, Transform parent) where T : UnityEngine.Object; + T LoadAsset(string assetName, Transform parent,out AssetOperationHandle handle) where T : UnityEngine.Object; /// /// 异步加载资源。 diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceManager.cs b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceManager.cs index 8645e514..6d528b11 100644 --- a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceManager.cs +++ b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceManager.cs @@ -165,12 +165,12 @@ namespace TEngine throw new System.NotImplementedException(); } - public T LoadAsset(string assetName) where T : Object + public T LoadAsset(string assetName,out AssetOperationHandle handle) where T : Object { throw new System.NotImplementedException(); } - public T LoadAsset(string assetName, Transform parent) where T : Object + public T LoadAsset(string assetName, Transform parent,out AssetOperationHandle handle) where T : Object { throw new System.NotImplementedException(); } diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs new file mode 100644 index 00000000..a4d16e22 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs @@ -0,0 +1,284 @@ +using System; +using UnityEngine; +using UnityEngine.Serialization; +using YooAsset; + +namespace TEngine +{ + /// + /// 资源模块。 + /// + [DisallowMultipleComponent] + public class ResourceModule : GameFrameworkModuleBase + { + #region Propreties + /// + /// 获取当前资源适用的游戏版本号。 + /// + public string ApplicableGameVersion => m_ResourceManager?.ApplicableGameVersion ?? "Unknown"; + + /// + /// 获取当前内部资源版本号。 + /// + public int InternalResourceVersion => m_ResourceManager?.InternalResourceVersion ?? 0; + + /// + /// 默认资源加载优先级。 + /// + public const int DefaultPriority = 0; + + /// + /// 当前最新的包裹版本。 + /// + public string PackageVersion { set; get; } + + /// + /// 资源包名称。 + /// + public string packageName = "DefaultPackage"; + + /// + /// 资源系统运行模式。 + /// + public EPlayMode playMode = EPlayMode.EditorSimulateMode; + + /// + /// 下载文件校验等级。 + /// + public EVerifyLevel verifyLevel = EVerifyLevel.Middle; + + /// + /// 资源下载器,用于下载当前资源版本所有的资源包文件。 + /// + public ResourceDownloaderOperation Downloader { get; set; } + + [SerializeField] + private ReadWritePathType readWritePathType = ReadWritePathType.Unspecified; + + [SerializeField] + private float minUnloadUnusedAssetsInterval = 60f; + + [SerializeField] + private float maxUnloadUnusedAssetsInterval = 300f; + + /// + /// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒) + /// + public long milliseconds = 30; + public int downloadingMaxNum = 3; + public int failedTryAgain = 3; + + private IResourceManager m_ResourceManager; + private AsyncOperation m_AsyncOperation = null; + private bool m_ForceUnloadUnusedAssets = false; + private bool m_PreorderUnloadUnusedAssets = false; + private bool m_PerformGCCollect = false; + private float m_LastUnloadUnusedAssetsOperationElapseSeconds = 0f; + + /// + /// 获取或设置同时最大下载数目。 + /// + public int DownloadingMaxNum + { + get => downloadingMaxNum; + set => downloadingMaxNum = value; + } + + /// + /// 失败尝试数目。 + /// + public int FailedTryAgain + { + get => failedTryAgain; + set => failedTryAgain = value; + } + + /// + /// 获取资源读写路径类型。 + /// + public ReadWritePathType ReadWritePathType => readWritePathType; + + /// + /// 获取或设置无用资源释放的最小间隔时间,以秒为单位。 + /// + public float MinUnloadUnusedAssetsInterval + { + get => minUnloadUnusedAssetsInterval; + set => minUnloadUnusedAssetsInterval = value; + } + + /// + /// 获取或设置无用资源释放的最大间隔时间,以秒为单位。 + /// + public float MaxUnloadUnusedAssetsInterval + { + get => maxUnloadUnusedAssetsInterval; + set => maxUnloadUnusedAssetsInterval = value; + } + + /// + /// 获取无用资源释放的等待时长,以秒为单位。 + /// + public float LastUnloadUnusedAssetsOperationElapseSeconds => m_LastUnloadUnusedAssetsOperationElapseSeconds; + + /// + /// 获取资源只读路径。 + /// + public string ReadOnlyPath => m_ResourceManager.ReadOnlyPath; + + /// + /// 获取资源读写路径。 + /// + public string ReadWritePath => m_ResourceManager.ReadWritePath; + + #endregion + + private void Start() + { + RootModule baseComponent = GameEntry.GetModule(); + if (baseComponent == null) + { + Log.Fatal("Base component is invalid."); + return; + } + + m_ResourceManager = GameFrameworkEntry.GetModule(); + if (m_ResourceManager == null) + { + Log.Fatal("YooAssetsManager component is invalid."); + return; + } + + if (playMode == EPlayMode.EditorSimulateMode) + { + Log.Info("During this run, Game Framework will use editor resource files, which you should validate first."); +#if !UNITY_EDITOR + playMode = EPlayMode.OfflinePlayMode; +#endif + } + + m_ResourceManager.SetReadOnlyPath(Application.streamingAssetsPath); + if (readWritePathType == ReadWritePathType.TemporaryCache) + { + m_ResourceManager.SetReadWritePath(Application.temporaryCachePath); + } + else + { + if (readWritePathType == ReadWritePathType.Unspecified) + { + readWritePathType = ReadWritePathType.PersistentData; + } + + m_ResourceManager.SetReadWritePath(Application.persistentDataPath); + } + + m_ResourceManager.PackageName = packageName; + m_ResourceManager.PlayMode = playMode; + m_ResourceManager.VerifyLevel = verifyLevel; + m_ResourceManager.Milliseconds = milliseconds; + m_ResourceManager.Initialize(); + Log.Info($"AssetsComponent Run Mode:{playMode}"); + } + + /// + /// 初始化操作。 + /// + /// + public InitializationOperation InitPackage() + { + return m_ResourceManager.InitPackage(); + } + + /// + /// 异步更新最新包的版本。 + /// + /// + /// 超时时间。 + /// 请求远端包裹的最新版本操作句柄。 + public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60) + { + var package = YooAssets.GetPackage(packageName); + return package.UpdatePackageVersionAsync(appendTimeTicks,timeout); + } + + /// + /// 异步更新最新包的Manifest文件。 + /// + /// 包版本信息。 + /// 超时时间。 + /// 向远端请求并更新清单操作句柄。 + public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60) + { + var package = YooAssets.GetPackage(packageName); + return package.UpdatePackageManifestAsync(packageVersion,timeout); + } + + /// + /// 创建资源下载器,用于下载当前资源版本所有的资源包文件。 + /// + public ResourceDownloaderOperation CreateResourceDownloader() + { + var package = YooAssets.GetPackage(packageName); + Downloader = package.CreateResourceDownloader(downloadingMaxNum,failedTryAgain); + return Downloader; + } + + /// + /// 清理包裹未使用的缓存文件。 + /// + public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync() + { + var package = YooAssets.GetPackage(packageName); + return package.ClearUnusedCacheFilesAsync(); + } + + /// + /// 清理沙盒路径。 + /// + public void ClearSandbox() + { + YooAssets.ClearSandbox(); + } + + /// + /// 强制执行释放未被使用的资源。 + /// + /// 是否使用垃圾回收。 + public void ForceUnloadUnusedAssets(bool performGCCollect) + { + m_ForceUnloadUnusedAssets = true; + if (performGCCollect) + { + m_PerformGCCollect = true; + } + } + + /// + /// 资源模块外部轮询(释放无用资源)。 + /// + private void Update() + { + m_LastUnloadUnusedAssetsOperationElapseSeconds += Time.unscaledDeltaTime; + if (m_AsyncOperation == null && (m_ForceUnloadUnusedAssets || m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval || m_PreorderUnloadUnusedAssets && m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval)) + { + Log.Info("Unload unused assets..."); + m_ForceUnloadUnusedAssets = false; + m_PreorderUnloadUnusedAssets = false; + m_LastUnloadUnusedAssetsOperationElapseSeconds = 0f; + m_AsyncOperation = Resources.UnloadUnusedAssets(); + } + + if (m_AsyncOperation is { isDone: true }) + { + m_ResourceManager.UnloadUnusedAssets(); + m_AsyncOperation = null; + if (m_PerformGCCollect) + { + Log.Info("GC.Collect..."); + m_PerformGCCollect = false; + GC.Collect(); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs.meta b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs.meta new file mode 100644 index 00000000..3f13e853 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6e9edd9af2004f138ce8c543a2509393 +timeCreated: 1680588655 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs deleted file mode 100644 index 540e0ef0..00000000 --- a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using UnityEngine; - -namespace TEngine -{ - [DisallowMultipleComponent] - public class ResourceModuleBase: GameFrameworkModuleBase - { - private IResourceManager m_ResourceManager; - - /// - /// 获取当前资源适用的游戏版本号。 - /// - public string ApplicableGameVersion => m_ResourceManager?.ApplicableGameVersion ?? "Unknown"; - - /// - /// 获取当前内部资源版本号。 - /// - public int InternalResourceVersion => m_ResourceManager?.InternalResourceVersion ?? 0; - - /// - /// 强制执行释放未被使用的资源。 - /// - /// 是否使用垃圾回收。 - public void ForceUnloadUnusedAssets(bool performGCCollect) - { - - } - - private void Start() - { - - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs.meta b/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs.meta deleted file mode 100644 index 1f15b25b..00000000 --- a/Assets/TEngine/Runtime/GameFramework/Resource/ResourceModuleBase.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 77d67944806247f99024bf5307adc918 -timeCreated: 1680501384 \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/RootModule.cs b/Assets/TEngine/Runtime/GameFramework/RootModule.cs index a88b5701..9b11fc90 100644 --- a/Assets/TEngine/Runtime/GameFramework/RootModule.cs +++ b/Assets/TEngine/Runtime/GameFramework/RootModule.cs @@ -235,13 +235,13 @@ namespace TEngine 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); + Version.IVersionHelper versionHelper = (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); + Version.SetVersionHelper(versionHelper); } private void InitLogHelper() @@ -324,10 +324,10 @@ namespace TEngine objectPoolModule.ReleaseAllUnused(); } - ResourceModuleBase resourceModuleBase = GameEntry.GetModule(); - if (resourceModuleBase != null) + ResourceModule ResourceModule = GameEntry.GetModule(); + if (ResourceModule != null) { - resourceModuleBase.ForceUnloadUnusedAssets(true); + ResourceModule.ForceUnloadUnusedAssets(true); } } } diff --git a/Assets/TEngine/Runtime/GameFramework/UI/DefaultUIWindowHelper.cs b/Assets/TEngine/Runtime/GameFramework/UI/DefaultUIWindowHelper.cs index 05d20567..1fa3a982 100644 --- a/Assets/TEngine/Runtime/GameFramework/UI/DefaultUIWindowHelper.cs +++ b/Assets/TEngine/Runtime/GameFramework/UI/DefaultUIWindowHelper.cs @@ -7,7 +7,7 @@ namespace TEngine /// public class DefaultUIWindowHelper : UIWindowHelperBase { - private ResourceModuleBase _mResourceModuleBase = null; + private ResourceModule _mResourceModule = null; private Vector2 m_Half = new Vector2(0.5f,0.5f); @@ -16,8 +16,8 @@ namespace TEngine private void Start() { m_UILayer = LayerMask.NameToLayer("UI"); - _mResourceModuleBase = GameEntry.GetModule(); - if (_mResourceModuleBase == null) + _mResourceModule = GameEntry.GetModule(); + if (_mResourceModule == null) { Log.Fatal("Resource component is invalid."); return; diff --git a/Assets/TEngine/Runtime/GameModule.cs b/Assets/TEngine/Runtime/GameModule.cs index 4b4fdc67..8c6f6b9e 100644 --- a/Assets/TEngine/Runtime/GameModule.cs +++ b/Assets/TEngine/Runtime/GameModule.cs @@ -32,7 +32,7 @@ public class GameModule:MonoBehaviour /// /// 获取资源模块。 /// - public static ResourceModuleBase Resource { get; private set; } + public static ResourceModule Resource { get; private set; } /// /// 获取配置模块。 @@ -55,7 +55,7 @@ public class GameModule:MonoBehaviour Debugger = Get(); Fsm = Get(); ObjectPool = Get(); - Resource = Get(); + Resource = Get(); Setting = Get(); UI = Get(); }