From bb64ff727842e8f7efcec77667738ebe7e06202e Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 21 Oct 2022 18:36:03 +0800 Subject: [PATCH] update runtime code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了ILocationServices接口类。 增加了bool CheckLocationValid(string location)方法。 --- .../Runtime/AssetSystem/AssetSystem.cs | 3 + Assets/YooAsset/Runtime/AssetsPackage.cs | 79 +++++++------------ .../YooAsset/Runtime/InitializeParameters.cs | 5 -- .../Runtime/PatchSystem/PatchManifest.cs | 17 ++++ .../PlayMode/EditorSimulateModeImpl.cs | 4 + .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 4 + .../PlayMode/OfflinePlayModeImpl.cs | 4 + .../Runtime/Services/IBundleServices.cs | 5 ++ .../Runtime/Services/ILocationServices.cs | 11 --- .../Services/ILocationServices.cs.meta | 11 --- .../Runtime/Services/LocationServices.meta | 8 -- .../AddressLocationServices.cs | 11 --- .../AddressLocationServices.cs.meta | 11 --- .../DefaultLocationServices.cs | 27 ------- .../DefaultLocationServices.cs.meta | 11 --- Assets/YooAsset/Runtime/YooAssetsExtension.cs | 7 +- 16 files changed, 70 insertions(+), 148 deletions(-) delete mode 100644 Assets/YooAsset/Runtime/Services/ILocationServices.cs delete mode 100644 Assets/YooAsset/Runtime/Services/ILocationServices.cs.meta delete mode 100644 Assets/YooAsset/Runtime/Services/LocationServices.meta delete mode 100644 Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs delete mode 100644 Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta delete mode 100644 Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs delete mode 100644 Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index aa4265d..6e7c693 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -142,6 +142,7 @@ namespace YooAsset { if (assetInfo.IsInvalid) { + YooLogger.Error($"Failed to load scene. {assetInfo.Error}"); CompletedProvider completedProvider = new CompletedProvider(assetInfo); completedProvider.SetCompleted(assetInfo.Error); return completedProvider.CreateHandle(); @@ -190,6 +191,7 @@ namespace YooAsset { if (assetInfo.IsInvalid) { + YooLogger.Error($"Failed to load asset. {assetInfo.Error}"); CompletedProvider completedProvider = new CompletedProvider(assetInfo); completedProvider.SetCompleted(assetInfo.Error); return completedProvider.CreateHandle(); @@ -216,6 +218,7 @@ namespace YooAsset { if (assetInfo.IsInvalid) { + YooLogger.Error($"Failed to load sub assets. {assetInfo.Error}"); CompletedProvider completedProvider = new CompletedProvider(assetInfo); completedProvider.SetCompleted(assetInfo.Error); return completedProvider.CreateHandle(); diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/AssetsPackage.cs index 82f63c1..5692d8b 100644 --- a/Assets/YooAsset/Runtime/AssetsPackage.cs +++ b/Assets/YooAsset/Runtime/AssetsPackage.cs @@ -13,7 +13,6 @@ namespace YooAsset private EOperationStatus _initializeStatus = EOperationStatus.None; private EPlayMode _playMode; private IBundleServices _bundleServices; - private ILocationServices _locationServices; private AssetSystemImpl _assetSystemImpl; private EditorSimulateModeImpl _editorSimulateModeImpl; private OfflinePlayModeImpl _offlinePlayModeImpl; @@ -33,7 +32,7 @@ namespace YooAsset } - internal AssetsPackage() + private AssetsPackage() { } internal AssetsPackage(string packageName) @@ -62,7 +61,6 @@ namespace YooAsset _initializeStatus = EOperationStatus.None; _bundleServices = null; - _locationServices = null; _editorSimulateModeImpl = null; _offlinePlayModeImpl = null; _hostPlayModeImpl = null; @@ -72,8 +70,6 @@ namespace YooAsset _assetSystemImpl.DestroyAll(); _assetSystemImpl = null; } - - YooLogger.Log("YooAssets destroy all !"); } } @@ -87,7 +83,6 @@ namespace YooAsset // 初始化资源系统 InitializationOperation initializeOperation; - _locationServices = parameters.LocationServices; _assetSystemImpl = new AssetSystemImpl(); if (_playMode == EPlayMode.EditorSimulateMode) { @@ -143,9 +138,6 @@ namespace YooAsset throw new Exception($"Editor simulate mode only support unity editor."); #endif - if (parameters.LocationServices == null) - throw new Exception($"{nameof(ILocationServices)} is null."); - if (parameters is EditorSimulateModeParameters) { var editorSimulateModeParameters = parameters as EditorSimulateModeParameters; @@ -335,7 +327,10 @@ namespace YooAsset DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); if (assetInfo.IsInvalid) + { + YooLogger.Warning(assetInfo.Error); return false; + } BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) @@ -397,14 +392,14 @@ namespace YooAsset } /// - /// 获取资源路径 + /// 检查资源定位地址是否有效 /// /// 资源的定位地址 - /// 如果location地址无效,则返回空字符串 - public string GetAssetPath(string location) + public bool CheckLocationValid(string location) { DebugCheckInitialize(); - return _locationServices.ConvertLocationToAssetPath(this, location); + string assetPath = _bundleServices.TryMappingToAssetPath(location); + return string.IsNullOrEmpty(assetPath) == false; } #endregion @@ -429,8 +424,6 @@ namespace YooAsset public RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); return GetRawFileInternal(assetInfo, copyPath); } @@ -439,6 +432,7 @@ namespace YooAsset { if (assetInfo.IsInvalid) { + YooLogger.Error($"Failed to get raw file. {assetInfo.Error}"); RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath); OperationSystem.StartOperation(operation); return operation; @@ -508,8 +502,6 @@ namespace YooAsset public SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); var handle = _assetSystemImpl.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); return handle; } @@ -523,8 +515,6 @@ namespace YooAsset public AssetOperationHandle LoadAssetSync(AssetInfo assetInfo) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); return LoadAssetInternal(assetInfo, true); } @@ -560,8 +550,6 @@ namespace YooAsset public AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); return LoadAssetInternal(assetInfo, false); } @@ -593,14 +581,17 @@ namespace YooAsset private AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete) { #if UNITY_EDITOR - BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); - if (bundleInfo.Bundle.IsRawFile) + if (assetInfo.IsInvalid == false) { - string error = $"Cannot load raw file using LoadAsset method !"; - YooLogger.Error(error); - CompletedProvider completedProvider = new CompletedProvider(assetInfo); - completedProvider.SetCompleted(error); - return completedProvider.CreateHandle(); + BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); + if (bundleInfo.Bundle.IsRawFile) + { + string error = $"Cannot load raw file using LoadAsset method !"; + YooLogger.Error(error); + CompletedProvider completedProvider = new CompletedProvider(assetInfo); + completedProvider.SetCompleted(error); + return completedProvider.CreateHandle(); + } } #endif @@ -619,8 +610,6 @@ namespace YooAsset public SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); return LoadSubAssetsInternal(assetInfo, true); } @@ -656,8 +645,6 @@ namespace YooAsset public SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) { DebugCheckInitialize(); - if (assetInfo.IsInvalid) - YooLogger.Warning(assetInfo.Error); return LoadSubAssetsInternal(assetInfo, false); } @@ -689,14 +676,17 @@ namespace YooAsset private SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete) { #if UNITY_EDITOR - BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); - if (bundleInfo.Bundle.IsRawFile) + if (assetInfo.IsInvalid == false) { - string error = $"Cannot load raw file using LoadSubAssets method !"; - YooLogger.Error(error); - CompletedProvider completedProvider = new CompletedProvider(assetInfo); - completedProvider.SetCompleted(error); - return completedProvider.CreateHandle(); + BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); + if (bundleInfo.Bundle.IsRawFile) + { + string error = $"Cannot load raw file using LoadSubAssets method !"; + YooLogger.Error(error); + CompletedProvider completedProvider = new CompletedProvider(assetInfo); + completedProvider.SetCompleted(error); + return completedProvider.CreateHandle(); + } } #endif @@ -940,14 +930,6 @@ namespace YooAsset #endregion #region 内部方法 - /// - /// 资源定位地址转换为资源完整路径 - /// - internal string MappingToAssetPath(string location) - { - return _bundleServices.MappingToAssetPath(location); - } - /// /// 是否包含资源文件 /// @@ -1014,7 +996,7 @@ namespace YooAsset private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType) { DebugCheckLocation(location); - string assetPath = _locationServices.ConvertLocationToAssetPath(this, location); + string assetPath = _bundleServices.MappingToAssetPath(location); PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath); if (patchAsset != null) { @@ -1028,7 +1010,6 @@ namespace YooAsset error = $"The location is null or empty !"; else error = $"The location is invalid : {location}"; - YooLogger.Error(error); AssetInfo assetInfo = new AssetInfo(error); return assetInfo; } diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index a8664e3..8417830 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -33,11 +33,6 @@ namespace YooAsset /// public bool LocationToLower = false; - /// - /// 资源定位服务接口 - /// - public ILocationServices LocationServices = null; - /// /// 文件解密服务接口 /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index 49cfbfd..36766dc 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -147,6 +147,23 @@ namespace YooAsset } } + /// + /// 尝试映射为资源路径 + /// + public string TryMappingToAssetPath(string location) + { + if (string.IsNullOrEmpty(location)) + return string.Empty; + + if (_locationToLower) + location = location.ToLower(); + + if (AssetPathMapping.TryGetValue(location, out string assetPath)) + return assetPath; + else + return string.Empty; + } + /// /// 获取主资源包 /// 注意:传入的资源路径一定合法有效! diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs index 3dca035..ef92f65 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs @@ -66,6 +66,10 @@ namespace YooAsset { return _simulatePatchManifest.MappingToAssetPath(location); } + string IBundleServices.TryMappingToAssetPath(string location) + { + return _simulatePatchManifest.TryMappingToAssetPath(location); + } string IBundleServices.GetPackageName() { return _simulatePatchManifest.PackageName; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 7a2137f..82ca124 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -392,6 +392,10 @@ namespace YooAsset { return LocalPatchManifest.MappingToAssetPath(location); } + string IBundleServices.TryMappingToAssetPath(string location) + { + return LocalPatchManifest.TryMappingToAssetPath(location); + } string IBundleServices.GetPackageName() { return LocalPatchManifest.PackageName; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index bd41a0f..2217fd2 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -117,6 +117,10 @@ namespace YooAsset { return _appPatchManifest.MappingToAssetPath(location); } + string IBundleServices.TryMappingToAssetPath(string location) + { + return _appPatchManifest.TryMappingToAssetPath(location); + } string IBundleServices.GetPackageName() { return _appPatchManifest.PackageName; diff --git a/Assets/YooAsset/Runtime/Services/IBundleServices.cs b/Assets/YooAsset/Runtime/Services/IBundleServices.cs index a7513c2..8198d72 100644 --- a/Assets/YooAsset/Runtime/Services/IBundleServices.cs +++ b/Assets/YooAsset/Runtime/Services/IBundleServices.cs @@ -28,6 +28,11 @@ namespace YooAsset /// string MappingToAssetPath(string location); + /// + /// 尝试映射为资源路径 + /// + string TryMappingToAssetPath(string location); + /// /// 获取所属的包裹名 /// diff --git a/Assets/YooAsset/Runtime/Services/ILocationServices.cs b/Assets/YooAsset/Runtime/Services/ILocationServices.cs deleted file mode 100644 index e646ed2..0000000 --- a/Assets/YooAsset/Runtime/Services/ILocationServices.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace YooAsset -{ - public interface ILocationServices - { - /// - /// 定位地址转换为资源路径 - /// - string ConvertLocationToAssetPath(AssetsPackage package, string location); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/ILocationServices.cs.meta b/Assets/YooAsset/Runtime/Services/ILocationServices.cs.meta deleted file mode 100644 index 31308ea..0000000 --- a/Assets/YooAsset/Runtime/Services/ILocationServices.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cfc81e18e5b5f6f4b821c7427b34d349 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Services/LocationServices.meta b/Assets/YooAsset/Runtime/Services/LocationServices.meta deleted file mode 100644 index 7825f00..0000000 --- a/Assets/YooAsset/Runtime/Services/LocationServices.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6e400ee1e8b3556479bfa493ff7fe778 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs deleted file mode 100644 index 158396c..0000000 --- a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace YooAsset -{ - public class AddressLocationServices : ILocationServices - { - string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location) - { - return package.MappingToAssetPath(location); - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta deleted file mode 100644 index bb7a512..0000000 --- a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a8d6592eded144142afcf85c79cf1ce4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs deleted file mode 100644 index 4268a90..0000000 --- a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs +++ /dev/null @@ -1,27 +0,0 @@ - -namespace YooAsset -{ - public class DefaultLocationServices : ILocationServices - { - private readonly string _resourceRoot; - - public DefaultLocationServices(string resourceRoot) - { - if (string.IsNullOrEmpty(resourceRoot) == false) - _resourceRoot = PathHelper.GetRegularPath(resourceRoot); - } - - string ILocationServices.ConvertLocationToAssetPath(AssetsPackage package, string location) - { - if (string.IsNullOrEmpty(_resourceRoot)) - { - return package.MappingToAssetPath(location); - } - else - { - string tempLocation = $"{_resourceRoot}/{location}"; - return package.MappingToAssetPath(tempLocation); - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta deleted file mode 100644 index 0d76172..0000000 --- a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8d996937ba73c9b4bb942b8ba6f43398 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/YooAssetsExtension.cs b/Assets/YooAsset/Runtime/YooAssetsExtension.cs index 8b86987..43ce4d9 100644 --- a/Assets/YooAsset/Runtime/YooAssetsExtension.cs +++ b/Assets/YooAsset/Runtime/YooAssetsExtension.cs @@ -70,14 +70,13 @@ namespace YooAsset } /// - /// 获取资源路径 + /// 检查资源定位地址是否有效 /// /// 资源的定位地址 - /// 如果location地址无效,则返回空字符串 - public static string GetAssetPath(string location) + public static bool CheckLocationValid(string location) { DebugCheckDefaultPackageValid(); - return _defaultPackage.GetAssetPath(location); + return _defaultPackage.CheckLocationValid(location); } #endregion