From 5e86bc279ef848f72bc9e8c38647914a4cd8353e Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Sat, 1 Apr 2023 23:24:47 +0800
Subject: [PATCH] Update ResourceManager.cs
---
.../Runtime/Resource/ResourceManager.cs | 127 ++++++++++++++++--
1 file changed, 117 insertions(+), 10 deletions(-)
diff --git a/Assets/TEngine/Runtime/Resource/ResourceManager.cs b/Assets/TEngine/Runtime/Resource/ResourceManager.cs
index 3c8e951e..8645e514 100644
--- a/Assets/TEngine/Runtime/Resource/ResourceManager.cs
+++ b/Assets/TEngine/Runtime/Resource/ResourceManager.cs
@@ -1,32 +1,139 @@
-using System.Threading;
+using System.Diagnostics;
+using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using YooAsset;
namespace TEngine
{
- internal partial class ResourceManager:IResourceManager
+ ///
+ /// 资源管理器。
+ ///
+ internal partial class ResourceManager: GameFrameworkModule,IResourceManager
{
- public string ApplicableGameVersion { get; }
- public int InternalResourceVersion { get; }
+ #region Propreties
+ ///
+ /// 资源包名称。
+ ///
+ public string PackageName { get; set; } = "DefaultPackage";
+
+ ///
+ /// 获取当前资源适用的游戏版本号。
+ ///
+ public string ApplicableGameVersion => m_ApplicableGameVersion;
+
+ private string m_ApplicableGameVersion;
+
+ ///
+ /// 获取当前内部资源版本号。
+ ///
+ public int InternalResourceVersion => m_InternalResourceVersion;
+
+ private int m_InternalResourceVersion;
+
+ ///
+ /// 同时下载的最大数目。
+ ///
public int DownloadingMaxNum { get; set; }
+
+ ///
+ /// 失败重试最大数目。
+ ///
public int FailedTryAgain { get; set; }
- public string ReadOnlyPath { get; }
- public string ReadWritePath { get; }
- public string PackageName { get; set; }
+
+ ///
+ /// 获取资源只读区路径。
+ ///
+ public string ReadOnlyPath => m_ReadOnlyPath;
+
+ private string m_ReadOnlyPath;
+
+ ///
+ /// 获取资源读写区路径。
+ ///
+ public string ReadWritePath => m_ReadWritePath;
+
+ private string m_ReadWritePath;
+
+ ///
+ /// 资源系统运行模式。
+ ///
public EPlayMode PlayMode { get; set; }
+
+ ///
+ /// 下载文件校验等级。
+ ///
public EVerifyLevel VerifyLevel { get; set; }
+
+ ///
+ /// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)。
+ ///
public long Milliseconds { get; set; }
- public void SetReadOnlyPath(string readOnlyPath)
+ ///
+ /// The total number of frames since the start of the game (Read Only).
+ ///
+ private static int _lastUpdateFrame = 0;
+
+ ///
+ /// 获取游戏框架模块优先级。
+ ///
+ /// 优先级较高的模块会优先轮询,并且关闭操作会后进行。
+ internal override int Priority => 4;
+ #endregion
+
+ internal override void Update(float elapseSeconds, float realElapseSeconds)
{
- throw new System.NotImplementedException();
+ DebugCheckDuplicateDriver();
+ YooAssets.Update();
+ }
+
+ [Conditional("DEBUG")]
+ private void DebugCheckDuplicateDriver()
+ {
+ if (_lastUpdateFrame > 0)
+ {
+ if (_lastUpdateFrame == Time.frameCount)
+ YooLogger.Warning($"There are two {nameof(YooAssetsDriver)} in the scene. Please ensure there is always exactly one driver in the scene.");
+ }
+
+ _lastUpdateFrame = Time.frameCount;
}
+ internal override void Shutdown()
+ {
+ YooAssets.Destroy();
+ }
+
+ #region 设置接口
+ ///
+ /// 设置资源只读区路径。
+ ///
+ /// 资源只读区路径。
+ public void SetReadOnlyPath(string readOnlyPath)
+ {
+ if (string.IsNullOrEmpty(readOnlyPath))
+ {
+ throw new GameFrameworkException("Read-only path is invalid.");
+ }
+
+ m_ReadOnlyPath = readOnlyPath;
+ }
+
+ ///
+ /// 设置资源读写区路径。
+ ///
+ /// 资源读写区路径。
public void SetReadWritePath(string readWritePath)
{
- throw new System.NotImplementedException();
+ if (string.IsNullOrEmpty(readWritePath))
+ {
+ throw new GameFrameworkException("Read-write path is invalid.");
+ }
+
+ m_ReadWritePath = readWritePath;
}
+ #endregion
public void Initialize()
{