├── .github └── workflows │ ├── publish_upm_release.yml │ └── semantic_release_dry_run.yml ├── .releaserc.json ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── Editor.meta ├── Editor ├── RuntimeAssets.meta └── RuntimeAssets │ ├── AssetNameAsKeyAssetsScanner.cs │ ├── AssetNameAsKeyAssetsScanner.cs.meta │ ├── AssetsScanner.cs │ ├── AssetsScanner.cs.meta │ ├── AssetsScannerComposite.cs │ ├── AssetsScannerComposite.cs.meta │ ├── CustomKeyAssetsScanner.cs │ ├── CustomKeyAssetsScanner.cs.meta │ ├── Dre0Dru.RuntimeAssets.Editor.asmdef │ ├── Dre0Dru.RuntimeAssets.Editor.asmdef.meta │ ├── ScannerTarget.cs │ └── ScannerTarget.cs.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── AddressableAssets.meta ├── AddressableAssets │ ├── Common.meta │ ├── Common │ │ ├── Dre0Dru.AddressableAssets.Common.asmdef │ │ ├── Dre0Dru.AddressableAssets.Common.asmdef.meta │ │ ├── IAssetReferenceProvider.cs │ │ └── IAssetReferenceProvider.cs.meta │ ├── Downloaders.meta │ ├── Downloaders │ │ ├── AddressablesDownloadersExtensions.cs │ │ ├── AddressablesDownloadersExtensions.cs.meta │ │ ├── AssetLabelsDownloadPack.cs │ │ ├── AssetLabelsDownloadPack.cs.meta │ │ ├── AssetsDownloadResult.cs │ │ ├── AssetsDownloadResult.cs.meta │ │ ├── AssetsDownloadStatus.cs │ │ ├── AssetsDownloadStatus.cs.meta │ │ ├── DownloadOperationStatus.cs │ │ ├── DownloadOperationStatus.cs.meta │ │ ├── Dre0Dru.AddressableAssets.Downloaders.asmdef │ │ ├── Dre0Dru.AddressableAssets.Downloaders.asmdef.meta │ │ ├── IAssetsDownloadStatus.cs │ │ ├── IAssetsDownloadStatus.cs.meta │ │ ├── IStartableDownload.cs │ │ ├── IStartableDownload.cs.meta │ │ ├── ITrackableProgress.cs │ │ ├── ITrackableProgress.cs.meta │ │ ├── Queue.meta │ │ └── Queue │ │ │ ├── AssetsDownloadQueue.cs │ │ │ ├── AssetsDownloadQueue.cs.meta │ │ │ ├── Dequeue.cs │ │ │ ├── Dequeue.cs.meta │ │ │ ├── IAssetsDownloadQueue.cs │ │ │ └── IAssetsDownloadQueue.cs.meta │ ├── Loaders.meta │ ├── Loaders │ │ ├── AssetReferenceComponent.cs │ │ ├── AssetReferenceComponent.cs.meta │ │ ├── AssetsLoaderExtensions.cs │ │ ├── AssetsLoaderExtensions.cs.meta │ │ ├── AssetsReferenceLoader.cs │ │ ├── AssetsReferenceLoader.cs.meta │ │ ├── Dre0Dru.AddressableAssets.Loaders.asmdef │ │ ├── Dre0Dru.AddressableAssets.Loaders.asmdef.meta │ │ ├── IAssetsLoader.cs │ │ ├── IAssetsLoader.cs.meta │ │ ├── IAssetsReferenceLoader.cs │ │ ├── IAssetsReferenceLoader.cs.meta │ │ ├── IAssetsUnloader.cs │ │ └── IAssetsUnloader.cs.meta │ ├── SpriteAtlases.meta │ └── SpriteAtlases │ │ ├── Dre0Dru.AddressableAssets.SpriteAtlases.asmdef │ │ ├── Dre0Dru.AddressableAssets.SpriteAtlases.asmdef.meta │ │ ├── ISpriteAtlasProvider.cs │ │ ├── ISpriteAtlasProvider.cs.meta │ │ ├── SpriteAtlasesProvider.cs │ │ ├── SpriteAtlasesProvider.cs.meta │ │ ├── SpriteAtlasesProviderEntryPoint.cs │ │ └── SpriteAtlasesProviderEntryPoint.cs.meta ├── GameAssets.meta ├── GameAssets │ ├── Dre0Dru.GameAssets.asmdef │ ├── Dre0Dru.GameAssets.asmdef.meta │ ├── GameAssetsExtensions.cs │ ├── GameAssetsExtensions.cs.meta │ ├── IDataAsset.cs │ ├── IDataAsset.cs.meta │ ├── IGameAsset.cs │ ├── IGameAsset.cs.meta │ ├── ScopedAsset.cs │ ├── ScopedAsset.cs.meta │ ├── TransientAsset.cs │ └── TransientAsset.cs.meta ├── TODO.md └── TODO.md.meta ├── package.json └── package.json.meta /.github/workflows/publish_upm_release.yml: -------------------------------------------------------------------------------- 1 | name: Publish UPM release 2 | on: [workflow_dispatch] 3 | jobs: 4 | release: 5 | name: release 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | with: 10 | fetch-depth: 0 11 | - name: Semantic release 12 | id: semantic 13 | uses: cycjimmy/semantic-release-action@v3 14 | with: 15 | extra_plugins: | 16 | @semantic-release/changelog 17 | @semantic-release/git 18 | branch: master 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/semantic_release_dry_run.yml: -------------------------------------------------------------------------------- 1 | name: Semantic Release Dry Run 2 | on: [workflow_dispatch] 3 | jobs: 4 | release: 5 | name: semantic_release_dry_run 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | with: 10 | fetch-depth: 0 11 | - name: Semantic release 12 | id: semantic 13 | uses: cycjimmy/semantic-release-action@v3 14 | with: 15 | dry_run: true 16 | extra_plugins: | 17 | @semantic-release/changelog 18 | @semantic-release/git 19 | branch: master 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tagFormat": "v${version}", 3 | "plugins": [ 4 | ["@semantic-release/commit-analyzer", { "preset": "angular" }], 5 | "@semantic-release/release-notes-generator", 6 | ["@semantic-release/changelog", { "preset": "angular", "changelogFile": "CHANGELOG.md" }], 7 | ["@semantic-release/npm", { "npmPublish": false, "pkgRoot": "./" }], 8 | ["@semantic-release/git", { 9 | "assets": ["package.json", "CHANGELOG.md"], 10 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 11 | }], 12 | "@semantic-release/github" 13 | ] 14 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [7.1.1](https://github.com/dre0dru/AssetManagement/compare/v7.1.0...v7.1.1) (2023-09-11) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * wrapped missing VContainer usage with defines ([2c73201](https://github.com/dre0dru/AssetManagement/commit/2c73201619d7cf78115d107d7733789aa3e744e8)) 7 | 8 | # [7.1.0](https://github.com/dre0dru/AssetManagement/compare/v7.0.0...v7.1.0) (2023-06-06) 9 | 10 | 11 | ### Features 12 | 13 | * added scoped/transient assets ([c1ec7e6](https://github.com/dre0dru/AssetManagement/commit/c1ec7e6363a3c9b6c1b3b61520941c6f95a216c4)) 14 | 15 | # [7.0.0](https://github.com/dre0dru/AssetManagement/compare/v6.1.1...v7.0.0) (2022-11-29) 16 | 17 | 18 | ### Features 19 | 20 | * package at root ([f0b2d73](https://github.com/dre0dru/AssetManagement/commit/f0b2d73e94f9d7238d6f8de5d519eb84b7c99dce)) 21 | 22 | 23 | ### BREAKING CHANGES 24 | 25 | * namespaces change 26 | 27 | ## [6.1.1](https://github.com/dre0dru/AddressablesServices/compare/v6.1.0...v6.1.1) (2022-06-01) 28 | 29 | 30 | ### Bug Fixes 31 | 32 | * fixed invalid dependency on shared.sources ([4764de4](https://github.com/dre0dru/AddressablesServices/commit/4764de4ca0f29b80791ff1df68ecec19d253e24e)) 33 | 34 | # [6.1.0](https://github.com/dre0dru/AddressablesServices/compare/v6.0.0...v6.1.0) (2021-12-27) 35 | 36 | 37 | ### Features 38 | 39 | * updated TMP fonts build processor ([a0ab4e1](https://github.com/dre0dru/AddressablesServices/commit/a0ab4e11e93b76a6bf8bf2c2bc696f511c0952de)) 40 | 41 | # [6.0.0](https://github.com/dre0dru/AddressablesServices/compare/v5.0.0...v6.0.0) (2021-12-19) 42 | 43 | 44 | ### Features 45 | 46 | * reworked fonts service, generic assets ([cee22b2](https://github.com/dre0dru/AddressablesServices/commit/cee22b228267357b529a9e76e527703bdbf50457)) 47 | 48 | 49 | ### BREAKING CHANGES 50 | 51 | * fonts service signature changes 52 | 53 | # [5.0.0](https://github.com/dre0dru/AddressablesServices/compare/v4.0.0...v5.0.0) (2021-12-19) 54 | 55 | 56 | ### Bug Fixes 57 | 58 | * removed webgl preprocessor directive for asasets download pack ([c5ddab7](https://github.com/dre0dru/AddressablesServices/commit/c5ddab7231a00ead3fe36d9483b3ad9ccf1af8d1)) 59 | 60 | 61 | ### Features 62 | 63 | * updated code to support shared sources changes ([b2c069f](https://github.com/dre0dru/AddressablesServices/commit/b2c069fca8da692dc456a7ace339ede726ed150a)) 64 | 65 | 66 | ### BREAKING CHANGES 67 | 68 | * namespaces and interfaces were changed fonts, sprite atlases and databases 69 | 70 | # [4.0.0](https://github.com/dre0dru/AddressablesServices/compare/v3.0.1...v4.0.0) (2021-12-06) 71 | 72 | 73 | ### Bug Fixes 74 | 75 | * added missing lifetime parameter ([4c5f275](https://github.com/dre0dru/AddressablesServices/commit/4c5f27512e3b3ddc054220cdb6597fbfdcb0a0d4)) 76 | * added preprocessor for required member attribute ([e08fdb3](https://github.com/dre0dru/AddressablesServices/commit/e08fdb368dd994c79add5d50cafdd83301ac49dd)) 77 | * fonts editor assembly target platform wasn't set as editor ([ee81709](https://github.com/dre0dru/AddressablesServices/commit/ee817091f67fe9ee6139448e9193f6d46679f0c7)) 78 | * wrong preprocessor directive for sprite atlases ([cfe1060](https://github.com/dre0dru/AddressablesServices/commit/cfe10601927d7e85d02a136b828e4f0d5af8b440)) 79 | 80 | 81 | ### Code Refactoring 82 | 83 | * renaming ([adad578](https://github.com/dre0dru/AddressablesServices/commit/adad578e832177aeda6b3128217f549e4b07e274)) 84 | 85 | 86 | ### Features 87 | 88 | * added asset references database ([4257873](https://github.com/dre0dru/AddressablesServices/commit/4257873a69faf62d4915093e4b8857c4f934ecd0)) 89 | * added single/multiple loaders ([4b3e02a](https://github.com/dre0dru/AddressablesServices/commit/4b3e02a24dac84a354950f00b2de636b1b34ef92)) 90 | * added sprite atlases provider ([21fe731](https://github.com/dre0dru/AddressablesServices/commit/21fe731c4541790859d65a27f1b838cd94377271)) 91 | * added TMP fonts load ([1d6dd9a](https://github.com/dre0dru/AddressablesServices/commit/1d6dd9a4aa6e83bf2c50d95c2350f52100a40723)) 92 | * assets downloader wip ([f1cd059](https://github.com/dre0dru/AddressablesServices/commit/f1cd05983e9500c1a9368954ce1a43e97f138b25)) 93 | * assets downloading, project restructure ([58aca9f](https://github.com/dre0dru/AddressablesServices/commit/58aca9f05016cbc54cfaa1c2320f635448a161f7)) 94 | * removed multiple assets loader, introduced higher level interface for asset reference loader ([d131385](https://github.com/dre0dru/AddressablesServices/commit/d131385f878e7b0060518152bc3b6294ce402604)) 95 | * single/multiple loaders ontroduces ([d6d3dd7](https://github.com/dre0dru/AddressablesServices/commit/d6d3dd7f0c8286671125e25082b259efcba2b21c)) 96 | 97 | 98 | ### BREAKING CHANGES 99 | 100 | * renamed core interfaces and namespaces 101 | * renamed core interfaces 102 | * changed single loader interface 103 | * changed single loader interface 104 | 105 | ## [3.0.1](https://github.com/dre0dru/AddressablesServices/compare/v3.0.0...v3.0.1) (2021-08-01) 106 | 107 | 108 | ### Bug Fixes 109 | 110 | * wrapped `RequiredMember` attribute in preprocessor directive ([9c22785](https://github.com/dre0dru/AddressablesServices/commit/9c227859da01e00714bc454a3a3d00f29c330764)) 111 | 112 | # [3.0.0](https://github.com/dre0dru/AddressablesServices/compare/v2.2.0...v3.0.0) (2021-06-30) 113 | 114 | 115 | ### Bug Fixes 116 | 117 | * fixed handle leak on asset preload failure ([4df9bf3](https://github.com/dre0dru/AddressablesServices/commit/4df9bf3f2723e28787217f404eaeb5053e45eb6f)) 118 | * regenerated guid to avoid conflicts with other packages ([a9ae311](https://github.com/dre0dru/AddressablesServices/commit/a9ae311ce2785c5e3536cf2d5009959c7ea109b0)) 119 | * update menu item name ([b398758](https://github.com/dre0dru/AddressablesServices/commit/b39875808f63854fe1d7cca5b8870e26045fa3ab)) 120 | 121 | 122 | ### Features 123 | 124 | * moved to scripting define utility to optional dependencies ([38e2abe](https://github.com/dre0dru/AddressablesServices/commit/38e2abefc3c20862e5f271b40dd0b3431ee4e13d)) 125 | 126 | 127 | ### BREAKING CHANGES 128 | 129 | * moved loader classes to different namespace 130 | 131 | # [2.2.0](https://github.com/dre0dru/AddressablesServices/compare/v2.1.0...v2.2.0) (2021-04-09) 132 | 133 | 134 | ### Features 135 | 136 | * extracted `params` overload for `IAddressablesLoader` to extension methods, added extension methods for assets loading ([e0eb22f](https://github.com/dre0dru/AddressablesServices/commit/e0eb22f05a5f6ebb865ebebef73eec6e4df471d1)) 137 | 138 | # [2.1.0](https://github.com/dre0dru/AddressablesServices/compare/v2.0.0...v2.1.0) (2021-04-04) 139 | 140 | 141 | ### Features 142 | 143 | * added `IsAssetPreloaded` methods to `IAddressablesLoader` ([1470742](https://github.com/dre0dru/AddressablesServices/commit/1470742f8724c1e0702b7d6bc6d13c432790a625)) 144 | 145 | # [2.0.0](https://github.com/dre0dru/AddressablesServices/compare/v1.1.0...v2.0.0) (2021-03-27) 146 | 147 | 148 | ### Features 149 | 150 | * added params[] overload for AssetReference and AssetLabelReference methods ([3e8f721](https://github.com/dre0dru/AddressablesServices/commit/3e8f7210aad49763859522b0f0ea552de7a90dc0)) 151 | * changed IAddressablesLoader component extensions to accept only AssetReferenceComponent as its argument ([0bf948c](https://github.com/dre0dru/AddressablesServices/commit/0bf948c4bfacbee51c31b0148a833430a6c9a304)) 152 | 153 | 154 | * chore!: unity version update, packages update ([245ffd8](https://github.com/dre0dru/AddressablesServices/commit/245ffd8825b873a35529eb0751ee1028b0575d90)) 155 | 156 | 157 | ### BREAKING CHANGES 158 | 159 | * addressables and unitask packages updated to latest versions 160 | 161 | # [1.1.0](https://github.com/dre0dru/AddressablesServices/compare/v1.0.1...v1.1.0) (2021-02-27) 162 | 163 | 164 | ### Features 165 | 166 | * replaced own scripting define utils with upm packaged ([11b74b3](https://github.com/dre0dru/AddressablesServices/commit/11b74b3560028628b452947bf1f86369c5165cb0)) 167 | 168 | ## [1.0.1](https://github.com/dre0dru/AddressablesServices/compare/v1.0.0...v1.0.1) (2021-02-26) 169 | 170 | 171 | ### Bug Fixes 172 | 173 | * changed changelog filepath for semantic release ([0ec806a](https://github.com/dre0dru/AddressablesServices/commit/0ec806a05dbf4c48f7aa07636759e28fdf59b7a1)) 174 | -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfb5a13fa70130647aa073c5c49e74b8 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2214755086149541842f2b603576ec2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ffd7c2b126a6ae41a889224b933f820 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetNameAsKeyAssetsScanner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Dre0Dru.RuntimeAssets.Editor 4 | { 5 | public class AssetNameAsKeyAssetsScanner : CustomKeyAssetsScanner 6 | where TRuntimeAsset : Object 7 | { 8 | public override string GetKeyFromAsset(TRuntimeAsset runtimeAsset) 9 | { 10 | return runtimeAsset.name; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetNameAsKeyAssetsScanner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be9cb707519442b8836ee0c2b97bd4c2 3 | timeCreated: 1647370458 -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetsScanner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Dre0Dru.RuntimeAssets.Editor 4 | { 5 | public abstract class AssetsScanner : ScriptableObject 6 | { 7 | #if EASY_BUTTONS_SUPPORT 8 | [EasyButtons.Button] 9 | #endif 10 | public abstract void Scan(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetsScanner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4e5bbc666a847309f8c6a32516661b2 3 | timeCreated: 1647375798 -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetsScannerComposite.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Dre0Dru.EditorExtensions.Editor; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace Dre0Dru.RuntimeAssets.Editor 7 | { 8 | [CreateAssetMenu(fileName = "AssetsScannerComposite", menuName = "RuntimeAssets/AssetsScannerComposite")] 9 | public class AssetsScannerComposite : AssetsScanner 10 | { 11 | [SerializeField] 12 | protected List _assetsScanners; 13 | 14 | public override void Scan() 15 | { 16 | foreach (var assetsScanner in _assetsScanners) 17 | { 18 | assetsScanner.Scan(); 19 | } 20 | } 21 | 22 | #if EASY_BUTTONS_SUPPORT 23 | [EasyButtons.Button] 24 | #endif 25 | public void FindAllScanners() 26 | { 27 | _assetsScanners.Clear(); 28 | 29 | foreach (var assetsScanner in AssetDatabaseUtils.LoadAssets()) 30 | { 31 | if (assetsScanner != this) 32 | { 33 | _assetsScanners.Add(assetsScanner); 34 | } 35 | } 36 | 37 | AssetDatabaseUtils.SetDirtyAndSave(this); 38 | AssetDatabase.Refresh(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/AssetsScannerComposite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e704f69724348e188904f5b27f35ed9 3 | timeCreated: 1647452296 -------------------------------------------------------------------------------- /Editor/RuntimeAssets/CustomKeyAssetsScanner.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Dre0Dru.EditorExtensions.Editor; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace Dre0Dru.RuntimeAssets.Editor 7 | { 8 | public abstract class CustomKeyAssetsScanner : AssetsScanner 9 | where TRuntimeAsset : Object 10 | { 11 | [SerializeField] 12 | protected List> _scannerTargets; 13 | 14 | public override void Scan() 15 | { 16 | foreach (var scannerTarget in _scannerTargets) 17 | { 18 | var folderPaths = scannerTarget.ScanFolders.GetFoldersPaths(); 19 | 20 | var assets = AssetDatabaseUtils.LoadAssetsAtPaths(folderPaths); 21 | 22 | scannerTarget.Target.Clear(); 23 | 24 | foreach (var runtimeAsset in assets) 25 | { 26 | scannerTarget.Target.Add(GetKeyFromAsset(runtimeAsset), runtimeAsset); 27 | } 28 | 29 | AssetDatabaseUtils.SetDirtyAndSave(scannerTarget.Target); 30 | } 31 | 32 | AssetDatabase.Refresh(); 33 | } 34 | 35 | public abstract TKey GetKeyFromAsset(TRuntimeAsset runtimeAsset); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/CustomKeyAssetsScanner.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 522a0437a4cc4a6ea4bf29eade12d2f3 3 | timeCreated: 1648373205 -------------------------------------------------------------------------------- /Editor/RuntimeAssets/Dre0Dru.RuntimeAssets.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.RuntimeAssets.Editor", 3 | "rootNamespace": "Dre0Dru.RuntimeAssets.Editor", 4 | "references": [ 5 | "GUID:f24cf67903b27ae498b3069ecc30cc11", 6 | "GUID:dc1efc5b0af9df743ad1e20ba7076138", 7 | "GUID:858f01292afdc66489a4648c01d9ca1e", 8 | "GUID:a6fcf49d5403da6468e825c181d92b8a" 9 | ], 10 | "includePlatforms": [ 11 | "Editor" 12 | ], 13 | "excludePlatforms": [], 14 | "allowUnsafeCode": false, 15 | "overrideReferences": false, 16 | "precompiledReferences": [], 17 | "autoReferenced": true, 18 | "defineConstraints": [ 19 | "EASY_BUTTONS_SUPPORT", 20 | "EDITOR_EXTENSIONS", 21 | "COLLECTIONS" 22 | ], 23 | "versionDefines": [ 24 | { 25 | "name": "com.madsbangh.easybuttons", 26 | "expression": "", 27 | "define": "EASY_BUTTONS_SUPPORT" 28 | }, 29 | { 30 | "name": "com.dre0dru.editorextensions", 31 | "expression": "", 32 | "define": "EDITOR_EXTENSIONS" 33 | }, 34 | { 35 | "name": "com.dre0dru.collections", 36 | "expression": "", 37 | "define": "COLLECTIONS" 38 | } 39 | ], 40 | "noEngineReferences": false 41 | } -------------------------------------------------------------------------------- /Editor/RuntimeAssets/Dre0Dru.RuntimeAssets.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88ed04fd302e5aa4da0897fffa2d1db9 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/ScannerTarget.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dre0Dru.Collections; 3 | using Dre0Dru.EditorExtensions; 4 | using UnityEngine; 5 | 6 | namespace Dre0Dru.RuntimeAssets.Editor 7 | { 8 | [Serializable] 9 | public struct ScannerTarget 10 | { 11 | [SerializeField] 12 | public UDictionarySo Target; 13 | 14 | [SerializeField] 15 | public FolderReference[] ScanFolders; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Editor/RuntimeAssets/ScannerTarget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 101b0ebf42cf4e4ba28a489a8bc5cf5f 3 | timeCreated: 1647372330 -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021-2022 Dre0Dru. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 515d5a2aa40f87b49a123cad72aa1514 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![openupm](https://img.shields.io/npm/v/com.dre0dru.assetmanagement?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.dre0dru.assetmanagement/) 2 | # Addressables Services 3 | A set of classes to convert Unity `Addressables` callbacks/coroutine workflow to async/await with UniTask. 4 | Unity 2020.1+ 5 | 6 | 7 | ## Installation 8 | This package can be installed as a Unity package from git url. 9 | 10 | ### Latest release 11 | - Add following line in `Packages/manifest.json`: 12 | ``` 13 | "com.dre0dru.assetmanagement": "https://github.com/dre0dru/AssetManagement.git", 14 | ``` 15 | - Use `Window/Package Manager/Add package from git URL...` in Unity: 16 | ``` 17 | https://github.com/dre0dru/AssetManagement.git 18 | ``` 19 | 20 | ## Dependencies 21 | This package has following dependencies that must be present for package to compile: 22 | - [UniTask](https://github.com/Cysharp/UniTask) 23 | 24 | ### Optional 25 | - [ScriptingDefineUtility](https://github.com/Thundernerd/Unity3D-ScriptingDefineUtility) enables full logs switch for `Addressables` under `Window->Asset Management->Addressables->Logs` 26 | - [VContainer](https://github.com/hadashiA/VContainer) - optional extension methods for bindings 27 | - [Shared.Sources](https://github.com/dre0dru/Shared.Sources) used for implementations of interfaces in several modules, interfaces are not dependent on this package 28 | 29 | ## Loaders 30 | Generic type-safe assets loader. 31 | Can be used for both async assets loading on demand or async preloading and sync usage during gameplay. 32 | ```csharp 33 | [SerializeField] 34 | private AssetReferenceT _clipAssetReference01; 35 | [SerializeField] 36 | private AssetReferenceT _clipAssetReference02; 37 | 38 | IAssetsReferenceLoader loader = new AssetsReferenceLoader(); 39 | 40 | //Or more generic IAssetsLoader 41 | IAssetsLoader, AudioClip> loader = 42 | new AssetsReferenceLoader(); 43 | 44 | //Preload assets 45 | await loader.PreloadAssetAsync(_clipAssetReference01); 46 | await loader.PreloadAssetsAsync(_clipAssetReference01, _clipAssetReference02); 47 | 48 | //Safely extract preloaded asset synchronously 49 | if (loader.TryGetAsset(_clipAssetReference01, out AudioClip audioClip)) 50 | { 51 | Debug.Log($"Asset loaded successfully: {audioClip}"); 52 | } 53 | else 54 | { 55 | Debug.Log($"No asset was for preloaded for {_clipAssetReference01.RuntimeKey}"); 56 | } 57 | 58 | //Check if asset was loaded 59 | bool isAssetPreloaded = loader.IsAssetLoaded(_clipAssetReference01); 60 | 61 | //Or use unsafe asset extraction, will throw exception if no asset was preloaded 62 | AudioClip audioClip = loader.GetAsset(_clipAssetReference01); 63 | 64 | //Load asynchronously on demand, will be completed immediately if asset is already loaded 65 | AudioClip audioClip = await loader.LoadAssetAsync(_clipAssetReference01); 66 | AudioClip[] audioClips = await loader.LoadAssetsAsync(_clipAssetReference01, _clipAssetReference02); 67 | 68 | //Unload unused assets 69 | loader.UnloadAsset(_clipAssetReference01); 70 | //Or unload all assets that were loaded 71 | loader.UnloadAllAssets(); 72 | ``` 73 | 74 | 75 | ### AssetReferenceComponent 76 | `AssetReferenceComponent` allows to filter Addressables assets by specific component in Unity Editor. Must be used with `IAssetsReferenceLoader`. 77 | ```csharp 78 | [SerializeField] 79 | private AssetReferenceComponent _cameraReference; 80 | 81 | IAssetsReferenceLoader gameObjectLoader = 82 | new AssetsReferenceLoader(); 83 | 84 | //AssetReferenceComponent can be passed to IAssetsReferenceLoader 85 | //since it is inherited from AssetReferenceGameObject 86 | await gameObjectLoader.PreloadAssetAsync(_cameraReference); 87 | 88 | //Safely extract preloaded GameObject with Camera component on it 89 | if(gameObjectLoader.TryGetComponent(_cameraReference, out Camera camera)) 90 | { 91 | Camera cameraInstance = Object.Instantiate(camera); 92 | } 93 | 94 | //Or use unsafe asset extraction, will throw exception if no asset was preloaded 95 | var cameraComponent = gameObjectLoader.GetComponent(_cameraReference); 96 | ``` 97 | 98 | ### VContainer extensions 99 | ```csharp 100 | //Will bind IAssetReferenceLoader to AssetRefereceLoader implementation 101 | builder.RegisterAssetsReferenceLoader(Lifetime.Scoped); 102 | ``` 103 | 104 | ## Downloaders 105 | Any downloader implements several interfaces: `IStartableDownload`, 106 | `IAssetsDownloadStatus` and optional ` ITrackableProgress`. 107 | Currently only `AssetLabelsDownloadPack` is provided since downloading by `AssetReferenceLabel` is the most common way. 108 | ```csharp 109 | //Create download pack 110 | var downloadPack = new AssetLabelsDownloadPack(_assetLabelReference); 111 | 112 | //Set method to track download status changes, accepts implementations of IProgress 113 | _downloadPack.TrackProgress(Progress.Create(DisplayStatus)); 114 | 115 | //Or get status manually 116 | var status = _downloadPack.DownloadStatus; 117 | 118 | //Start download 119 | bool isSuccess = await _downloadPack.StartDownloadAsync(); 120 | 121 | if(!isSuccess){ 122 | //Download can be restarted anytime 123 | isSuccess = await _downloadPack.StartDownloadAsync(); 124 | } 125 | 126 | _downloadPack.Dispose(); 127 | ``` 128 | 129 | ```csharp 130 | private void DisplayStatus(AssetsDownloadStatus status) 131 | { 132 | _downloadSize.text = $"Size {status.DownloadSizeBytes.ToString()}"; 133 | _percentProgress.text = $"Percent: {status.PercentProgress:F}"; 134 | _isDownloaded.text = $"Is downloaded {status.IsDownloaded}"; 135 | _status.text = $"Status {status.DownloadOperationStatus.ToString()}"; 136 | _downloadedBytes.text = $"Downloaded: {status.DownloadedBytes.ToString()}"; 137 | } 138 | ``` 139 | 140 | ## AssetReferences 141 | Simple Unity `ScriptableObject` Dictionaries for `AssetLabelReference` and `AssetReference`: 142 | - `AssetLabelsUDictionarySo` 143 | - `AssetReferencesUDictionarySo` 144 | 145 | ## Fonts 146 | > When using TMP with Addressables without initial preparations there will be either duplicated assets or broken Unity Editor workflow. 147 | 148 | 1. Inherit `TMPAddressableAssets` 149 | 2. Create `ScriptableObject` instance, set it up with fonts/sprite assets addressable references 150 | 3. Create instance of `TMPBuildProcessorSettings`, set it up 151 | ```csharp 152 | TMPAddressableAssets assets; 153 | IAssetsReferenceLoader fontsLoader; 154 | IAssetsReferenceLoader spriteAssetsLoader; 155 | 156 | //Setup/bind service instance 157 | IFontsService service = new FontsService( 158 | assets, fontsLoader, spriteAssetsLoader 159 | ); 160 | 161 | //Load font by locale 162 | await service.LoadFontForLocale("en"); 163 | 164 | //Unload unused fonts 165 | service.UnloadFontForLocale("ru"); 166 | 167 | await service.LoadSpriteAsset("CurrencyIcons"); 168 | 169 | service.UnloadSpriteAsset("CurrencyIcons"); 170 | 171 | ``` 172 | 173 | ## SpriteAtlases 174 | `ISpriteAtlasProvider` implementation can be used to control Unity `SpriteAtlase` loading/unloading at runtime via `Addressables`. 175 | ```csharp 176 | IAssetsReferenceLoader spriteAtlasLoader; 177 | ISpriteAtlasAddressableAssets spriteAtlasAddressableAssets; 178 | 179 | ISpriteAtlasProvider provider = new SpriteAtlasProvider( 180 | spriteAtlasLoader, spriteAtlasAddressableAssets 181 | ); 182 | 183 | //Listen SpriteAtlasManager atlas requests 184 | //Requeted SpriteAtlases will be loaded automatically 185 | provider.SubscribeToAtlasManagerRequests(); 186 | 187 | //Unload all SpriteAtlases that we loaded by this provider 188 | provider.UnloadSpriteAtlases(); 189 | 190 | provider.UnsubscribeFromAtlasManagerRequests(); 191 | ``` 192 | ### VContainer extensions 193 | Entry point for managing provider lifetime: 194 | ```csharp 195 | builder.RegisterEntryPoint(); 196 | ``` 197 | 198 | # License 199 | The software released under the terms of the [MIT license](./LICENSE.md). -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af15ef039b036b64d93ec93f15317a89 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 532693ac3b370f140bd80a709483929b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8cb243b2d8510714f926b6afc41db9f5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 738ce16185445c9498403c4d57f5701e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Common/Dre0Dru.AddressableAssets.Common.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.AddressableAssets.Common", 3 | "rootNamespace": "Dre0Dru.AddressableAssets.Common", 4 | "references": [ 5 | "GUID:9e24947de15b9834991c9d8411ea37cf" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [ 14 | "ADDRESSABLES_SUPPORT" 15 | ], 16 | "versionDefines": [ 17 | { 18 | "name": "com.unity.addressables", 19 | "expression": "", 20 | "define": "ADDRESSABLES_SUPPORT" 21 | } 22 | ], 23 | "noEngineReferences": false 24 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Common/Dre0Dru.AddressableAssets.Common.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70f7626a22e696b4cb0c451b9caa0dc1 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Common/IAssetReferenceProvider.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.AddressableAssets; 3 | 4 | namespace Dre0Dru.AddressableAssets.Common 5 | { 6 | //TODO as generic key-value SO in separate module? 7 | public interface IAssetReferenceProvider 8 | where TAsset : Object 9 | { 10 | AssetReferenceT GetByKey(TKey key); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Common/IAssetReferenceProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 914ed8fbac474aafa663181e11c071b8 3 | timeCreated: 1665335786 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 500ac5f12c5859f4c8d69d05cee3f22f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AddressablesDownloadersExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders 4 | { 5 | public static class AddressablesDownloadersExtensions 6 | { 7 | public static bool IsDownloadSuccessful(this AssetsDownloadResult assetsDownloadResult, out Exception failureException) 8 | { 9 | failureException = assetsDownloadResult.FailureException; 10 | 11 | return assetsDownloadResult.IsSuccess; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AddressablesDownloadersExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5925060e021247f2925b7fc92a8c0f50 3 | timeCreated: 1636913503 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetLabelsDownloadPack.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Cysharp.Threading.Tasks; 5 | using UnityEngine.AddressableAssets; 6 | using UnityEngine.ResourceManagement.AsyncOperations; 7 | using UnityEngine.ResourceManagement.Exceptions; 8 | 9 | namespace Dre0Dru.AddressableAssets.Downloaders 10 | { 11 | public class AssetLabelsDownloadPack : IStartableDownload, 12 | IAssetsDownloadStatus, ITrackableProgress 13 | { 14 | private readonly AssetLabelReference[] _assetLabelReferences; 15 | private readonly List> _trackedProgress; 16 | 17 | private AsyncOperationHandle _downloadOperationHandle; 18 | private UniTaskCompletionSource _downloadTaskCompletionSource; 19 | private AssetsDownloadStatus _downloadStatus; 20 | 21 | public AssetsDownloadStatus DownloadStatus => _downloadStatus; 22 | 23 | #if UNITY_2020_3_OR_NEWER 24 | [UnityEngine.Scripting.RequiredMember] 25 | #endif 26 | public AssetLabelsDownloadPack(params AssetLabelReference[] assetLabelReferences) 27 | { 28 | _assetLabelReferences = assetLabelReferences; 29 | _downloadStatus = CreateInitialDownloadStatus(); 30 | _trackedProgress = new List>(1); 31 | } 32 | 33 | public async UniTask StartDownloadAsync() 34 | { 35 | if (_downloadStatus.DownloadOperationStatus == DownloadOperationStatus.InProgress) 36 | { 37 | return await _downloadTaskCompletionSource.Task; 38 | } 39 | 40 | _downloadTaskCompletionSource = new UniTaskCompletionSource(); 41 | 42 | _downloadStatus.DownloadOperationStatus = DownloadOperationStatus.InProgress; 43 | 44 | _downloadOperationHandle = Addressables.DownloadDependenciesAsync((IEnumerable)_assetLabelReferences, 45 | Addressables.MergeMode.Union, true); 46 | 47 | var result = await DownloadAsyncInternal(); 48 | 49 | if (result.IsDownloadSuccessful(out var failureException)) 50 | { 51 | _downloadStatus.DownloadSizeBytes = 0; 52 | _downloadStatus.DownloadOperationStatus = DownloadOperationStatus.Succeeded; 53 | _downloadStatus.PercentProgress = 1.0f; 54 | } 55 | else 56 | { 57 | _downloadStatus.DownloadOperationStatus = DownloadOperationStatus.Failed; 58 | _downloadStatus.FailureException = failureException; 59 | _downloadStatus.PercentProgress = 0.0f; 60 | } 61 | 62 | ReportProgressUpdate(); 63 | 64 | if (_downloadTaskCompletionSource.TrySetResult(result) == false) 65 | { 66 | throw new OperationException("Failed to complete download task"); 67 | } 68 | 69 | return await _downloadTaskCompletionSource.Task; 70 | } 71 | 72 | public void TrackProgress(IProgress progress) 73 | { 74 | _trackedProgress.Add(progress); 75 | } 76 | 77 | public void Dispose() 78 | { 79 | _trackedProgress.Clear(); 80 | } 81 | 82 | private async UniTask DownloadAsyncInternal() 83 | { 84 | try 85 | { 86 | await _downloadOperationHandle.ToUniTask(Progress.Create(OnUniTaskProgress)); 87 | return new AssetsDownloadResult() 88 | { 89 | IsSuccess = true 90 | }; 91 | } 92 | catch (OperationException e) 93 | { 94 | return new AssetsDownloadResult() 95 | { 96 | IsSuccess = false, 97 | FailureException = e 98 | }; 99 | } 100 | catch (InvalidKeyException e) 101 | { 102 | return new AssetsDownloadResult() 103 | { 104 | IsSuccess = false, 105 | FailureException = e 106 | }; 107 | } 108 | } 109 | 110 | private void OnUniTaskProgress(float _) 111 | { 112 | UpdateDownloadStatusProgress(); 113 | ReportProgressUpdate(); 114 | } 115 | 116 | private void UpdateDownloadStatusProgress() 117 | { 118 | var downloadStatus = _downloadOperationHandle.GetDownloadStatus(); 119 | _downloadStatus.DownloadedBytes = downloadStatus.DownloadedBytes; 120 | _downloadStatus.PercentProgress = downloadStatus.Percent; 121 | } 122 | 123 | // TODO Won't work on WebGL 124 | // Call Addressables.InitializeAsync() before creating instance of this class 125 | // https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/SynchronousAddressables.html#webgl 126 | private long GetDownloadSizeBytes() 127 | { 128 | return Addressables.GetDownloadSizeAsync((IEnumerable)_assetLabelReferences).WaitForCompletion(); 129 | } 130 | 131 | private AssetsDownloadStatus CreateInitialDownloadStatus() 132 | { 133 | var downloadSize = GetDownloadSizeBytes(); 134 | return new AssetsDownloadStatus() 135 | { 136 | DownloadSizeBytes = downloadSize, 137 | DownloadedBytes = 0, 138 | DownloadOperationStatus = DownloadOperationStatus.NotStarted, 139 | PercentProgress = downloadSize == 0 ? 0.0f : 1.0f, 140 | FailureException = null, 141 | }; 142 | } 143 | 144 | private void ReportProgressUpdate() 145 | { 146 | foreach (var progress in _trackedProgress) 147 | { 148 | progress.Report(_downloadStatus); 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetLabelsDownloadPack.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db0e9e6c6bbd44fd89f56c7a4dbd8274 3 | timeCreated: 1638004148 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetsDownloadResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders 4 | { 5 | public struct AssetsDownloadResult 6 | { 7 | public bool IsSuccess; 8 | public Exception FailureException; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetsDownloadResult.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 95c91e76e530483798697876658e4499 3 | timeCreated: 1638003049 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetsDownloadStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders 4 | { 5 | public struct AssetsDownloadStatus 6 | { 7 | public long DownloadSizeBytes; 8 | public long DownloadedBytes; 9 | public float PercentProgress; 10 | public bool IsDownloaded => 11 | DownloadSizeBytes == 0 || DownloadOperationStatus == DownloadOperationStatus.Succeeded; 12 | 13 | public DownloadOperationStatus DownloadOperationStatus; 14 | 15 | public Exception FailureException; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/AssetsDownloadStatus.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a53f6c9e8f448c0a62b2861e4e18994 3 | timeCreated: 1638004275 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/DownloadOperationStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.Downloaders 2 | { 3 | public enum DownloadOperationStatus 4 | { 5 | NotStarted, 6 | InProgress, 7 | Succeeded, 8 | Failed 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/DownloadOperationStatus.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59565fec532f4e609c09aec850df3d52 3 | timeCreated: 1638004654 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Dre0Dru.AddressableAssets.Downloaders.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.AddressableAssets.Downloaders", 3 | "rootNamespace": "Dre0Dru.AddressableAssets.Downloaders", 4 | "references": [ 5 | "GUID:9e24947de15b9834991c9d8411ea37cf", 6 | "GUID:84651a3751eca9349aac36a66bba901b", 7 | "GUID:f51ebe6a0ceec4240a699833d6309b23", 8 | "GUID:593a5b492d29ac6448b1ebf7f035ef33" 9 | ], 10 | "includePlatforms": [], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [ 17 | "ADDRESSABLES_SUPPORT", 18 | "UNITASK_SUPPORT" 19 | ], 20 | "versionDefines": [ 21 | { 22 | "name": "com.cysharp.unitask", 23 | "expression": "", 24 | "define": "UNITASK_SUPPORT" 25 | }, 26 | { 27 | "name": "com.unity.addressables", 28 | "expression": "", 29 | "define": "ADDRESSABLES_SUPPORT" 30 | } 31 | ], 32 | "noEngineReferences": false 33 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Dre0Dru.AddressableAssets.Downloaders.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efb7970c14600f348bb456a5dffa6a6f 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/IAssetsDownloadStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.Downloaders 2 | { 3 | public interface IAssetsDownloadStatus 4 | { 5 | TDownloadStatus DownloadStatus { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/IAssetsDownloadStatus.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1f09b60e54d415e93b9e39b7cf4c386 3 | timeCreated: 1638003520 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/IStartableDownload.cs: -------------------------------------------------------------------------------- 1 | using Cysharp.Threading.Tasks; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders 4 | { 5 | public interface IStartableDownload 6 | { 7 | UniTask StartDownloadAsync(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/IStartableDownload.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 420836d08bdd40abb80bc9e1748afd4f 3 | timeCreated: 1638002891 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/ITrackableProgress.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders 4 | { 5 | public interface ITrackableProgress : IDisposable 6 | { 7 | void TrackProgress(IProgress progress); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/ITrackableProgress.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82c7dcc5837f4ded85d7a3ab54c0db4b 3 | timeCreated: 1637998650 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7abb1d1ef8d4e90b184ff3d19675e66 3 | timeCreated: 1638002784 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/AssetsDownloadQueue.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.Downloaders.Queue 2 | { 3 | 4 | //TODO move to queue settings 5 | public enum DownloadFailureBehaviour 6 | { 7 | None, 8 | Restart 9 | } 10 | 11 | //TODO restart behaviour as an extension that gets the result of the queue? 12 | 13 | 14 | //TODO queue, parallel downloads, configurable 15 | //TODO works with asset labels? 16 | public class AssetsDownloadQueue : IAssetsDownloadQueue 17 | { 18 | 19 | private readonly Dequeue> _dequeue; 20 | 21 | private bool _isProcessingQueue; 22 | 23 | #if UNITY_2020_3_OR_NEWER 24 | [UnityEngine.Scripting.RequiredMember] 25 | #endif 26 | public AssetsDownloadQueue() 27 | { 28 | _dequeue = new Dequeue>(); 29 | _isProcessingQueue = false; 30 | } 31 | 32 | public void Enqueue(IStartableDownload downloadable) 33 | { 34 | 35 | } 36 | 37 | //TODO maybe add some IProgress that can report progress and errors 38 | private async void ProcessDownloadQueue() 39 | { 40 | _isProcessingQueue = true; 41 | 42 | while (_dequeue.Count > 0) 43 | { 44 | var downloadProgress = _dequeue.PeekFirst(); 45 | 46 | var result = await downloadProgress.StartDownloadAsync(); 47 | 48 | if (result.IsDownloadSuccessful(out var exception) == false) 49 | { 50 | return; 51 | } 52 | } 53 | 54 | if (_dequeue.Count > 0) 55 | { 56 | ProcessDownloadQueue(); 57 | } 58 | else 59 | { 60 | _isProcessingQueue = false; 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/AssetsDownloadQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5817a1b2cc194a799823a0e1d4b47da2 3 | timeCreated: 1636911443 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/Dequeue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Dre0Dru.AddressableAssets.Downloaders.Queue 4 | { 5 | public class Dequeue 6 | { 7 | private readonly LinkedList _linkedList; 8 | 9 | public int Count => _linkedList.Count; 10 | 11 | public Dequeue() 12 | { 13 | _linkedList = new LinkedList(); 14 | } 15 | 16 | public void EnqueueFirst(T value) 17 | { 18 | _linkedList.AddFirst(value); 19 | } 20 | 21 | public T PeekFirst() 22 | { 23 | return _linkedList.First.Value; 24 | } 25 | 26 | public void EnqueueLast(T value) 27 | { 28 | _linkedList.AddLast(value); 29 | } 30 | 31 | public T PeekLast() 32 | { 33 | return _linkedList.Last.Value; 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/Dequeue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6759c8f29e6424296f559eef772b7a6 3 | timeCreated: 1637940089 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/IAssetsDownloadQueue.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.Downloaders.Queue 2 | { 3 | //TODO download queue factory? but how it can survive scene reloads 4 | //TODO queue is instance only via some builder as an extensions interface for factory, maybe add progress tracking as a extension too 5 | //TODO or not, it will expose dependencies on implementation 6 | //TODO additional interface for status? 7 | public interface IAssetsDownloadQueue 8 | { 9 | void Enqueue(IStartableDownload downloadable); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Downloaders/Queue/IAssetsDownloadQueue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd6f48d652a94b12afddcf0ae81181d3 3 | timeCreated: 1636911420 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 748b0cd46c8b59d4f9828fa3428d6ce0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetReferenceComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.AddressableAssets; 4 | using Object = UnityEngine.Object; 5 | 6 | namespace Dre0Dru.AddressableAssets.Loaders 7 | { 8 | [Serializable] 9 | public class AssetReferenceComponent : AssetReferenceGameObject where T : Component 10 | { 11 | public AssetReferenceComponent(string guid) : base(guid) 12 | { 13 | } 14 | 15 | public override bool ValidateAsset(Object obj) 16 | { 17 | var go = obj as GameObject; 18 | return go != null && go.GetComponent() != null; 19 | } 20 | 21 | public override bool ValidateAsset(string path) 22 | { 23 | #if UNITY_EDITOR 24 | var go = UnityEditor.AssetDatabase.LoadAssetAtPath(path); 25 | return go != null && go.GetComponent() != null; 26 | #else 27 | return false; 28 | #endif 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetReferenceComponent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44891d726f4090848b42fc63e2e4199e 3 | timeCreated: 1604785326 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetsLoaderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Cysharp.Threading.Tasks; 4 | using UnityEngine; 5 | using UnityEngine.AddressableAssets; 6 | #if VCONTAINER_SUPPORT 7 | using VContainer; 8 | #endif 9 | 10 | namespace Dre0Dru.AddressableAssets.Loaders 11 | { 12 | public static class AssetsLoaderExtensions 13 | { 14 | public static bool TryGetComponent( 15 | this IAssetsLoader, GameObject> assetsLoader, 16 | AssetReferenceComponent key, out T component) 17 | where T : Component 18 | { 19 | if (assetsLoader.TryGetAsset(key, out var gameObject)) 20 | { 21 | return gameObject.TryGetComponent(out component); 22 | } 23 | 24 | component = default; 25 | return false; 26 | } 27 | 28 | public static T GetComponent( 29 | this IAssetsLoader, GameObject> assetsLoader, 30 | AssetReferenceComponent key) 31 | where T : Component => 32 | assetsLoader.GetAsset(key).GetComponent(); 33 | 34 | public static UniTask PreloadAssetsAsync( 35 | this IAssetsLoader assetsLoader, 36 | params TKey[] keys) 37 | where TAsset : Object => 38 | UniTask.WhenAll(keys.Select(assetsLoader.PreloadAssetAsync)); 39 | 40 | public static UniTask PreloadAssetsAsync( 41 | this IAssetsLoader assetsLoader, 42 | IEnumerable keys) 43 | where TAsset : Object => 44 | UniTask.WhenAll(keys.Select(assetsLoader.PreloadAssetAsync)); 45 | 46 | public static void UnloadAssets( 47 | this IAssetsLoader assetsLoader, 48 | params TKey[] keys) 49 | where TAsset : Object => 50 | assetsLoader.UnloadAssets((IEnumerable)keys); 51 | 52 | public static void UnloadAssets( 53 | this IAssetsLoader assetsLoader, 54 | IEnumerable keys) 55 | where TAsset : Object 56 | { 57 | foreach (var key in keys) 58 | { 59 | assetsLoader.UnloadAsset(key); 60 | } 61 | } 62 | 63 | public static UniTask LoadAssetsAsync( 64 | this IAssetsLoader assetsLoader, 65 | params TKey[] keys) 66 | where TAsset : Object => 67 | LoadAssetsAsync(assetsLoader, (IEnumerable)keys); 68 | 69 | public static UniTask LoadAssetsAsync( 70 | this IAssetsLoader assetsLoader, 71 | IEnumerable keys) 72 | where TAsset : Object => 73 | UniTask.WhenAll(keys.Select(assetsLoader.LoadAssetAsync)); 74 | 75 | public static IEnumerable GetAssets( 76 | this IAssetsLoader assetsLoader, 77 | params TKey[] keys) 78 | where TAsset : Object => 79 | assetsLoader.GetAssets((IEnumerable)keys); 80 | 81 | public static IEnumerable GetAssets( 82 | this IAssetsLoader assetsLoader, 83 | IEnumerable keys) 84 | where TAsset : Object => 85 | keys.Select(assetsLoader.GetAsset); 86 | 87 | public static bool TryGetAssets( 88 | this IAssetsLoader assetsLoader, 89 | out IEnumerable assets, params TKey[] keys) 90 | where TAsset : Object => 91 | assetsLoader.TryGetAssets(keys, out assets); 92 | 93 | public static bool TryGetAssets( 94 | this IAssetsLoader assetsLoader, 95 | IEnumerable keys, out IEnumerable assets) 96 | where TAsset : Object 97 | { 98 | if (keys.All(assetsLoader.IsAssetLoaded) == false) 99 | { 100 | assets = Enumerable.Empty(); 101 | return false; 102 | } 103 | 104 | assets = assetsLoader.GetAssets(keys); 105 | return true; 106 | } 107 | 108 | #if VCONTAINER_SUPPORT 109 | 110 | public static RegistrationBuilder RegisterAssetsReferenceLoader(this IContainerBuilder builder, Lifetime lifetime) 111 | where TAsset : Object 112 | { 113 | return builder.Register, AssetsReferenceLoader>(lifetime); 114 | } 115 | 116 | #endif 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetsLoaderExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f4491a7fe3ad244190347e59b7b1b3b 3 | timeCreated: 1616830837 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetsReferenceLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Cysharp.Threading.Tasks; 3 | using UnityEngine; 4 | using UnityEngine.AddressableAssets; 5 | using UnityEngine.ResourceManagement.AsyncOperations; 6 | 7 | namespace Dre0Dru.AddressableAssets.Loaders 8 | { 9 | public sealed class 10 | AssetsReferenceLoader : IAssetsReferenceLoader 11 | where TAsset : Object 12 | { 13 | private readonly Dictionary> _operationHandles; 14 | 15 | #if UNITY_2020_3_OR_NEWER 16 | [UnityEngine.Scripting.RequiredMember] 17 | #endif 18 | public AssetsReferenceLoader() => 19 | _operationHandles = new Dictionary>(); 20 | 21 | public UniTask PreloadAssetAsync(AssetReferenceT key) => 22 | LoadAssetAsync(key); 23 | 24 | public async UniTask LoadAssetAsync(AssetReferenceT key) 25 | { 26 | var handle = GetLoadHandle(key); 27 | 28 | try 29 | { 30 | return await handle; 31 | } 32 | catch 33 | { 34 | Addressables.Release(handle); 35 | _operationHandles.Remove(key.RuntimeKey); 36 | throw; 37 | } 38 | } 39 | 40 | public bool IsAssetLoaded(AssetReferenceT key) 41 | { 42 | if (_operationHandles.TryGetValue(key.RuntimeKey, out var handle)) 43 | { 44 | return handle.IsDone; 45 | } 46 | 47 | return false; 48 | } 49 | 50 | public TAsset GetAsset(AssetReferenceT key) => 51 | _operationHandles[key.RuntimeKey].Result; 52 | 53 | public bool TryGetAsset(AssetReferenceT key, out TAsset asset) 54 | { 55 | asset = default; 56 | 57 | if (_operationHandles.TryGetValue(key.RuntimeKey, out var handle)) 58 | { 59 | if (handle.IsDone) 60 | { 61 | asset = handle.Result; 62 | } 63 | 64 | return handle.IsDone; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | public void UnloadAsset(AssetReferenceT key) 71 | { 72 | if (_operationHandles.TryGetValue(key.RuntimeKey, out var handle)) 73 | { 74 | Addressables.Release(handle); 75 | _operationHandles.Remove(key.RuntimeKey); 76 | } 77 | } 78 | 79 | public void UnloadAllAssets() 80 | { 81 | foreach (var handle in _operationHandles.Values) 82 | { 83 | Addressables.Release(handle); 84 | } 85 | 86 | _operationHandles.Clear(); 87 | } 88 | 89 | private AsyncOperationHandle GetLoadHandle(AssetReferenceT key) 90 | { 91 | if (!_operationHandles.TryGetValue(key.RuntimeKey, out var handle)) 92 | { 93 | handle = Addressables.LoadAssetAsync(key); 94 | _operationHandles.Add(key.RuntimeKey, handle); 95 | } 96 | 97 | return handle; 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/AssetsReferenceLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a66eebcaf2dc803449b1d73c6d84224c 3 | timeCreated: 1616830597 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/Dre0Dru.AddressableAssets.Loaders.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.AddressableAssets.Loaders", 3 | "rootNamespace": "Dre0Dru.AddressableAssets.Loaders", 4 | "references": [ 5 | "GUID:9e24947de15b9834991c9d8411ea37cf", 6 | "GUID:84651a3751eca9349aac36a66bba901b", 7 | "GUID:f51ebe6a0ceec4240a699833d6309b23", 8 | "GUID:593a5b492d29ac6448b1ebf7f035ef33", 9 | "GUID:b0214a6008ed146ff8f122a6a9c2f6cc" 10 | ], 11 | "includePlatforms": [], 12 | "excludePlatforms": [], 13 | "allowUnsafeCode": false, 14 | "overrideReferences": false, 15 | "precompiledReferences": [], 16 | "autoReferenced": true, 17 | "defineConstraints": [ 18 | "ADDRESSABLES_SUPPORT", 19 | "UNITASK_SUPPORT" 20 | ], 21 | "versionDefines": [ 22 | { 23 | "name": "jp.hadashikick.vcontainer", 24 | "expression": "", 25 | "define": "VCONTAINER_SUPPORT" 26 | }, 27 | { 28 | "name": "com.cysharp.unitask", 29 | "expression": "", 30 | "define": "UNITASK_SUPPORT" 31 | }, 32 | { 33 | "name": "com.unity.addressables", 34 | "expression": "", 35 | "define": "ADDRESSABLES_SUPPORT" 36 | } 37 | ], 38 | "noEngineReferences": false 39 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/Dre0Dru.AddressableAssets.Loaders.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9bfa8149881bc314697e6c3c96d0530a 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsLoader.cs: -------------------------------------------------------------------------------- 1 | using Cysharp.Threading.Tasks; 2 | using UnityEngine; 3 | 4 | namespace Dre0Dru.AddressableAssets.Loaders 5 | { 6 | public interface IAssetsLoader : IAssetsUnloader 7 | where TAsset : Object 8 | { 9 | UniTask PreloadAssetAsync(TKey key); 10 | 11 | UniTask LoadAssetAsync(TKey key); 12 | 13 | bool IsAssetLoaded(TKey key); 14 | 15 | TAsset GetAsset(TKey key); 16 | 17 | bool TryGetAsset(TKey key, out TAsset asset); 18 | 19 | void UnloadAsset(TKey key); 20 | } 21 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 708142ce87819834f867921a1815d949 3 | timeCreated: 1604748284 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsReferenceLoader.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.AddressableAssets; 3 | 4 | namespace Dre0Dru.AddressableAssets.Loaders 5 | { 6 | public interface IAssetsReferenceLoader : IAssetsLoader, TAsset> 7 | where TAsset : Object 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsReferenceLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57e534993aa343ed9e3afb32e22cd0da 3 | timeCreated: 1632742271 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsUnloader.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.Loaders 2 | { 3 | public interface IAssetsUnloader 4 | { 5 | void UnloadAllAssets(); 6 | } 7 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/Loaders/IAssetsUnloader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a37f1edfa2c54772b6ca913c7ae4b7bc 3 | timeCreated: 1627933957 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8d26858cdf95c841a5ec6ca57c49e96 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/Dre0Dru.AddressableAssets.SpriteAtlases.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.AddressableAssets.SpriteAtlases", 3 | "rootNamespace": "Dre0Dru.AddressableAssets.SpriteAtlases", 4 | "references": [ 5 | "GUID:9bfa8149881bc314697e6c3c96d0530a", 6 | "GUID:9e24947de15b9834991c9d8411ea37cf", 7 | "GUID:f51ebe6a0ceec4240a699833d6309b23", 8 | "GUID:b0214a6008ed146ff8f122a6a9c2f6cc", 9 | "GUID:70f7626a22e696b4cb0c451b9caa0dc1" 10 | ], 11 | "includePlatforms": [], 12 | "excludePlatforms": [], 13 | "allowUnsafeCode": false, 14 | "overrideReferences": false, 15 | "precompiledReferences": [], 16 | "autoReferenced": true, 17 | "defineConstraints": [ 18 | "ADDRESSABLES_SUPPORT", 19 | "UNITASK_SUPPORT" 20 | ], 21 | "versionDefines": [ 22 | { 23 | "name": "jp.hadashikick.vcontainer", 24 | "expression": "", 25 | "define": "VCONTAINER_SUPPORT" 26 | }, 27 | { 28 | "name": "com.cysharp.unitask", 29 | "expression": "", 30 | "define": "UNITASK_SUPPORT" 31 | }, 32 | { 33 | "name": "com.unity.addressables", 34 | "expression": "", 35 | "define": "ADDRESSABLES_SUPPORT" 36 | } 37 | ], 38 | "noEngineReferences": false 39 | } -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/Dre0Dru.AddressableAssets.SpriteAtlases.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0a2cce9c0cefda46877c8f1786e07da 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/ISpriteAtlasProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.AddressableAssets.SpriteAtlases 2 | { 3 | public interface ISpriteAtlasProvider 4 | { 5 | void SubscribeToAtlasManagerRequests(); 6 | void UnsubscribeFromAtlasManagerRequests(); 7 | void UnloadSpriteAtlases(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/ISpriteAtlasProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7204924800e4dfd8084133549a9ed66 3 | timeCreated: 1638107327 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/SpriteAtlasesProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dre0Dru.AddressableAssets.Common; 3 | using Dre0Dru.AddressableAssets.Loaders; 4 | using UnityEngine.Scripting; 5 | using UnityEngine.U2D; 6 | 7 | namespace Dre0Dru.AddressableAssets.SpriteAtlases 8 | { 9 | public class SpriteAtlasProvider : ISpriteAtlasProvider 10 | { 11 | private readonly IAssetsReferenceLoader _spriteAtlasLoader; 12 | private readonly IAssetReferenceProvider _spriteAtlasAssetReferenceProvider; 13 | 14 | [RequiredMember] 15 | public SpriteAtlasProvider(IAssetsReferenceLoader spriteAtlasLoader, 16 | IAssetReferenceProvider spriteAtlasAssetReferenceProvider) 17 | { 18 | _spriteAtlasLoader = spriteAtlasLoader; 19 | _spriteAtlasAssetReferenceProvider = spriteAtlasAssetReferenceProvider; 20 | } 21 | 22 | public void SubscribeToAtlasManagerRequests() 23 | { 24 | SpriteAtlasManager.atlasRequested += OnAtlasRequested; 25 | } 26 | 27 | public void UnsubscribeFromAtlasManagerRequests() 28 | { 29 | SpriteAtlasManager.atlasRequested -= OnAtlasRequested; 30 | } 31 | 32 | public void UnloadSpriteAtlases() 33 | { 34 | _spriteAtlasLoader.UnloadAllAssets(); 35 | } 36 | 37 | private async void OnAtlasRequested(string atlasName, Action callback) 38 | { 39 | var spriteAtlas = 40 | await _spriteAtlasLoader.LoadAssetAsync(_spriteAtlasAssetReferenceProvider.GetByKey(atlasName)); 41 | 42 | callback?.Invoke(spriteAtlas); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/SpriteAtlasesProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 898b78d2e2cb4875b82379f28bfb1795 3 | timeCreated: 1637930056 -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/SpriteAtlasesProviderEntryPoint.cs: -------------------------------------------------------------------------------- 1 | #if VCONTAINER_SUPPORT 2 | 3 | using System; 4 | using VContainer.Unity; 5 | 6 | namespace Dre0Dru.AddressableAssets.SpriteAtlases 7 | { 8 | public class SpriteAtlasesProviderEntryPoint : IInitializable, IDisposable 9 | { 10 | private readonly ISpriteAtlasProvider _spriteAtlasProvider; 11 | 12 | #if UNITY_2020_3_OR_NEWER 13 | [UnityEngine.Scripting.RequiredMember] 14 | #endif 15 | public SpriteAtlasesProviderEntryPoint(ISpriteAtlasProvider spriteAtlasProvider) 16 | { 17 | _spriteAtlasProvider = spriteAtlasProvider; 18 | } 19 | 20 | public void Initialize() 21 | { 22 | _spriteAtlasProvider.SubscribeToAtlasManagerRequests(); 23 | } 24 | 25 | public void Dispose() 26 | { 27 | _spriteAtlasProvider.UnsubscribeFromAtlasManagerRequests(); 28 | _spriteAtlasProvider.UnloadSpriteAtlases(); 29 | } 30 | } 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Runtime/AddressableAssets/SpriteAtlases/SpriteAtlasesProviderEntryPoint.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e2a96b3f9d4243c4864ba7b28c1557ed 3 | timeCreated: 1638107088 -------------------------------------------------------------------------------- /Runtime/GameAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a948a7d76e02b8544814883c53b9f529 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/GameAssets/Dre0Dru.GameAssets.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dre0Dru.GameAssets", 3 | "rootNamespace": "Dre0Dru.GameAssets", 4 | "references": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [], 13 | "noEngineReferences": false 14 | } -------------------------------------------------------------------------------- /Runtime/GameAssets/Dre0Dru.GameAssets.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f11e37a5a5be020458bc0db7dab7f3e8 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/GameAssets/GameAssetsExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Dre0Dru.GameAssets 4 | { 5 | public static class GameAssetsExtensions 6 | { 7 | public static TData ExtractData(this TDataAsset asset) 8 | where TDataAsset : IDataAsset => 9 | asset.Data; 10 | 11 | public static TDataAsset ExtractData(this TDataAsset asset, out TData data) 12 | where TDataAsset : IDataAsset 13 | { 14 | data = asset.Data; 15 | return asset; 16 | } 17 | 18 | public static TData CreateCopyAndExtractData(this TDataAsset asset) 19 | where TDataAsset : ScriptableObject, IDataAsset => 20 | Object.Instantiate(asset).ExtractData(); 21 | 22 | public static TDataAsset CreateCopyAndExtractData(this TDataAsset asset, out TData data) 23 | where TDataAsset : ScriptableObject, IDataAsset 24 | { 25 | Object.Destroy(Object.Instantiate(asset).ExtractData(out data)); 26 | return asset; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/GameAssets/GameAssetsExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3f3fe3d45c44d0185ff283014ea64cd 3 | timeCreated: 1652251805 -------------------------------------------------------------------------------- /Runtime/GameAssets/IDataAsset.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.GameAssets 2 | { 3 | public interface IDataAsset 4 | { 5 | TData Data { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Runtime/GameAssets/IDataAsset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 835b1065691d4904cbceb6ba7053cf34 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/GameAssets/IGameAsset.cs: -------------------------------------------------------------------------------- 1 | namespace Dre0Dru.GameAssets 2 | { 3 | public interface IGameAsset 4 | { 5 | //TODO guid? name? name -> guid -> asset? 6 | //TODO multiple keys? 7 | public string Guid { get; } 8 | } 9 | 10 | //TODO guid? name? name -> guid -> asset? 11 | //TODO multiple keys? 12 | public interface IGameAsset 13 | { 14 | public string Id { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Runtime/GameAssets/IGameAsset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59dd2a0d94db4fc4804518fb0b786104 3 | timeCreated: 1659820415 -------------------------------------------------------------------------------- /Runtime/GameAssets/ScopedAsset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using Object = UnityEngine.Object; 4 | 5 | namespace Dre0Dru.GameAssets 6 | { 7 | [Serializable] 8 | public class ScopedAsset : IDisposable 9 | where TAsset : ScriptableObject 10 | { 11 | [SerializeField] 12 | private TAsset _asset; 13 | 14 | private TAsset _instance; 15 | 16 | public TAsset Asset 17 | { 18 | get 19 | { 20 | if (_instance == null) 21 | { 22 | _instance = Object.Instantiate(_asset); 23 | } 24 | 25 | return _instance; 26 | } 27 | } 28 | 29 | public void Dispose() 30 | { 31 | if (_instance != null) 32 | { 33 | Object.Destroy(_instance); 34 | } 35 | } 36 | 37 | public static implicit operator TAsset(ScopedAsset scopedAsset) 38 | { 39 | return scopedAsset.Asset; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Runtime/GameAssets/ScopedAsset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6998cac8f10e409dba2e7b904e3743ac 3 | timeCreated: 1679846589 -------------------------------------------------------------------------------- /Runtime/GameAssets/TransientAsset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using Object = UnityEngine.Object; 4 | 5 | namespace Dre0Dru.GameAssets 6 | { 7 | [Serializable] 8 | public class TransientAsset 9 | where TAsset : ScriptableObject 10 | { 11 | [SerializeField] 12 | private TAsset _asset; 13 | 14 | public TAsset Asset => Object.Instantiate(_asset); 15 | 16 | public static implicit operator TAsset(TransientAsset scopedAsset) 17 | { 18 | return scopedAsset.Asset; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Runtime/GameAssets/TransientAsset.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22972b2a0dc84d558ee7e52122c3fc7e 3 | timeCreated: 1679847203 -------------------------------------------------------------------------------- /Runtime/TODO.md: -------------------------------------------------------------------------------- 1 | From Blades&Swords take runtime part 2 | Move AddressablesService here -------------------------------------------------------------------------------- /Runtime/TODO.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c3ee77249244721a4010e1e2d30bc3b 3 | timeCreated: 1665089316 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.dre0dru.assetmanagement", 3 | "version": "7.1.1", 4 | "displayName": "Asset Management", 5 | "description": "Strongly typed Addressables services for async/await workflow using UniTask:\n - Assets Loaders\n - Assets Donwloaders", 6 | "keywords": [ 7 | "Unity" 8 | ], 9 | "author": { 10 | "name": "Dre0Dru", 11 | "url": "https://github.com/dre0dru" 12 | }, 13 | "license": "MIT", 14 | "documentationUrl": "https://github.com/dre0dru", 15 | "changelogUrl": "https://github.com/dre0dru", 16 | "licensesUrl": "https://github.com/dre0dru", 17 | "type": "library" 18 | } 19 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7bacb03173b1704468c5ac1ba1ed6620 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------