diff --git a/Editor/Files/EditorDatabaseAsset.cs b/Editor/Files/EditorDatabaseAsset.cs index 36c1052..6322d8e 100644 --- a/Editor/Files/EditorDatabaseAsset.cs +++ b/Editor/Files/EditorDatabaseAsset.cs @@ -7,11 +7,11 @@ using System.Threading; using System.Threading.Tasks; using Depra.Assets.Delegates; -using Depra.Assets.Exceptions; using Depra.Assets.Extensions; +using Depra.Assets.ValueObjects; +using Depra.Assets.Exceptions; using Depra.Assets.Files; using Depra.Assets.Files.Database; -using Depra.Assets.ValueObjects; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; diff --git a/Editor/Files/PreloadedAsset.cs b/Editor/Files/PreloadedAsset.cs index 87ef4ec..85a3de1 100644 --- a/Editor/Files/PreloadedAsset.cs +++ b/Editor/Files/PreloadedAsset.cs @@ -7,9 +7,9 @@ using System.Threading; using System.Threading.Tasks; using Depra.Assets.Delegates; +using Depra.Assets.ValueObjects; using Depra.Assets.Exceptions; using Depra.Assets.Files; -using Depra.Assets.ValueObjects; using UnityEditor; using Object = UnityEngine.Object; diff --git a/Plugins/Depra.Assets.dll b/Plugins/Depra.Assets.dll index 517ba53..07e6641 100644 Binary files a/Plugins/Depra.Assets.dll and b/Plugins/Depra.Assets.dll differ diff --git a/Plugins/Depra.Assets.dll.meta b/Plugins/Depra.Assets.dll.meta index db3b087..91521f5 100644 --- a/Plugins/Depra.Assets.dll.meta +++ b/Plugins/Depra.Assets.dll.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 12144cd499077c94f82093417464f995 +guid: 77ba2cc553cbfdb44b728b7ed74e24e7 PluginImporter: externalObjects: {} serializedVersion: 2 @@ -7,7 +7,7 @@ PluginImporter: executionOrder: {} defineConstraints: [] isPreloaded: 0 - isOverridable: 1 + isOverridable: 0 isExplicitlyReferenced: 0 validateReferences: 1 platformData: diff --git a/Runtime/Files.Bundles.meta b/Runtime/Files.Bundles.meta deleted file mode 100644 index 22a3bad..0000000 --- a/Runtime/Files.Bundles.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1b515f5fd5fb4947b51aca6c4d4add4b -timeCreated: 1678833399 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions.meta b/Runtime/Files.Bundles/Exceptions.meta deleted file mode 100644 index 7ecd06f..0000000 --- a/Runtime/Files.Bundles/Exceptions.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a849a6e185684d4e9b7c31aa35363bb3 -timeCreated: 1675007048 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs b/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs deleted file mode 100644 index 75e69be..0000000 --- a/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; - -namespace Depra.Assets.Files.Bundles.Exceptions -{ - internal sealed class AssetBundleFileNotLoaded : Exception - { - public AssetBundleFileNotLoaded(string name, string bundleName) : base( - $"File with name '{name}' form asset bundle '{bundleName}' was not loaded!") { } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs.meta b/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs.meta deleted file mode 100644 index 48de1cf..0000000 --- a/Runtime/Files.Bundles/Exceptions/AssetBundleFileNotLoaded.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0830601e1e2748408111e864be749369 -timeCreated: 1679184587 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs b/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs deleted file mode 100644 index 94ae48d..0000000 --- a/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; - -namespace Depra.Assets.Files.Bundles.Exceptions -{ - internal sealed class AssetBundleNotLoaded : Exception - { - public AssetBundleNotLoaded(string path) : base($"Asset bundle at path '{path}' was not loaded!") { } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs.meta b/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs.meta deleted file mode 100644 index 1924a8c..0000000 --- a/Runtime/Files.Bundles/Exceptions/AssetBundleNotLoaded.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f2cac11d17ff44eeb72d0d577d301d74 -timeCreated: 1678334306 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs b/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs deleted file mode 100644 index 0a26629..0000000 --- a/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using UnityEngine.Networking; - -namespace Depra.Assets.Files.Bundles.Exceptions -{ - internal sealed class UnityWebRequestFailed : Exception - { - private readonly string _text; - private readonly string _error; - - private string _message; - - public UnityWebRequestFailed(UnityWebRequest webRequest) - { - _error = webRequest.error; - if (webRequest.downloadHandler is DownloadHandlerBuffer buffer) - { - _text = buffer.text; - } - - webRequest.GetResponseHeaders(); - } - - public override string Message => _message ??= string.IsNullOrWhiteSpace(_text) == false - ? _error + Environment.NewLine + _text - : _error; - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs.meta b/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs.meta deleted file mode 100644 index b36b933..0000000 --- a/Runtime/Files.Bundles/Exceptions/UnityWebRequestFailed.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0136a5931ea44508a55463712109d3cb -timeCreated: 1693691555 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions.meta b/Runtime/Files.Bundles/Extensions.meta deleted file mode 100644 index 0d8e0ed..0000000 --- a/Runtime/Files.Bundles/Extensions.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 377f0e77315e477e9f0d161a2816af1c -timeCreated: 1679185654 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs b/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs deleted file mode 100644 index 5079a56..0000000 --- a/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles.Extensions -{ - internal static class AssetBundleCreateRequestExtensions - { - public static Task ToTask(this AssetBundleCreateRequest self, - Action onProgress = null, CancellationToken cancellationToken = default) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - - return self.isDone - ? Task.FromResult(self.assetBundle) - : AwaitWithProgress(self, onProgress, cancellationToken); - } - - private async static Task AwaitWithProgress(this AssetBundleCreateRequest self, - Action onProgress, CancellationToken cancellationToken = default) - { - while (self.isDone == false) - { - if (cancellationToken.IsCancellationRequested) - { - return await Task.FromCanceled(cancellationToken); - } - - onProgress?.Invoke(self.progress); - await Task.Yield(); - } - - return self.assetBundle; - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs.meta b/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs.meta deleted file mode 100644 index 145a2db..0000000 --- a/Runtime/Files.Bundles/Extensions/AssetBundleCreateRequestExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0b729d14e0b8448e82a608f61f52207a -timeCreated: 1693689257 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs b/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs deleted file mode 100644 index 1258d8d..0000000 --- a/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Depra.Assets.Files.Bundles.Extensions -{ - internal static class AssetBundleRequestExtensions - { - public static Task ToTask(this AssetBundleRequest self, Action onProgress = null, - CancellationToken cancellationToken = default) => cancellationToken.IsCancellationRequested - ? Task.FromCanceled(cancellationToken) - : self.isDone - ? Task.FromResult(self.asset) - : AwaitWithProgress(self, onProgress, cancellationToken); - - private async static Task AwaitWithProgress(this AssetBundleRequest self, - Action onProgress, CancellationToken cancellationToken = default) - { - while (self.isDone == false) - { - if (cancellationToken.IsCancellationRequested) - { - return await Task.FromCanceled(cancellationToken); - } - - onProgress?.Invoke(self.progress); - await Task.Yield(); - } - - return self.asset; - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs.meta b/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs.meta deleted file mode 100644 index 4df0150..0000000 --- a/Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 64a5b260684e4a9b9fe7f92c881568e6 -timeCreated: 1693691926 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs b/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs deleted file mode 100644 index 2486277..0000000 --- a/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Files.Bundles.Exceptions; -using UnityEngine.Networking; - -namespace Depra.Assets.Files.Bundles.Extensions -{ - internal static class UnityWebRequestAsyncOperationExtensions - { - public static Task ToTask(this UnityWebRequestAsyncOperation self, - Action onProgress = null, CancellationToken cancellationToken = default) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - - if (self.isDone) - { - return self.webRequest.CanGetResult() - ? Task.FromResult(self.webRequest) - : Task.FromException(new UnityWebRequestFailed(self.webRequest)); - } - - return AwaitWithProgress(self, onProgress, cancellationToken); - } - - private async static Task AwaitWithProgress(this UnityWebRequestAsyncOperation self, - Action onProgress, CancellationToken cancellationToken = default) - { - while (self.isDone == false) - { - if (cancellationToken.IsCancellationRequested) - { - return await Task.FromCanceled(cancellationToken); - } - - onProgress?.Invoke(self.progress); - await Task.Yield(); - } - - return self.webRequest; - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs.meta b/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs.meta deleted file mode 100644 index e9dbbf0..0000000 --- a/Runtime/Files.Bundles/Extensions/UnityWebRequestAsyncOperationExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7558da688eae4dbfb151f39ce6d9eebc -timeCreated: 1693689731 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs b/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs deleted file mode 100644 index dcba984..0000000 --- a/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using UnityEngine.Networking; - -namespace Depra.Assets.Files.Bundles.Extensions -{ - internal static class UnityWebRequestExtensions - { - public static bool CanGetResult(this UnityWebRequest self) => - self.result is UnityWebRequest.Result.ConnectionError - or UnityWebRequest.Result.DataProcessingError - or UnityWebRequest.Result.ProtocolError; - - public static int ParseSize(this UnityWebRequest self) - { - var contentLength = self.GetResponseHeader("Content-Length"); - if (int.TryParse(contentLength, out var returnValue)) - { - return returnValue; - } - - return -1; - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs.meta b/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs.meta deleted file mode 100644 index 654ef2e..0000000 --- a/Runtime/Files.Bundles/Extensions/UnityWebRequestExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0c36217f40ce46f4be8d17509c831456 -timeCreated: 1693691779 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files.meta b/Runtime/Files.Bundles/Files.meta deleted file mode 100644 index 45b3ad5..0000000 --- a/Runtime/Files.Bundles/Files.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fef7721586e24a30ae7f34efa92eba7f -timeCreated: 1678833171 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs b/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs deleted file mode 100644 index 49140cc..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Delegates; -using Depra.Assets.Exceptions; -using Depra.Assets.Files.Bundles.Exceptions; -using Depra.Assets.Files.Bundles.Extensions; -using Depra.Assets.ValueObjects; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Depra.Assets.Files.Bundles -{ - public sealed class AssetBundleAssetFile : IAssetFile, IDisposable where TAsset : Object - { - private readonly AssetBundle _assetBundle; - private TAsset _loadedAsset; - - public AssetBundleAssetFile(AssetName name, AssetBundle assetBundle) - { - Guard.AgainstNull(name, nameof(name)); - Guard.AgainstNull(assetBundle, nameof(assetBundle)); - - _assetBundle = assetBundle; - Metadata = new AssetMetadata(name, FileSize.Unknown); - } - - public AssetMetadata Metadata { get; } - public bool IsLoaded => _loadedAsset != null; - private string Name => Metadata.Uri.Relative; - - public TAsset Load() - { - if (IsLoaded) - { - return _loadedAsset; - } - - var loadedAsset = _assetBundle.LoadAsset(Name); - Guard.AgainstNull(loadedAsset, () => new AssetBundleFileNotLoaded(Name, _assetBundle.name)); - - _loadedAsset = loadedAsset; - Metadata.Size = UnityFileSize.FromProfiler(_loadedAsset); - - return _loadedAsset; - } - - public void Unload() - { - if (IsLoaded) - { - _loadedAsset = null; - } - } - - public async Task LoadAsync(DownloadProgressDelegate onProgress = null, - CancellationToken cancellationToken = default) - { - if (IsLoaded) - { - onProgress?.Invoke(DownloadProgress.Full); - return _loadedAsset; - } - - var loadedAsset = await _assetBundle - .LoadAssetAsync(Name) - .ToTask(OnProgress, cancellationToken); - - Guard.AgainstNull(loadedAsset, () => new AssetBundleFileNotLoaded(Name, _assetBundle.name)); - - _loadedAsset = (TAsset) loadedAsset; - onProgress?.Invoke(DownloadProgress.Full); - Metadata.Size = UnityFileSize.FromProfiler(_loadedAsset); - - return _loadedAsset; - - void OnProgress(float progress) => onProgress?.Invoke(new DownloadProgress(progress)); - } - - public IEnumerable Dependencies() => AssetBundleDependenciesExtractor.Extract(_assetBundle); - - void IDisposable.Dispose() => Unload(); - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs.meta b/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs.meta deleted file mode 100644 index 8b5de77..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 57b8b1e701f2472ab311344d582e8e12 -timeCreated: 1677617200 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs b/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs deleted file mode 100644 index a7c4468..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using Depra.Assets.Files.Bundles.Exceptions; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles -{ - internal static class AssetBundleDependenciesExtractor - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static IEnumerable Extract(AssetBundle assetBundle) - { - const string MANIFEST_NAME = "assetbundlemanifest"; - var manifest = assetBundle.LoadAsset(MANIFEST_NAME); - if (manifest == null) - { - throw new AssetBundleFileNotLoaded(MANIFEST_NAME, assetBundle.name); - } - - var dependencies = manifest.GetAllDependencies(assetBundle.name); - foreach (var dependencyPath in dependencies) - { - yield return new AssetBundleUri(dependencyPath); - } - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs.meta b/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs.meta deleted file mode 100644 index 1e08f55..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleDependenciesExtractor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: aabb1d126b8e4408bdd8abf082852106 -timeCreated: 1703534281 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleFile.cs b/Runtime/Files.Bundles/Files/AssetBundleFile.cs deleted file mode 100644 index dc215d8..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleFile.cs +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Delegates; -using Depra.Assets.Exceptions; -using Depra.Assets.Files.Bundles.Exceptions; -using Depra.Assets.Files.Bundles.Sources; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles -{ - public sealed class AssetBundleFile : IAssetFile, IDisposable - { - private readonly AssetBundleUri _uri; - private readonly IAssetBundleSource _source; - - private AssetBundle _loadedAssetBundle; - - public AssetBundleFile(AssetBundleUri uri, IAssetBundleSource source) - { - Guard.AgainstNull(uri, nameof(uri)); - Guard.AgainstNull(source, nameof(source)); - - _source = source; - Metadata = new AssetMetadata(_uri = uri, FileSize.Unknown); - } - - public AssetMetadata Metadata { get; } - public bool IsLoaded => _loadedAssetBundle != null; - - public AssetBundle Load() - { - if (IsLoaded) - { - return _loadedAssetBundle; - } - - var loadedAssetBundle = _source.Load(by: _uri.AbsolutePathWithoutExtension); - Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.Absolute)); - - _loadedAssetBundle = loadedAssetBundle; - Metadata.Size = _source.Size(of: _loadedAssetBundle); - - return _loadedAssetBundle; - } - - public async Task LoadAsync(DownloadProgressDelegate onProgress = null, - CancellationToken cancellationToken = default) - { - if (IsLoaded) - { - onProgress?.Invoke(DownloadProgress.Full); - return _loadedAssetBundle; - } - - var loadedAssetBundle = await _source - .LoadAsync(_uri.AbsolutePathWithoutExtension, OnProgress, cancellationToken); - - Guard.AgainstNull(loadedAssetBundle, () => new AssetBundleNotLoaded(_uri.Absolute)); - - _loadedAssetBundle = loadedAssetBundle; - onProgress?.Invoke(DownloadProgress.Full); - Metadata.Size = _source.Size(of: _loadedAssetBundle); - - return _loadedAssetBundle; - - void OnProgress(float progress) => onProgress?.Invoke(new DownloadProgress(progress)); - } - - public void Unload() - { - if (IsLoaded == false) - { - return; - } - - _loadedAssetBundle.Unload(true); - _loadedAssetBundle = null; - } - - public void UnloadAsync() - { - if (IsLoaded == false) - { - return; - } - - _loadedAssetBundle.UnloadAsync(true); - _loadedAssetBundle = null; - } - - public IEnumerable Dependencies() - { - Guard.Against(IsLoaded == false, () => new AssetBundleNotLoaded(_uri.Absolute)); - return AssetBundleDependenciesExtractor.Extract(_loadedAssetBundle); - } - - void IDisposable.Dispose() => Unload(); - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleFile.cs.meta b/Runtime/Files.Bundles/Files/AssetBundleFile.cs.meta deleted file mode 100644 index e309064..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleFile.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3f66e0126c084eefa784bafbcec2f613 -timeCreated: 1675002783 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleUri.cs b/Runtime/Files.Bundles/Files/AssetBundleUri.cs deleted file mode 100644 index 31996ba..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleUri.cs +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System.IO; -using Depra.Assets.Extensions; -using Depra.Assets.ValueObjects; - -namespace Depra.Assets.Files.Bundles -{ - public sealed record AssetBundleUri : IAssetUri - { - private const string EXTENSION = ".assetbundle"; - - public static AssetBundleUri Empty => new(string.Empty); - public static AssetBundleUri Invalid => new(nameof(Invalid)); - public static implicit operator AssetBundleUri(string path) => new(path); - - private readonly FileInfo _fileInfo; - - public AssetBundleUri(string path) - { - _fileInfo = new FileInfo(path); - _fileInfo.Directory.Require(); - - Name = string.IsNullOrEmpty(Extension) - ? _fileInfo.Name - : _fileInfo.Name.Replace(Extension, string.Empty); - - AbsolutePathWithoutExtension = Absolute.Replace(EXTENSION, string.Empty); - } - - public AssetBundleUri(string name, string directory = null) : this(name, directory, EXTENSION) { } - - public AssetBundleUri(string name, string directory, string extension = null) : this( - Path.Combine(directory, name + extension)) { } - - public string Name { get; } - public string Extension => EXTENSION; - public string NameWithExtension => Name + Extension; - - public string Absolute => _fileInfo.FullName; - public string AbsoluteDirectoryPath => _fileInfo.DirectoryName; - public string AbsolutePathWithoutExtension { get; } - - string IAssetUri.Relative => Name; - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Files/AssetBundleUri.cs.meta b/Runtime/Files.Bundles/Files/AssetBundleUri.cs.meta deleted file mode 100644 index a1800c5..0000000 --- a/Runtime/Files.Bundles/Files/AssetBundleUri.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4e0039a268c44d8abef6239694f41351 -timeCreated: 1681075311 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources.meta b/Runtime/Files.Bundles/Sources.meta deleted file mode 100644 index 45d1147..0000000 --- a/Runtime/Files.Bundles/Sources.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f0305bc0b379403f8ebdb210e9d4fc10 -timeCreated: 1689980205 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs b/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs deleted file mode 100644 index 2289c84..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Exceptions; -using Depra.Assets.Files.Bundles.Extensions; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public readonly struct AssetBundleFromFile : IAssetBundleSource - { - FileSize IAssetBundleSource.Size(AssetBundle of) => AssetBundleSize.Evaluate(of); - - AssetBundle IAssetBundleSource.Load(string by) - { - Guard.AgainstFileNotFound(by); - - return AssetBundle.LoadFromFile(by); - } - - Task IAssetBundleSource.LoadAsync(string by, Action onProgress, - CancellationToken cancellationToken) - { - Guard.AgainstFileNotFound(by); - - return AssetBundle - .LoadFromFileAsync(by) - .ToTask(onProgress, cancellationToken); - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs.meta b/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs.meta deleted file mode 100644 index df1deac..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromFile.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7d63f73ae55546ea8984094fbed8aac9 -timeCreated: 1689980352 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs b/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs deleted file mode 100644 index 514ee49..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.IO; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Exceptions; -using Depra.Assets.Files.Bundles.Extensions; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public readonly struct AssetBundleFromMemory : IAssetBundleSource - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static byte[] ReadBytes(string path) => File.ReadAllBytes(path); - - FileSize IAssetBundleSource.Size(AssetBundle of) => AssetBundleSize.Evaluate(of); - - AssetBundle IAssetBundleSource.Load(string by) - { - Guard.AgainstFileNotFound(by); - - return AssetBundle.LoadFromMemory(ReadBytes(by)); - } - - Task IAssetBundleSource.LoadAsync(string by, Action onProgress, CancellationToken cancellationToken) - { - Guard.AgainstFileNotFound(by); - - return AssetBundle - .LoadFromMemoryAsync(ReadBytes(by)) - .ToTask(onProgress, cancellationToken); - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs.meta b/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs.meta deleted file mode 100644 index c490a04..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromMemory.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9dda631cf3b9436b945ee7b1b50ad7fd -timeCreated: 1689980742 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs b/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs deleted file mode 100644 index a172cc9..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.IO; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Exceptions; -using Depra.Assets.Files.Bundles.Extensions; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public readonly struct AssetBundleFromStream : IAssetBundleSource - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static Stream OpenStream(string path) => - new FileStream(path, FileMode.Open, FileAccess.Read); - - FileSize IAssetBundleSource.Size(AssetBundle of) => AssetBundleSize.Evaluate(of); - - AssetBundle IAssetBundleSource.Load(string by) - { - Guard.AgainstFileNotFound(by); - - using var fileStream = OpenStream(by); - - return AssetBundle.LoadFromStream(fileStream); - } - - async Task IAssetBundleSource.LoadAsync(string by, Action onProgress, - CancellationToken cancellationToken) - { - Guard.AgainstFileNotFound(by); - - await using var stream = OpenStream(by); - - return await AssetBundle - .LoadFromStreamAsync(stream) - .ToTask(onProgress, cancellationToken); - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs.meta b/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs.meta deleted file mode 100644 index 666509c..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromStream.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cce5384652054419bd4304851fd288c3 -timeCreated: 1689980594 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs b/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs deleted file mode 100644 index 27c161f..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.Files.Bundles.Exceptions; -using Depra.Assets.Files.Bundles.Extensions; -using Depra.Assets.ValueObjects; -using UnityEngine; -using UnityEngine.Networking; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public sealed class AssetBundleFromWeb : IAssetBundleSource - { - private long _contentSize; - - FileSize IAssetBundleSource.Size(AssetBundle of) => - _contentSize == -1 ? AssetBundleSize.Evaluate(of) : new FileSize(_contentSize); - - AssetBundle IAssetBundleSource.Load(string by) - { - using var unityWebRequest = UnityWebRequestAssetBundle.GetAssetBundle(by); - unityWebRequest.SendWebRequest(); - - while (unityWebRequest.isDone == false) - { - // Spinning for Synchronous Behavior (blocking). - } - - if (unityWebRequest.CanGetResult() == false) - { - throw new UnityWebRequestFailed(unityWebRequest); - } - - return DownloadHandlerAssetBundle.GetContent(unityWebRequest); - } - - async Task IAssetBundleSource.LoadAsync(string by, Action onProgress, - CancellationToken cancellationToken) - { - var webRequest = UnityWebRequestAssetBundle.GetAssetBundle(by); - await webRequest - .SendWebRequest() - .ToTask(onProgress, cancellationToken); - - var downloadedBundle = DownloadHandlerAssetBundle.GetContent(webRequest); - _contentSize = webRequest.ParseSize(); - webRequest.Dispose(); - - return downloadedBundle; - } - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs.meta b/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs.meta deleted file mode 100644 index 0f62301..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleFromWeb.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 19827faf232f4eff8cb06200df0fcaa9 -timeCreated: 1689980932 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleSize.cs b/Runtime/Files.Bundles/Sources/AssetBundleSize.cs deleted file mode 100644 index 6a11ac3..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleSize.cs +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Depra.Assets.ValueObjects; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public static class AssetBundleSize - { - public static FileSize Evaluate(AssetBundle assetBundle) - { - FileSize fileSize; -#if UNITY_EDITOR - fileSize = SizeInRAM(assetBundle); - if (fileSize.Bytes == 0) -#endif - { - fileSize = SizeOnDisk(assetBundle); - } - - return fileSize; - } - - private static FileSize SizeOnDisk(AssetBundle assetBundle) - { - var allScenePaths = assetBundle.GetAllScenePaths(); - var sizes = from scenePath in allScenePaths - select Path.Combine(Application.streamingAssetsPath, scenePath) - into absolutePath - select new FileInfo(absolutePath) - into fileInfo - where fileInfo.Exists - select fileInfo.Length; - - return new FileSize(sizes.Sum()); - } - -#if UNITY_EDITOR - /// - /// Returns size of in RAM. - /// - /// for calculating. - /// - /// Source - https://stackoverflow.com/questions/56822948/estimate-an-assetbundle-size-in-ram - private static FileSize SizeInRAM(Object assetBundle) - { - var sizes = new Dictionary(); - var serializedObject = new UnityEditor.SerializedObject(assetBundle); - var serializedProperty = serializedObject.FindProperty("m_PreloadTable"); - for (var index = 0; index < serializedProperty.arraySize; index++) - { - var objectReference = serializedProperty.GetArrayElementAtIndex(index).objectReferenceValue; - var type = objectReference.GetType(); - var size = UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong(objectReference); - if (sizes.TryAdd(type, size) == false) - { - sizes[type] += size; - } - } - - return new FileSize(sizes.Sum(x => x.Value)); - } -#endif - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/AssetBundleSize.cs.meta b/Runtime/Files.Bundles/Sources/AssetBundleSize.cs.meta deleted file mode 100644 index 908592a..0000000 --- a/Runtime/Files.Bundles/Sources/AssetBundleSize.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 60c170ca95ba4895ae0c6f706838c9b6 -timeCreated: 1679185663 \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs b/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs deleted file mode 100644 index b45f6bd..0000000 --- a/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// © 2023-2024 Nikolay Melnikov - -using System; -using System.Threading; -using System.Threading.Tasks; -using Depra.Assets.ValueObjects; -using UnityEngine; - -namespace Depra.Assets.Files.Bundles.Sources -{ - public interface IAssetBundleSource - { - FileSize Size(AssetBundle of); - - AssetBundle Load(string by); - - Task LoadAsync(string by, Action onProgress, CancellationToken cancellationToken = default); - } -} \ No newline at end of file diff --git a/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs.meta b/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs.meta deleted file mode 100644 index 42b4763..0000000 --- a/Runtime/Files.Bundles/Sources/IAssetBundleSource.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b28d47aaf9854f45bd2712363bda15c3 -timeCreated: 1689980199 \ No newline at end of file diff --git a/Runtime/Files.Resource/ResourcesPath.cs b/Runtime/Files.Resource/ResourcesPath.cs index c46a8d4..0c4dc78 100644 --- a/Runtime/Files.Resource/ResourcesPath.cs +++ b/Runtime/Files.Resource/ResourcesPath.cs @@ -7,7 +7,7 @@ using Depra.Assets.Extensions; using Depra.Assets.Files.Resource.Exceptions; using Depra.Assets.ValueObjects; -using static Depra.Assets.Common.UnityProject; +using static Depra.Assets.Internal.UnityProject; namespace Depra.Assets.Files.Resource { diff --git a/Runtime/Files/UnityFileSize.cs b/Runtime/Files/UnityFileSize.cs index a311f9c..bcf5714 100644 --- a/Runtime/Files/UnityFileSize.cs +++ b/Runtime/Files/UnityFileSize.cs @@ -8,7 +8,7 @@ namespace Depra.Assets.Files { - internal static class UnityFileSize + public static class UnityFileSize { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static FileSize FromProfiler(Object asset) => new(Profiler.GetRuntimeMemorySizeLong(asset)); diff --git a/Runtime/Common.meta b/Runtime/Internal.meta similarity index 100% rename from Runtime/Common.meta rename to Runtime/Internal.meta diff --git a/Runtime/Common/AssetTypes.cs b/Runtime/Internal/AssetTypes.cs similarity index 87% rename from Runtime/Common/AssetTypes.cs rename to Runtime/Internal/AssetTypes.cs index bc4373d..5a4e8a9 100644 --- a/Runtime/Common/AssetTypes.cs +++ b/Runtime/Internal/AssetTypes.cs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // © 2023-2024 Nikolay Melnikov -namespace Depra.Assets.Common +namespace Depra.Assets.Internal { public static class AssetTypes { diff --git a/Runtime/Common/AssetTypes.cs.meta b/Runtime/Internal/AssetTypes.cs.meta similarity index 100% rename from Runtime/Common/AssetTypes.cs.meta rename to Runtime/Internal/AssetTypes.cs.meta diff --git a/Runtime/Common/Module.cs b/Runtime/Internal/Module.cs similarity index 92% rename from Runtime/Common/Module.cs rename to Runtime/Internal/Module.cs index adfcc2d..a66ea6e 100644 --- a/Runtime/Common/Module.cs +++ b/Runtime/Internal/Module.cs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // © 2023-2024 Nikolay Melnikov -namespace Depra.Assets.Common +namespace Depra.Assets.Internal { internal static class Module { diff --git a/Runtime/Common/Module.cs.meta b/Runtime/Internal/Module.cs.meta similarity index 100% rename from Runtime/Common/Module.cs.meta rename to Runtime/Internal/Module.cs.meta diff --git a/Runtime/Common/UnityProject.cs b/Runtime/Internal/UnityProject.cs similarity index 95% rename from Runtime/Common/UnityProject.cs rename to Runtime/Internal/UnityProject.cs index d17b09b..3dec944 100644 --- a/Runtime/Common/UnityProject.cs +++ b/Runtime/Internal/UnityProject.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace Depra.Assets.Common +namespace Depra.Assets.Internal { public static class UnityProject { diff --git a/Runtime/Common/UnityProject.cs.meta b/Runtime/Internal/UnityProject.cs.meta similarity index 100% rename from Runtime/Common/UnityProject.cs.meta rename to Runtime/Internal/UnityProject.cs.meta diff --git a/Runtime/Properties/AssemblyInfo.cs b/Runtime/Properties/AssemblyInfo.cs index 3026076..61b15ea 100644 --- a/Runtime/Properties/AssemblyInfo.cs +++ b/Runtime/Properties/AssemblyInfo.cs @@ -1,9 +1,12 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Depra.Assets.Editor")] +[assembly: InternalsVisibleTo("Depra.Assets.Bundle")] [assembly: InternalsVisibleTo("Depra.Assets.Tests.EditMode")] [assembly: InternalsVisibleTo("Depra.Assets.Tests.PlayMode")] [assembly: InternalsVisibleTo("Depra.Assets.Addressable.Runtime")] -[assembly: InternalsVisibleTo("Depra.Assets.Addressable.Tests")] \ No newline at end of file +[assembly: InternalsVisibleTo("Depra.Assets.Addressable.Tests")] + +[assembly: InternalsVisibleTo("Depra.Assets.Bundle")] \ No newline at end of file diff --git a/package.json b/package.json index ffad24c..28cf734 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.depra.assets.unity", - "version": "0.2.7", + "version": "0.2.8-pre.5", "displayName": "Depra.Assets", "description": "Provides an API for loading Unity asset files in multiple ways through a single interface.", "unity": "2021.3", @@ -10,8 +10,7 @@ "assets", "editor", "runtime", - "resources", - "assetBundle" + "resources" ], "author": { "name": "Depra, Inc.",