diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index e2f8c96..4ff1842 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -344,6 +344,7 @@ namespace YooAsset providerInfo.AssetPath = provider.MainAssetInfo.AssetPath; providerInfo.SpawnScene = provider.SpawnScene; providerInfo.SpawnTime = provider.SpawnTime; + providerInfo.LoadingTime = provider.LoadingTime; providerInfo.RefCount = provider.RefCount; providerInfo.Status = (int)provider.Status; providerInfo.DependBundleInfos = new List(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs index 814b30c..5ff8b4a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs @@ -22,6 +22,8 @@ namespace YooAsset } public override void Update() { + DebugRecording(); + if (IsDone) return; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs index e100a34..4bef023 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; namespace YooAsset { - internal abstract class BundledProvider : ProviderBase - { + internal abstract class BundledProvider : ProviderBase + { protected AssetBundleLoaderBase OwnerBundle { private set; get; } protected DependAssetBundleGroup DependBundleGroup { private set; get; } - public BundledProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) + public BundledProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo) { OwnerBundle = impl.CreateOwnerAssetBundleLoader(assetInfo); OwnerBundle.Reference(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs index 5a95701..7792224 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs @@ -32,6 +32,8 @@ namespace YooAsset } public override void Update() { + DebugRecording(); + if (IsDone) return; @@ -97,7 +99,7 @@ namespace YooAsset SceneManager.SetActiveScene(SceneObject); Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; - if(Status == EStatus.Fail) + if (Status == EStatus.Fail) { LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs index 4f4e337..2e9cf81 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs @@ -22,6 +22,8 @@ namespace YooAsset } public override void Update() { + DebugRecording(); + if (IsDone) return; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index c0a8885..2c2fa1c 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -238,6 +238,17 @@ namespace YooAsset /// public string SpawnTime = string.Empty; + /// + /// 加载耗时(单位:毫秒) + /// + public long LoadingTime { protected set; get; } + +#if DEBUG + // 加载耗时统计 + private bool _isRecording = false; + private Stopwatch _watch; +#endif + [Conditional("DEBUG")] public void InitSpawnDebugInfo() { @@ -251,6 +262,25 @@ namespace YooAsset float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f); return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00"); } + + [Conditional("DEBUG")] + protected void DebugRecording() + { + if (_isRecording == false) + { + _isRecording = true; + _watch = Stopwatch.StartNew(); + } + + if (_watch != null) + { + if (IsDone) + { + LoadingTime = _watch.ElapsedMilliseconds; + _watch = null; + } + } + } #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs index 6aea281..ce14e35 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs @@ -27,6 +27,11 @@ namespace YooAsset /// public string SpawnTime; + /// + /// 加载耗时(单位:毫秒) + /// + public long LoadingTime; + /// /// 引用计数 ///