├── .gitignore ├── AddressablesManager.meta ├── AddressablesManager ├── AddressablesManager.cs ├── AddressablesManager.cs.meta ├── AsyncTaskMethods.cs ├── AsyncTaskMethods.cs.meta ├── AsyncUniTaskMethods.cs ├── AsyncUniTaskMethods.cs.meta ├── BaseMethods.cs ├── BaseMethods.cs.meta ├── CallbackMethods.cs ├── CallbackMethods.cs.meta ├── CoroutineMethods.cs ├── CoroutineMethods.cs.meta ├── Exceptions.cs ├── Exceptions.cs.meta ├── OnCompletedMethods.cs ├── OnCompletedMethods.cs.meta ├── OperationResult.cs ├── OperationResult.cs.meta ├── SyncMethods.cs └── SyncMethods.cs.meta ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Unity.AddressablesManager.asmdef ├── Unity.AddressablesManager.asmdef.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | [Ll]ogs/ 7 | 8 | # Never ignore Asset meta data 9 | ![Aa]ssets/**/*.meta 10 | 11 | # Uncomment this line if you wish to ignore the asset store tools plugin 12 | # [Aa]ssets/AssetStoreTools* 13 | 14 | # Visual Studio cache directory 15 | .vs/ 16 | .vscode/ 17 | 18 | # Gradle cache directory 19 | .gradle/ 20 | 21 | # Autogenerated VS/MD/Consulo solution and project files 22 | ExportedObj/ 23 | .consulo/ 24 | *.csproj 25 | *.unityproj 26 | *.sln 27 | *.suo 28 | *.tmp 29 | *.user 30 | *.userprefs 31 | *.pidb 32 | *.booproj 33 | *.svd 34 | *.pdb 35 | *.mdb 36 | *.opendb 37 | *.VC.db 38 | .leu 39 | 40 | # Unity3D generated meta files 41 | *.pidb.meta 42 | *.pdb.meta 43 | *.mdb.meta 44 | 45 | # Unity3D generated file on crash reports 46 | sysinfo.txt 47 | 48 | # Builds 49 | *.apk 50 | *.unitypackage 51 | -------------------------------------------------------------------------------- /AddressablesManager.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8d18c882bd045f44bdd75bbf2303e57 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /AddressablesManager/AddressablesManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace UnityEngine.AddressableAssets 5 | { 6 | using ResourceManagement.ResourceProviders; 7 | using ResourceManagement.ResourceLocations; 8 | 9 | public static partial class AddressablesManager 10 | { 11 | public enum ExceptionHandleType 12 | { 13 | Log, Throw, Suppress 14 | } 15 | 16 | private static readonly Dictionary> _locations; 17 | private static readonly List _noLocation; 18 | private static readonly Dictionary _assets; 19 | private static readonly Dictionary _scenes; 20 | private static readonly Dictionary> _instances; 21 | private static readonly Queue> _instanceListPool; 22 | private static readonly List _noInstanceList; 23 | private static readonly List _keys; 24 | 25 | public static IReadOnlyList Keys => _keys; 26 | 27 | public static ExceptionHandleType ExceptionHandle { get; set; } 28 | 29 | public static bool SuppressWarningLogs { get; set; } 30 | 31 | public static bool SuppressErrorLogs { get; set; } 32 | 33 | static AddressablesManager() 34 | { 35 | ExceptionHandle = ExceptionHandleType.Log; 36 | 37 | _locations = new Dictionary>(); 38 | _noLocation = new List(0); 39 | _assets = new Dictionary(); 40 | _scenes = new Dictionary(); 41 | _instances = new Dictionary>(); 42 | _instanceListPool = new Queue>(); 43 | _noInstanceList = new List(0); 44 | _keys = new List(); 45 | } 46 | 47 | #if UNITY_EDITOR 48 | // Support the usecase of disabled Domain Reload 49 | [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] 50 | static void Init() 51 | { 52 | _locations.Clear(); 53 | _noLocation.Clear(); 54 | _assets.Clear(); 55 | _scenes.Clear(); 56 | _instances.Clear(); 57 | _instanceListPool.Clear(); 58 | _noInstanceList.Clear(); 59 | _keys.Clear(); 60 | ExceptionHandle = default; 61 | SuppressWarningLogs = default; 62 | SuppressErrorLogs = default; 63 | } 64 | #endif 65 | 66 | private static void Clear() 67 | { 68 | _keys.Clear(); 69 | _locations.Clear(); 70 | _assets.Clear(); 71 | _scenes.Clear(); 72 | } 73 | 74 | private static List GetInstanceList() 75 | { 76 | if (_instanceListPool.Count > 0) 77 | return _instanceListPool.Dequeue(); 78 | 79 | return new List(); 80 | } 81 | 82 | private static void PoolInstanceList(List list) 83 | { 84 | list.Clear(); 85 | _instanceListPool.Enqueue(list); 86 | } 87 | 88 | private static bool GuardKey(string key, out string result) 89 | { 90 | result = key ?? string.Empty; 91 | 92 | return !string.IsNullOrEmpty(result); 93 | } 94 | 95 | private static bool GuardKey(AssetReference reference, out string result) 96 | { 97 | if (reference == null) 98 | { 99 | if (ExceptionHandle == ExceptionHandleType.Throw) 100 | throw new ArgumentNullException(nameof(reference)); 101 | 102 | if (ExceptionHandle == ExceptionHandleType.Log) 103 | Debug.LogException(new ArgumentNullException(nameof(reference))); 104 | 105 | result = string.Empty; 106 | } 107 | else 108 | { 109 | result = reference.RuntimeKey.ToString(); 110 | } 111 | 112 | return !string.IsNullOrEmpty(result); 113 | } 114 | 115 | public static bool ContainsAsset(string key) 116 | => _assets.ContainsKey(key) && _assets[key]; 117 | 118 | public static bool ContainsKey(object key) 119 | => _keys.Contains(key); 120 | 121 | public static bool TryGetScene(string key, out SceneInstance scene) 122 | { 123 | scene = default; 124 | 125 | if (!GuardKey(key, out key)) 126 | { 127 | if (ExceptionHandle == ExceptionHandleType.Throw) 128 | throw new InvalidKeyException(key); 129 | 130 | if (ExceptionHandle == ExceptionHandleType.Log) 131 | Debug.LogException(new InvalidKeyException(key)); 132 | 133 | return false; 134 | } 135 | 136 | if (_scenes.TryGetValue(key, out var value)) 137 | { 138 | scene = value; 139 | return true; 140 | } 141 | 142 | if (!SuppressWarningLogs) 143 | Debug.LogWarning($"No scene with key={key} has been loaded through {nameof(AddressablesManager)}."); 144 | 145 | return false; 146 | } 147 | 148 | public static bool TryGetScene(AssetReference reference, out SceneInstance scene) 149 | { 150 | scene = default; 151 | 152 | if (!GuardKey(reference, out var key)) 153 | { 154 | if (ExceptionHandle == ExceptionHandleType.Throw) 155 | throw Exceptions.InvalidReference; 156 | 157 | if (ExceptionHandle == ExceptionHandleType.Log) 158 | Debug.LogException(new InvalidKeyException(key)); 159 | 160 | return false; 161 | } 162 | 163 | if (_scenes.TryGetValue(key, out var value)) 164 | { 165 | scene = value; 166 | return true; 167 | } 168 | 169 | return false; 170 | } 171 | 172 | public static IReadOnlyList GetLocations(string key) 173 | { 174 | if (!GuardKey(key, out key)) 175 | { 176 | if (ExceptionHandle == ExceptionHandleType.Throw) 177 | throw new InvalidKeyException(key); 178 | 179 | if (ExceptionHandle == ExceptionHandleType.Log) 180 | Debug.LogException(new InvalidKeyException(key)); 181 | 182 | return _noLocation; 183 | } 184 | 185 | if (!_locations.TryGetValue(key, out var list)) 186 | return _noLocation; 187 | 188 | return list; 189 | } 190 | 191 | public static T GetAsset(string key) where T : Object 192 | { 193 | if (!GuardKey(key, out key)) 194 | { 195 | if (ExceptionHandle == ExceptionHandleType.Throw) 196 | throw new InvalidKeyException(key); 197 | 198 | if (ExceptionHandle == ExceptionHandleType.Log) 199 | Debug.LogException(new InvalidKeyException(key)); 200 | 201 | return default; 202 | } 203 | 204 | return GetAssetInternal(key); 205 | } 206 | 207 | public static T GetAsset(AssetReference reference) where T : Object 208 | { 209 | if (!GuardKey(reference, out var key)) 210 | { 211 | if (ExceptionHandle == ExceptionHandleType.Throw) 212 | throw Exceptions.InvalidReference; 213 | 214 | if (ExceptionHandle == ExceptionHandleType.Log) 215 | Debug.LogException(new InvalidKeyException(key)); 216 | 217 | return default; 218 | } 219 | 220 | return GetAssetInternal(key); 221 | } 222 | 223 | private static T GetAssetInternal(string key) where T : Object 224 | { 225 | if (!_assets.ContainsKey(key)) 226 | { 227 | if (!SuppressWarningLogs) 228 | Debug.LogWarning(Exceptions.CannotFindAssetByKey(key)); 229 | 230 | return default; 231 | } 232 | 233 | if (_assets[key] is T asset) 234 | return asset; 235 | 236 | if (!SuppressWarningLogs) 237 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 238 | 239 | return default; 240 | } 241 | 242 | public static bool TryGetAsset(string key, out T asset) where T : Object 243 | { 244 | asset = default; 245 | 246 | if (!GuardKey(key, out key)) 247 | { 248 | if (ExceptionHandle == ExceptionHandleType.Throw) 249 | throw new InvalidKeyException(key); 250 | 251 | if (ExceptionHandle == ExceptionHandleType.Log) 252 | Debug.LogException(new InvalidKeyException(key)); 253 | 254 | return false; 255 | } 256 | 257 | return TryGetAssetInternal(key, out asset); 258 | } 259 | 260 | public static bool TryGetAsset(AssetReference reference, out T asset) where T : Object 261 | { 262 | asset = default; 263 | 264 | if (!GuardKey(reference, out var key)) 265 | { 266 | if (ExceptionHandle == ExceptionHandleType.Throw) 267 | throw Exceptions.InvalidReference; 268 | 269 | if (ExceptionHandle == ExceptionHandleType.Log) 270 | Debug.LogException(new InvalidKeyException(key)); 271 | 272 | return false; 273 | } 274 | 275 | return TryGetAssetInternal(key, out asset); 276 | } 277 | 278 | private static bool TryGetAssetInternal(string key, out T asset) where T : Object 279 | { 280 | asset = default; 281 | 282 | if (!_assets.ContainsKey(key)) 283 | { 284 | if (!SuppressWarningLogs) 285 | Debug.LogWarning(Exceptions.CannotFindAssetByKey(key)); 286 | 287 | return false; 288 | } 289 | 290 | if (_assets[key] is T assetT) 291 | { 292 | asset = assetT; 293 | return true; 294 | } 295 | 296 | if (!SuppressWarningLogs) 297 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 298 | 299 | return false; 300 | } 301 | 302 | public static void ReleaseAsset(string key) 303 | { 304 | if (!GuardKey(key, out key)) 305 | { 306 | if (ExceptionHandle == ExceptionHandleType.Throw) 307 | throw new InvalidKeyException(key); 308 | 309 | if (ExceptionHandle == ExceptionHandleType.Log) 310 | Debug.LogException(new InvalidKeyException(key)); 311 | 312 | return; 313 | } 314 | 315 | if (!_assets.TryGetValue(key, out var asset)) 316 | return; 317 | 318 | _assets.Remove(key); 319 | Addressables.Release(asset); 320 | } 321 | 322 | public static void ReleaseAsset(AssetReference reference) 323 | { 324 | if (!GuardKey(reference, out var key)) 325 | { 326 | if (ExceptionHandle == ExceptionHandleType.Throw) 327 | throw Exceptions.InvalidReference; 328 | 329 | if (ExceptionHandle == ExceptionHandleType.Log) 330 | Debug.LogException(new InvalidKeyException(key)); 331 | 332 | return; 333 | } 334 | 335 | if (!_assets.ContainsKey(key)) 336 | return; 337 | 338 | _assets.Remove(key); 339 | reference.ReleaseAsset(); 340 | } 341 | 342 | public static IReadOnlyList GetInstances(string key) 343 | { 344 | if (!GuardKey(key, out key)) 345 | { 346 | if (ExceptionHandle == ExceptionHandleType.Throw) 347 | throw new InvalidKeyException(key); 348 | 349 | if (ExceptionHandle == ExceptionHandleType.Log) 350 | Debug.LogException(new InvalidKeyException(key)); 351 | 352 | return _noInstanceList; 353 | } 354 | 355 | if (_instances.TryGetValue(key, out var instanceList)) 356 | return instanceList; 357 | 358 | return _noInstanceList; 359 | } 360 | 361 | public static IReadOnlyList GetInstances(AssetReference reference) 362 | { 363 | if (!GuardKey(reference, out var key)) 364 | { 365 | if (ExceptionHandle == ExceptionHandleType.Throw) 366 | throw Exceptions.InvalidReference; 367 | 368 | if (ExceptionHandle == ExceptionHandleType.Log) 369 | Debug.LogException(new InvalidKeyException(key)); 370 | 371 | return _noInstanceList; 372 | } 373 | 374 | if (_instances.TryGetValue(key, out var instanceList)) 375 | return instanceList; 376 | 377 | return _noInstanceList; 378 | } 379 | 380 | public static void ReleaseInstances(string key) 381 | { 382 | if (!GuardKey(key, out key)) 383 | { 384 | if (ExceptionHandle == ExceptionHandleType.Throw) 385 | throw new InvalidKeyException(key); 386 | 387 | if (ExceptionHandle == ExceptionHandleType.Log) 388 | Debug.LogException(new InvalidKeyException(key)); 389 | 390 | return; 391 | } 392 | 393 | ReleaseInstanceInternal(key); 394 | } 395 | 396 | public static void ReleaseInstances(AssetReference reference) 397 | { 398 | if (!GuardKey(reference, out var key)) 399 | { 400 | if (ExceptionHandle == ExceptionHandleType.Throw) 401 | throw Exceptions.InvalidReference; 402 | 403 | if (ExceptionHandle == ExceptionHandleType.Log) 404 | Debug.LogException(new InvalidKeyException(key)); 405 | 406 | return; 407 | } 408 | 409 | ReleaseInstanceInternal(key); 410 | } 411 | 412 | private static void ReleaseInstanceInternal(string key) 413 | { 414 | if (!_instances.TryGetValue(key, out var instanceList)) 415 | return; 416 | 417 | _instances.Remove(key); 418 | 419 | foreach (var instance in instanceList) 420 | { 421 | Addressables.ReleaseInstance(instance); 422 | } 423 | 424 | PoolInstanceList(instanceList); 425 | } 426 | 427 | public static void ReleaseInstance(string key, GameObject instance) 428 | { 429 | if (!GuardKey(key, out key)) 430 | { 431 | if (ExceptionHandle == ExceptionHandleType.Throw) 432 | throw new InvalidKeyException(key); 433 | 434 | if (ExceptionHandle == ExceptionHandleType.Log) 435 | Debug.LogException(new InvalidKeyException(key)); 436 | 437 | return; 438 | } 439 | 440 | ReleaseInstanceInternal(key, instance); 441 | } 442 | 443 | public static void ReleaseInstance(AssetReference reference, GameObject instance) 444 | { 445 | if (!GuardKey(reference, out var key)) 446 | { 447 | if (ExceptionHandle == ExceptionHandleType.Throw) 448 | throw Exceptions.InvalidReference; 449 | 450 | if (ExceptionHandle == ExceptionHandleType.Log) 451 | Debug.LogException(new InvalidKeyException(key)); 452 | 453 | return; 454 | } 455 | 456 | ReleaseInstanceInternal(key, instance); 457 | } 458 | 459 | private static void ReleaseInstanceInternal(string key, GameObject instance) 460 | { 461 | if (!instance) 462 | return; 463 | 464 | if (!_instances.TryGetValue(key, out var instanceList)) 465 | { 466 | if (!SuppressWarningLogs) 467 | Debug.LogWarning(Exceptions.NoInstanceKeyInitialized(key), instance); 468 | 469 | return; 470 | } 471 | 472 | var index = instanceList.FindIndex(x => x.GetInstanceID() == instance.GetInstanceID()); 473 | 474 | if (index < 0) 475 | { 476 | if (!SuppressWarningLogs) 477 | Debug.LogWarning(Exceptions.NoInstanceKeyInitialized(key), instance); 478 | 479 | return; 480 | } 481 | 482 | instanceList.RemoveAt(index); 483 | Addressables.ReleaseInstance(instance); 484 | 485 | if (instanceList.Count > 0) 486 | return; 487 | 488 | _instances.Remove(key); 489 | PoolInstanceList(instanceList); 490 | } 491 | } 492 | } -------------------------------------------------------------------------------- /AddressablesManager/AddressablesManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a82c310384da99340a484e7cc1d6e62b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/AsyncTaskMethods.cs: -------------------------------------------------------------------------------- 1 | #if !ADDRESSABLES_UNITASK 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Threading.Tasks; 6 | using System.Runtime.CompilerServices; 7 | using UnityEngine.SceneManagement; 8 | using UnityEngine.ResourceManagement.ResourceLocations; 9 | 10 | namespace UnityEngine.AddressableAssets 11 | { 12 | using ResourceManagement.ResourceProviders; 13 | using AddressableAssets.ResourceLocators; 14 | 15 | public static partial class AddressablesManager 16 | { 17 | public static async Task> InitializeAsync(bool autoReleaseHandle = true) 18 | { 19 | Clear(); 20 | 21 | try 22 | { 23 | var operation = Addressables.InitializeAsync(false); 24 | await operation.Task; 25 | 26 | OnInitializeCompleted(operation); 27 | 28 | var result = new OperationResult(operation); 29 | 30 | if (autoReleaseHandle) 31 | { 32 | Addressables.Release(operation); 33 | } 34 | 35 | return result; 36 | } 37 | catch (Exception ex) 38 | { 39 | if (ExceptionHandle == ExceptionHandleType.Throw) 40 | throw ex; 41 | 42 | if (ExceptionHandle == ExceptionHandleType.Log) 43 | Debug.LogException(ex); 44 | 45 | return new OperationResult(false, default, default); 46 | } 47 | } 48 | 49 | public static async Task>> LoadLocationsAsync(object key, Type type = null) 50 | { 51 | if (key == null) 52 | { 53 | if (ExceptionHandle == ExceptionHandleType.Throw) 54 | throw new InvalidKeyException(key); 55 | 56 | if (ExceptionHandle == ExceptionHandleType.Log) 57 | Debug.LogException(new InvalidKeyException(key)); 58 | 59 | return new OperationResult>(false, key, default); 60 | } 61 | 62 | try 63 | { 64 | var operation = Addressables.LoadResourceLocationsAsync(key, type); 65 | await operation.Task; 66 | 67 | OnLoadLocationsCompleted(operation, key); 68 | return new OperationResult>(key, operation); 69 | } 70 | catch (Exception ex) 71 | { 72 | if (ExceptionHandle == ExceptionHandleType.Throw) 73 | throw ex; 74 | 75 | if (ExceptionHandle == ExceptionHandleType.Log) 76 | Debug.LogException(ex); 77 | 78 | return new OperationResult>(false, key, default); 79 | } 80 | } 81 | 82 | public static async Task> LoadAssetAsync(string key) where T : Object 83 | { 84 | if (!GuardKey(key, out key)) 85 | { 86 | if (ExceptionHandle == ExceptionHandleType.Throw) 87 | throw new InvalidKeyException(key); 88 | 89 | if (ExceptionHandle == ExceptionHandleType.Log) 90 | Debug.LogException(new InvalidKeyException(key)); 91 | 92 | return new OperationResult(false, key, default); 93 | } 94 | 95 | if (_assets.ContainsKey(key)) 96 | { 97 | if (_assets[key] is T asset) 98 | return new OperationResult(true, key, asset); 99 | 100 | if (!SuppressWarningLogs) 101 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 102 | 103 | return new OperationResult(false, key, default); 104 | } 105 | 106 | try 107 | { 108 | var operation = Addressables.LoadAssetAsync(key); 109 | await operation.Task; 110 | 111 | OnLoadAssetCompleted(operation, key, false); 112 | return new OperationResult(key, operation); 113 | } 114 | catch (Exception ex) 115 | { 116 | if (ExceptionHandle == ExceptionHandleType.Throw) 117 | throw ex; 118 | 119 | if (ExceptionHandle == ExceptionHandleType.Log) 120 | Debug.LogException(ex); 121 | 122 | return new OperationResult(false, key, default); 123 | } 124 | } 125 | 126 | public static async Task> LoadAssetAsync(AssetReferenceT reference) where T : Object 127 | { 128 | if (!GuardKey(reference, out var key)) 129 | { 130 | if (ExceptionHandle == ExceptionHandleType.Throw) 131 | throw Exceptions.InvalidReference; 132 | 133 | if (ExceptionHandle == ExceptionHandleType.Log) 134 | Debug.LogException(new InvalidKeyException(key)); 135 | 136 | return new OperationResult(false, reference, default); 137 | } 138 | 139 | if (_assets.ContainsKey(key)) 140 | { 141 | if (_assets[key] is T asset) 142 | return new OperationResult(true, reference, asset); 143 | 144 | if (!SuppressWarningLogs) 145 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 146 | 147 | return new OperationResult(false, reference, default); 148 | } 149 | 150 | try 151 | { 152 | var operation = reference.LoadAssetAsync(); 153 | await operation.Task; 154 | 155 | OnLoadAssetCompleted(operation, key, true); 156 | return new OperationResult(reference, operation); 157 | } 158 | catch (Exception ex) 159 | { 160 | if (ExceptionHandle == ExceptionHandleType.Throw) 161 | throw ex; 162 | 163 | if (ExceptionHandle == ExceptionHandleType.Log) 164 | Debug.LogException(ex); 165 | 166 | return new OperationResult(false, reference, default); 167 | } 168 | } 169 | 170 | public static async Task ActivateSceneAsync(SceneInstance scene, int priority) 171 | { 172 | var operation = scene.ActivateAsync(); 173 | operation.priority = priority; 174 | 175 | await operation; 176 | } 177 | 178 | public static async Task> LoadSceneAsync(string key, 179 | LoadSceneMode loadMode = LoadSceneMode.Single, 180 | bool activateOnLoad = true, 181 | int priority = 100) 182 | { 183 | if (!GuardKey(key, out key)) 184 | { 185 | if (ExceptionHandle == ExceptionHandleType.Throw) 186 | throw new InvalidKeyException(key); 187 | 188 | if (ExceptionHandle == ExceptionHandleType.Log) 189 | Debug.LogException(new InvalidKeyException(key)); 190 | 191 | return new OperationResult(false, key, default); 192 | } 193 | 194 | if (_scenes.TryGetValue(key, out var scene)) 195 | { 196 | if (activateOnLoad) 197 | await ActivateSceneAsync(scene, priority); 198 | 199 | return new OperationResult(true, key, in scene); 200 | } 201 | 202 | try 203 | { 204 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 205 | await operation.Task; 206 | 207 | OnLoadSceneCompleted(operation, key); 208 | return new OperationResult(key, operation); 209 | } 210 | catch (Exception ex) 211 | { 212 | if (ExceptionHandle == ExceptionHandleType.Throw) 213 | throw ex; 214 | 215 | if (ExceptionHandle == ExceptionHandleType.Log) 216 | Debug.LogException(ex); 217 | 218 | return new OperationResult(false, key, default); 219 | } 220 | } 221 | 222 | public static async Task> LoadSceneAsync(AssetReference reference, 223 | LoadSceneMode loadMode = LoadSceneMode.Single, 224 | bool activateOnLoad = true, 225 | int priority = 100) 226 | { 227 | if (!GuardKey(reference, out var key)) 228 | { 229 | if (ExceptionHandle == ExceptionHandleType.Throw) 230 | throw Exceptions.InvalidReference; 231 | 232 | if (ExceptionHandle == ExceptionHandleType.Log) 233 | Debug.LogException(new InvalidKeyException(key)); 234 | 235 | return new OperationResult(false, reference, default); 236 | } 237 | 238 | if (_scenes.TryGetValue(key, out var scene)) 239 | { 240 | if (activateOnLoad) 241 | await ActivateSceneAsync(scene, priority); 242 | 243 | return new OperationResult(true, reference, in scene); 244 | } 245 | 246 | try 247 | { 248 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 249 | await operation.Task; 250 | 251 | OnLoadSceneCompleted(operation, key); 252 | return new OperationResult(reference, operation); 253 | } 254 | catch (Exception ex) 255 | { 256 | if (ExceptionHandle == ExceptionHandleType.Throw) 257 | throw ex; 258 | 259 | if (ExceptionHandle == ExceptionHandleType.Log) 260 | Debug.LogException(ex); 261 | 262 | return new OperationResult(false, reference, default); 263 | } 264 | } 265 | 266 | public static async Task> UnloadSceneAsync(string key, bool autoReleaseHandle = true) 267 | { 268 | if (!GuardKey(key, out key)) 269 | { 270 | if (ExceptionHandle == ExceptionHandleType.Throw) 271 | throw new InvalidKeyException(key); 272 | 273 | if (ExceptionHandle == ExceptionHandleType.Log) 274 | Debug.LogException(new InvalidKeyException(key)); 275 | 276 | return new OperationResult(false, key, default); 277 | } 278 | 279 | if (!_scenes.TryGetValue(key, out var scene)) 280 | { 281 | if (!SuppressWarningLogs) 282 | Debug.LogWarning(Exceptions.NoSceneKeyLoaded(key)); 283 | 284 | return new OperationResult(false, key, default); 285 | } 286 | 287 | _scenes.Remove(key); 288 | 289 | try 290 | { 291 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 292 | await operation.Task; 293 | 294 | return new OperationResult(key, operation); 295 | } 296 | catch (Exception ex) 297 | { 298 | if (ExceptionHandle == ExceptionHandleType.Throw) 299 | throw ex; 300 | 301 | if (ExceptionHandle == ExceptionHandleType.Log) 302 | Debug.LogException(ex); 303 | 304 | return new OperationResult(false, key, in scene); 305 | } 306 | } 307 | 308 | public static async Task> UnloadSceneAsync(AssetReference reference) 309 | { 310 | if (!GuardKey(reference, out var key)) 311 | { 312 | if (ExceptionHandle == ExceptionHandleType.Throw) 313 | throw Exceptions.InvalidReference; 314 | 315 | if (ExceptionHandle == ExceptionHandleType.Log) 316 | Debug.LogException(new InvalidKeyException(key)); 317 | 318 | return new OperationResult(false, reference, default); 319 | } 320 | 321 | if (!_scenes.TryGetValue(key, out var scene)) 322 | { 323 | if (!SuppressWarningLogs) 324 | Debug.LogWarning(Exceptions.NoSceneReferenceLoaded(key)); 325 | 326 | return new OperationResult(false, reference, default); 327 | } 328 | 329 | _scenes.Remove(key); 330 | 331 | try 332 | { 333 | var operation = reference.UnLoadScene(); 334 | await operation.Task; 335 | 336 | return new OperationResult(reference, operation); 337 | } 338 | catch (Exception ex) 339 | { 340 | if (ExceptionHandle == ExceptionHandleType.Throw) 341 | throw ex; 342 | 343 | if (ExceptionHandle == ExceptionHandleType.Log) 344 | Debug.LogException(ex); 345 | 346 | return new OperationResult(false, reference, scene); 347 | } 348 | } 349 | 350 | public static async Task> InstantiateAsync(string key, 351 | Transform parent = null, 352 | bool inWorldSpace = false, 353 | bool trackHandle = true) 354 | { 355 | if (!GuardKey(key, out key)) 356 | { 357 | if (ExceptionHandle == ExceptionHandleType.Throw) 358 | throw new InvalidKeyException(key); 359 | 360 | if (ExceptionHandle == ExceptionHandleType.Log) 361 | Debug.LogException(new InvalidKeyException(key)); 362 | 363 | return new OperationResult(false, key, default); 364 | } 365 | 366 | try 367 | { 368 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 369 | await operation.Task; 370 | 371 | OnInstantiateCompleted(operation, key, false); 372 | return new OperationResult(key, operation); 373 | } 374 | catch (Exception ex) 375 | { 376 | if (ExceptionHandle == ExceptionHandleType.Throw) 377 | throw ex; 378 | 379 | if (ExceptionHandle == ExceptionHandleType.Log) 380 | Debug.LogException(ex); 381 | 382 | return new OperationResult(false, key, default); 383 | } 384 | } 385 | 386 | public static async Task> InstantiateAsync(AssetReference reference, 387 | Transform parent = null, 388 | bool inWorldSpace = false) 389 | { 390 | if (!GuardKey(reference, out var key)) 391 | { 392 | if (ExceptionHandle == ExceptionHandleType.Throw) 393 | throw Exceptions.InvalidReference; 394 | 395 | if (ExceptionHandle == ExceptionHandleType.Log) 396 | Debug.LogException(new InvalidKeyException(key)); 397 | 398 | return new OperationResult(false, reference, default); 399 | } 400 | 401 | try 402 | { 403 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 404 | await operation.Task; 405 | 406 | OnInstantiateCompleted(operation, key, true); 407 | return new OperationResult(reference, operation); 408 | } 409 | catch (Exception ex) 410 | { 411 | if (ExceptionHandle == ExceptionHandleType.Throw) 412 | throw ex; 413 | 414 | if (ExceptionHandle == ExceptionHandleType.Log) 415 | Debug.LogException(ex); 416 | 417 | return new OperationResult(false, reference, default); 418 | } 419 | } 420 | } 421 | 422 | internal static partial class AsyncOperationExtensions 423 | { 424 | public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation operation) 425 | { 426 | return new AsyncOperationAwaiter(operation); 427 | } 428 | } 429 | 430 | internal readonly struct AsyncOperationAwaiter : INotifyCompletion 431 | { 432 | private readonly AsyncOperation operation; 433 | 434 | public AsyncOperationAwaiter(AsyncOperation operation) 435 | { 436 | this.operation = operation ?? throw new ArgumentNullException(nameof(operation)); 437 | } 438 | 439 | public bool IsCompleted 440 | => this.operation.isDone; 441 | 442 | public void OnCompleted(Action continuation) 443 | => this.operation.completed += _ => continuation?.Invoke(); 444 | 445 | public void GetResult() { } 446 | } 447 | } 448 | 449 | #endif -------------------------------------------------------------------------------- /AddressablesManager/AsyncTaskMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69346ecc06c661c44a5d5012d885cb40 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/AsyncUniTaskMethods.cs: -------------------------------------------------------------------------------- 1 | #if ADDRESSABLES_UNITASK 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using UnityEngine.ResourceManagement.ResourceLocations; 6 | using UnityEngine.SceneManagement; 7 | using Cysharp.Threading.Tasks; 8 | 9 | namespace UnityEngine.AddressableAssets 10 | { 11 | using ResourceManagement.ResourceProviders; 12 | using AddressableAssets.ResourceLocators; 13 | 14 | public static partial class AddressablesManager 15 | { 16 | public static async UniTask> InitializeAsync(bool autoReleaseHandle = true) 17 | { 18 | Clear(); 19 | 20 | try 21 | { 22 | var operation = Addressables.InitializeAsync(false); 23 | await operation; 24 | 25 | OnInitializeCompleted(operation); 26 | 27 | var result = new OperationResult(operation); 28 | 29 | if (autoReleaseHandle) 30 | { 31 | Addressables.Release(operation); 32 | } 33 | 34 | return result; 35 | } 36 | catch (Exception ex) 37 | { 38 | if (ExceptionHandle == ExceptionHandleType.Throw) 39 | throw ex; 40 | 41 | if (ExceptionHandle == ExceptionHandleType.Log) 42 | Debug.LogException(ex); 43 | 44 | return new OperationResult(false, default, default); 45 | } 46 | } 47 | 48 | public static async UniTask>> LoadLocationsAsync(object key, Type type = null) 49 | { 50 | if (key == null) 51 | { 52 | if (ExceptionHandle == ExceptionHandleType.Throw) 53 | throw new InvalidKeyException(key); 54 | 55 | if (ExceptionHandle == ExceptionHandleType.Log) 56 | Debug.LogException(new InvalidKeyException(key)); 57 | 58 | return new OperationResult>(false, key, default); 59 | } 60 | 61 | try 62 | { 63 | var operation = Addressables.LoadResourceLocationsAsync(key, type); 64 | await operation; 65 | 66 | OnLoadLocationsCompleted(operation, key); 67 | return new OperationResult>(key, operation); 68 | } 69 | catch (Exception ex) 70 | { 71 | if (ExceptionHandle == ExceptionHandleType.Throw) 72 | throw ex; 73 | 74 | if (ExceptionHandle == ExceptionHandleType.Log) 75 | Debug.LogException(ex); 76 | 77 | return new OperationResult>(false, key, default); 78 | } 79 | } 80 | 81 | public static async UniTask> LoadAssetAsync(string key) where T : Object 82 | { 83 | if (!GuardKey(key, out key)) 84 | { 85 | if (ExceptionHandle == ExceptionHandleType.Throw) 86 | throw new InvalidKeyException(key); 87 | 88 | if (ExceptionHandle == ExceptionHandleType.Log) 89 | Debug.LogException(new InvalidKeyException(key)); 90 | 91 | return new OperationResult(false, key, default); 92 | } 93 | 94 | if (_assets.ContainsKey(key)) 95 | { 96 | if (_assets[key] is T asset) 97 | return new OperationResult(true, key, asset); 98 | 99 | if (!SuppressWarningLogs) 100 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 101 | 102 | return new OperationResult(false, key, default); 103 | } 104 | 105 | try 106 | { 107 | var operation = Addressables.LoadAssetAsync(key); 108 | await operation; 109 | 110 | OnLoadAssetCompleted(operation, key, false); 111 | return new OperationResult(key, operation); 112 | } 113 | catch (Exception ex) 114 | { 115 | if (ExceptionHandle == ExceptionHandleType.Throw) 116 | throw ex; 117 | 118 | if (ExceptionHandle == ExceptionHandleType.Log) 119 | Debug.LogException(ex); 120 | 121 | return new OperationResult(false, key, default); 122 | } 123 | } 124 | 125 | public static async UniTask> LoadAssetAsync(AssetReferenceT reference) where T : Object 126 | { 127 | if (!GuardKey(reference, out var key)) 128 | { 129 | if (ExceptionHandle == ExceptionHandleType.Throw) 130 | throw Exceptions.InvalidReference; 131 | 132 | if (ExceptionHandle == ExceptionHandleType.Log) 133 | Debug.LogException(new InvalidKeyException(key)); 134 | 135 | return new OperationResult(false, reference, default); 136 | } 137 | 138 | if (_assets.ContainsKey(key)) 139 | { 140 | if (_assets[key] is T asset) 141 | return new OperationResult(true, reference, asset); 142 | 143 | if (!SuppressWarningLogs) 144 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 145 | 146 | return new OperationResult(false, reference, default); 147 | } 148 | 149 | try 150 | { 151 | var operation = reference.LoadAssetAsync(); 152 | await operation; 153 | 154 | OnLoadAssetCompleted(operation, key, true); 155 | return new OperationResult(reference, operation); 156 | } 157 | catch (Exception ex) 158 | { 159 | if (ExceptionHandle == ExceptionHandleType.Throw) 160 | throw ex; 161 | 162 | if (ExceptionHandle == ExceptionHandleType.Log) 163 | Debug.LogException(ex); 164 | 165 | return new OperationResult(false, reference, default); 166 | } 167 | } 168 | 169 | public static async UniTask ActivateSceneAsync(SceneInstance scene, int priority) 170 | { 171 | var operation = scene.ActivateAsync(); 172 | operation.priority = priority; 173 | 174 | await operation; 175 | } 176 | 177 | public static async UniTask> LoadSceneAsync(string key, 178 | LoadSceneMode loadMode = LoadSceneMode.Single, 179 | bool activateOnLoad = true, 180 | int priority = 100) 181 | { 182 | if (!GuardKey(key, out key)) 183 | { 184 | if (ExceptionHandle == ExceptionHandleType.Throw) 185 | throw new InvalidKeyException(key); 186 | 187 | if (ExceptionHandle == ExceptionHandleType.Log) 188 | Debug.LogException(new InvalidKeyException(key)); 189 | 190 | return new OperationResult(false, key, default); 191 | } 192 | 193 | if (_scenes.TryGetValue(key, out var scene)) 194 | { 195 | if (activateOnLoad ) 196 | await ActivateSceneAsync(scene, priority); 197 | 198 | return new OperationResult(true, key, in scene); 199 | } 200 | 201 | try 202 | { 203 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad , priority); 204 | await operation; 205 | 206 | OnLoadSceneCompleted(operation, key); 207 | return new OperationResult(key, operation); 208 | } 209 | catch (Exception ex) 210 | { 211 | if (ExceptionHandle == ExceptionHandleType.Throw) 212 | throw ex; 213 | 214 | if (ExceptionHandle == ExceptionHandleType.Log) 215 | Debug.LogException(ex); 216 | 217 | return new OperationResult(false, key, default); 218 | } 219 | } 220 | 221 | public static async UniTask> LoadSceneAsync(AssetReference reference, 222 | LoadSceneMode loadMode = LoadSceneMode.Single, 223 | bool activateOnLoad = true, 224 | int priority = 100) 225 | { 226 | if (!GuardKey(reference, out var key)) 227 | { 228 | if (ExceptionHandle == ExceptionHandleType.Throw) 229 | throw Exceptions.InvalidReference; 230 | 231 | if (ExceptionHandle == ExceptionHandleType.Log) 232 | Debug.LogException(new InvalidKeyException(key)); 233 | 234 | return new OperationResult(false, reference, default); 235 | } 236 | 237 | if (_scenes.TryGetValue(key, out var scene)) 238 | { 239 | if (activateOnLoad) 240 | await ActivateSceneAsync(scene, priority); 241 | 242 | return new OperationResult(true, reference, in scene); 243 | } 244 | 245 | try 246 | { 247 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 248 | await operation; 249 | 250 | OnLoadSceneCompleted(operation, key); 251 | return new OperationResult(reference, operation); 252 | } 253 | catch (Exception ex) 254 | { 255 | if (ExceptionHandle == ExceptionHandleType.Throw) 256 | throw ex; 257 | 258 | if (ExceptionHandle == ExceptionHandleType.Log) 259 | Debug.LogException(ex); 260 | 261 | return new OperationResult(false, reference, default); 262 | } 263 | } 264 | 265 | public static async UniTask> UnloadSceneAsync(string key, bool autoReleaseHandle = true) 266 | { 267 | if (!GuardKey(key, out key)) 268 | { 269 | if (ExceptionHandle == ExceptionHandleType.Throw) 270 | throw new InvalidKeyException(key); 271 | 272 | if (ExceptionHandle == ExceptionHandleType.Log) 273 | Debug.LogException(new InvalidKeyException(key)); 274 | 275 | return new OperationResult(false, key, default); 276 | } 277 | 278 | if (!_scenes.TryGetValue(key, out var scene)) 279 | { 280 | if (!SuppressWarningLogs) 281 | Debug.LogWarning(Exceptions.NoSceneKeyLoaded(key)); 282 | 283 | return new OperationResult(false, key, default); 284 | } 285 | 286 | _scenes.Remove(key); 287 | 288 | try 289 | { 290 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 291 | await operation; 292 | 293 | return new OperationResult(key, operation); 294 | } 295 | catch (Exception ex) 296 | { 297 | if (ExceptionHandle == ExceptionHandleType.Throw) 298 | throw ex; 299 | 300 | if (ExceptionHandle == ExceptionHandleType.Log) 301 | Debug.LogException(ex); 302 | 303 | return new OperationResult(false, key, in scene); 304 | } 305 | } 306 | 307 | public static async UniTask> UnloadSceneAsync(AssetReference reference) 308 | { 309 | if (!GuardKey(reference, out var key)) 310 | { 311 | if (ExceptionHandle == ExceptionHandleType.Throw) 312 | throw Exceptions.InvalidReference; 313 | 314 | if (ExceptionHandle == ExceptionHandleType.Log) 315 | Debug.LogException(new InvalidKeyException(key)); 316 | 317 | return new OperationResult(false, reference, default); 318 | } 319 | 320 | if (!_scenes.TryGetValue(key, out var scene)) 321 | { 322 | if (!SuppressWarningLogs) 323 | Debug.LogWarning(Exceptions.NoSceneReferenceLoaded(key)); 324 | 325 | return new OperationResult(false, reference, default); 326 | } 327 | 328 | _scenes.Remove(key); 329 | 330 | try 331 | { 332 | var operation = reference.UnLoadScene(); 333 | await operation; 334 | 335 | return new OperationResult(reference, operation); 336 | } 337 | catch (Exception ex) 338 | { 339 | if (ExceptionHandle == ExceptionHandleType.Throw) 340 | throw ex; 341 | 342 | if (ExceptionHandle == ExceptionHandleType.Log) 343 | Debug.LogException(ex); 344 | 345 | return new OperationResult(false, reference, scene); 346 | } 347 | } 348 | 349 | public static async UniTask> InstantiateAsync(string key, 350 | Transform parent = null, 351 | bool inWorldSpace = false, 352 | bool trackHandle = true) 353 | { 354 | if (!GuardKey(key, out key)) 355 | { 356 | if (ExceptionHandle == ExceptionHandleType.Throw) 357 | throw new InvalidKeyException(key); 358 | 359 | if (ExceptionHandle == ExceptionHandleType.Log) 360 | Debug.LogException(new InvalidKeyException(key)); 361 | 362 | return new OperationResult(false, key, default); 363 | } 364 | 365 | try 366 | { 367 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 368 | await operation; 369 | 370 | OnInstantiateCompleted(operation, key, false); 371 | return new OperationResult(key, operation); 372 | } 373 | catch (Exception ex) 374 | { 375 | if (ExceptionHandle == ExceptionHandleType.Throw) 376 | throw ex; 377 | 378 | if (ExceptionHandle == ExceptionHandleType.Log) 379 | Debug.LogException(ex); 380 | 381 | return new OperationResult(false, key, default); 382 | } 383 | } 384 | 385 | public static async UniTask> InstantiateAsync(AssetReference reference, 386 | Transform parent = null, 387 | bool inWorldSpace = false) 388 | { 389 | if (!GuardKey(reference, out var key)) 390 | { 391 | if (ExceptionHandle == ExceptionHandleType.Throw) 392 | throw Exceptions.InvalidReference; 393 | 394 | if (ExceptionHandle == ExceptionHandleType.Log) 395 | Debug.LogException(new InvalidKeyException(key)); 396 | 397 | return new OperationResult(false, reference, default); 398 | } 399 | 400 | try 401 | { 402 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 403 | await operation; 404 | 405 | OnInstantiateCompleted(operation, key, true); 406 | return new OperationResult(reference, operation); 407 | } 408 | catch (Exception ex) 409 | { 410 | if (ExceptionHandle == ExceptionHandleType.Throw) 411 | throw ex; 412 | 413 | if (ExceptionHandle == ExceptionHandleType.Log) 414 | Debug.LogException(ex); 415 | 416 | return new OperationResult(false, reference, default); 417 | } 418 | } 419 | } 420 | } 421 | 422 | #endif -------------------------------------------------------------------------------- /AddressablesManager/AsyncUniTaskMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0562edfcc6803dd40bbaa696c3d4fa20 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/BaseMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine.SceneManagement; 3 | 4 | namespace UnityEngine.AddressableAssets 5 | { 6 | public static partial class AddressablesManager 7 | { 8 | public static void Initialize() 9 | { 10 | Clear(); 11 | 12 | try 13 | { 14 | var operation = Addressables.InitializeAsync(); 15 | operation.Completed += handle => OnInitializeCompleted(handle); 16 | } 17 | catch (Exception ex) 18 | { 19 | if (ExceptionHandle == ExceptionHandleType.Throw) 20 | throw ex; 21 | 22 | if (ExceptionHandle == ExceptionHandleType.Log) 23 | Debug.LogException(ex); 24 | } 25 | } 26 | 27 | public static void LoadLocations(object key) 28 | { 29 | if (key == null) 30 | { 31 | if (ExceptionHandle == ExceptionHandleType.Throw) 32 | throw new InvalidKeyException(key); 33 | 34 | if (ExceptionHandle == ExceptionHandleType.Log) 35 | Debug.LogException(new InvalidKeyException(key)); 36 | 37 | return; 38 | } 39 | 40 | try 41 | { 42 | var operation = Addressables.LoadResourceLocationsAsync(key); 43 | operation.Completed += handle => OnLoadLocationsCompleted(handle, key); 44 | } 45 | catch (Exception ex) 46 | { 47 | if (ExceptionHandle == ExceptionHandleType.Throw) 48 | throw ex; 49 | 50 | if (ExceptionHandle == ExceptionHandleType.Log) 51 | Debug.LogException(ex); 52 | } 53 | } 54 | 55 | public static void LoadAsset(string key) where T : Object 56 | { 57 | if (!GuardKey(key, out key)) 58 | { 59 | if (ExceptionHandle == ExceptionHandleType.Throw) 60 | throw new InvalidKeyException(key); 61 | 62 | if (ExceptionHandle == ExceptionHandleType.Log) 63 | Debug.LogException(new InvalidKeyException(key)); 64 | 65 | return; 66 | } 67 | 68 | if (_assets.ContainsKey(key)) 69 | { 70 | if (!(_assets[key] is T)) 71 | { 72 | if (!SuppressWarningLogs) 73 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 74 | } 75 | 76 | return; 77 | } 78 | 79 | try 80 | { 81 | var operation = Addressables.LoadAssetAsync(key); 82 | operation.Completed += handle => OnLoadAssetCompleted(handle, key, false); 83 | } 84 | catch (Exception ex) 85 | { 86 | if (ExceptionHandle == ExceptionHandleType.Throw) 87 | throw ex; 88 | 89 | if (ExceptionHandle == ExceptionHandleType.Log) 90 | Debug.LogException(ex); 91 | } 92 | } 93 | 94 | public static void LoadAsset(AssetReferenceT reference) where T : Object 95 | { 96 | if (!GuardKey(reference, out var key)) 97 | { 98 | if (ExceptionHandle == ExceptionHandleType.Throw) 99 | throw Exceptions.InvalidReference; 100 | 101 | if (ExceptionHandle == ExceptionHandleType.Log) 102 | Debug.LogException(new InvalidKeyException(key)); 103 | 104 | return; 105 | } 106 | 107 | if (_assets.ContainsKey(key)) 108 | { 109 | if (!(_assets[key] is T)) 110 | { 111 | if (!SuppressWarningLogs) 112 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 113 | } 114 | 115 | return; 116 | } 117 | 118 | try 119 | { 120 | var operation = reference.LoadAssetAsync(); 121 | operation.Completed += handle => OnLoadAssetCompleted(handle, key, true); 122 | } 123 | catch (Exception ex) 124 | { 125 | if (ExceptionHandle == ExceptionHandleType.Throw) 126 | throw ex; 127 | 128 | if (ExceptionHandle == ExceptionHandleType.Log) 129 | Debug.LogException(ex); 130 | } 131 | } 132 | 133 | public static void LoadScene(string key, 134 | LoadSceneMode loadMode = LoadSceneMode.Single, 135 | bool activateOnLoad = true, 136 | int priority = 100) 137 | { 138 | if (!GuardKey(key, out key)) 139 | { 140 | if (ExceptionHandle == ExceptionHandleType.Throw) 141 | throw new InvalidKeyException(key); 142 | 143 | if (ExceptionHandle == ExceptionHandleType.Log) 144 | Debug.LogException(new InvalidKeyException(key)); 145 | 146 | return; 147 | } 148 | 149 | if (_scenes.TryGetValue(key, out var scene)) 150 | { 151 | if (activateOnLoad) 152 | { 153 | var operation = scene.ActivateAsync(); 154 | operation.priority = priority; 155 | } 156 | 157 | return; 158 | } 159 | 160 | try 161 | { 162 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 163 | operation.Completed += handle => OnLoadSceneCompleted(handle, key); 164 | } 165 | catch (Exception ex) 166 | { 167 | if (ExceptionHandle == ExceptionHandleType.Throw) 168 | throw ex; 169 | 170 | if (ExceptionHandle == ExceptionHandleType.Log) 171 | Debug.LogException(ex); 172 | } 173 | } 174 | 175 | public static void LoadScene(AssetReference reference, 176 | LoadSceneMode loadMode = LoadSceneMode.Single, 177 | bool activateOnLoad = true, 178 | int priority = 100) 179 | { 180 | if (!GuardKey(reference, out var key)) 181 | { 182 | if (ExceptionHandle == ExceptionHandleType.Throw) 183 | throw Exceptions.InvalidReference; 184 | 185 | if (ExceptionHandle == ExceptionHandleType.Log) 186 | Debug.LogException(new InvalidKeyException(key)); 187 | 188 | return; 189 | } 190 | 191 | if (_scenes.TryGetValue(key, out var scene)) 192 | { 193 | if (activateOnLoad) 194 | { 195 | var operation = scene.ActivateAsync(); 196 | operation.priority = priority; 197 | } 198 | 199 | return; 200 | } 201 | 202 | try 203 | { 204 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 205 | operation.Completed += handle => OnLoadSceneCompleted(handle, key); 206 | } 207 | catch (Exception ex) 208 | { 209 | if (ExceptionHandle == ExceptionHandleType.Throw) 210 | throw ex; 211 | 212 | if (ExceptionHandle == ExceptionHandleType.Log) 213 | Debug.LogException(ex); 214 | } 215 | } 216 | 217 | 218 | public static void UnloadScene(string key, bool autoReleaseHandle = true) 219 | { 220 | if (!GuardKey(key, out key)) 221 | { 222 | if (ExceptionHandle == ExceptionHandleType.Throw) 223 | throw new InvalidKeyException(key); 224 | 225 | if (ExceptionHandle == ExceptionHandleType.Log) 226 | Debug.LogException(new InvalidKeyException(key)); 227 | 228 | return; 229 | } 230 | 231 | if (!_scenes.TryGetValue(key, out var scene)) 232 | { 233 | if (!SuppressWarningLogs) 234 | Debug.LogWarning(Exceptions.NoSceneKeyLoaded(key)); 235 | 236 | return; 237 | } 238 | 239 | _scenes.Remove(key); 240 | 241 | try 242 | { 243 | Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 244 | } 245 | catch (Exception ex) 246 | { 247 | if (ExceptionHandle == ExceptionHandleType.Throw) 248 | throw ex; 249 | 250 | if (ExceptionHandle == ExceptionHandleType.Log) 251 | Debug.LogException(ex); 252 | } 253 | } 254 | 255 | public static void UnloadScene(AssetReference reference) 256 | { 257 | if (!GuardKey(reference, out var key)) 258 | { 259 | if (ExceptionHandle == ExceptionHandleType.Throw) 260 | throw Exceptions.InvalidReference; 261 | 262 | if (ExceptionHandle == ExceptionHandleType.Log) 263 | Debug.LogException(new InvalidKeyException(key)); 264 | 265 | return; 266 | } 267 | 268 | if (!_scenes.ContainsKey(key)) 269 | { 270 | if (!SuppressWarningLogs) 271 | Debug.LogWarning(Exceptions.NoSceneReferenceLoaded(key)); 272 | 273 | return; 274 | } 275 | 276 | _scenes.Remove(key); 277 | 278 | try 279 | { 280 | reference.UnLoadScene(); 281 | } 282 | catch (Exception ex) 283 | { 284 | if (ExceptionHandle == ExceptionHandleType.Throw) 285 | throw ex; 286 | 287 | if (ExceptionHandle == ExceptionHandleType.Log) 288 | Debug.LogException(ex); 289 | } 290 | } 291 | 292 | public static void Instantiate(string key, 293 | Transform parent = null, 294 | bool inWorldSpace = false, 295 | bool trackHandle = true) 296 | { 297 | if (!GuardKey(key, out key)) 298 | { 299 | if (ExceptionHandle == ExceptionHandleType.Throw) 300 | throw new InvalidKeyException(key); 301 | 302 | if (ExceptionHandle == ExceptionHandleType.Log) 303 | Debug.LogException(new InvalidKeyException(key)); 304 | 305 | return; 306 | } 307 | 308 | try 309 | { 310 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 311 | operation.Completed += handle => OnInstantiateCompleted(handle, key, false); 312 | } 313 | catch (Exception ex) 314 | { 315 | if (ExceptionHandle == ExceptionHandleType.Throw) 316 | throw ex; 317 | 318 | if (ExceptionHandle == ExceptionHandleType.Log) 319 | Debug.LogException(ex); 320 | } 321 | } 322 | 323 | public static void Instantiate(AssetReference reference, 324 | Transform parent = null, 325 | bool inWorldSpace = false) 326 | { 327 | if (!GuardKey(reference, out var key)) 328 | { 329 | if (ExceptionHandle == ExceptionHandleType.Throw) 330 | throw Exceptions.InvalidReference; 331 | 332 | if (ExceptionHandle == ExceptionHandleType.Log) 333 | Debug.LogException(new InvalidKeyException(key)); 334 | 335 | return; 336 | } 337 | 338 | try 339 | { 340 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 341 | operation.Completed += handle => OnInstantiateCompleted(handle, key, true); 342 | } 343 | catch (Exception ex) 344 | { 345 | if (ExceptionHandle == ExceptionHandleType.Throw) 346 | throw ex; 347 | 348 | if (ExceptionHandle == ExceptionHandleType.Log) 349 | Debug.LogException(ex); 350 | } 351 | } 352 | } 353 | } -------------------------------------------------------------------------------- /AddressablesManager/BaseMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c86e13d14b178a9449a648edf144af9d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/CallbackMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine.ResourceManagement.ResourceProviders; 3 | using UnityEngine.SceneManagement; 4 | 5 | namespace UnityEngine.AddressableAssets 6 | { 7 | public static partial class AddressablesManager 8 | { 9 | public static void Initialize(Action onSucceeded, Action onFailed = null) 10 | { 11 | Clear(); 12 | 13 | try 14 | { 15 | var operation = Addressables.InitializeAsync(); 16 | operation.Completed += handle => OnInitializeCompleted(handle, onSucceeded, onFailed); 17 | } 18 | catch (Exception ex) 19 | { 20 | if (ExceptionHandle == ExceptionHandleType.Throw) 21 | throw ex; 22 | 23 | if (ExceptionHandle == ExceptionHandleType.Log) 24 | Debug.LogException(ex); 25 | 26 | onFailed?.Invoke(); 27 | } 28 | } 29 | 30 | public static void LoadLocations(object key, 31 | Action onSucceeded, 32 | Action onFailed = null) 33 | { 34 | if (key == null) 35 | { 36 | onFailed?.Invoke(key); 37 | return; 38 | } 39 | 40 | try 41 | { 42 | var operation = Addressables.LoadResourceLocationsAsync(key); 43 | operation.Completed += handle => OnLoadLocationsCompleted(handle, key, onSucceeded, onFailed); 44 | } 45 | catch (Exception ex) 46 | { 47 | if (ExceptionHandle == ExceptionHandleType.Throw) 48 | throw ex; 49 | 50 | if (ExceptionHandle == ExceptionHandleType.Log) 51 | Debug.LogException(ex); 52 | 53 | onFailed?.Invoke(key); 54 | } 55 | } 56 | 57 | public static void LoadAsset(string key, 58 | Action onSucceeded, 59 | Action onFailed = null) 60 | where T : Object 61 | { 62 | if (!GuardKey(key, out key)) 63 | { 64 | onFailed?.Invoke(key); 65 | return; 66 | } 67 | 68 | if (_assets.ContainsKey(key)) 69 | { 70 | if (_assets[key] is T asset) 71 | { 72 | onSucceeded?.Invoke(key, asset); 73 | return; 74 | } 75 | 76 | if (!SuppressWarningLogs) 77 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 78 | 79 | onFailed?.Invoke(key); 80 | return; 81 | } 82 | 83 | try 84 | { 85 | var operation = Addressables.LoadAssetAsync(key); 86 | operation.Completed += handle => OnLoadAssetCompleted(handle, key, false, onSucceeded, onFailed); 87 | } 88 | catch (Exception ex) 89 | { 90 | if (ExceptionHandle == ExceptionHandleType.Throw) 91 | throw ex; 92 | 93 | if (ExceptionHandle == ExceptionHandleType.Log) 94 | Debug.LogException(ex); 95 | 96 | onFailed?.Invoke(key); 97 | } 98 | } 99 | 100 | public static void LoadAsset(AssetReferenceT reference, 101 | Action onSucceeded, 102 | Action onFailed = null) 103 | where T : Object 104 | { 105 | if (!GuardKey(reference, out var key)) 106 | { 107 | onFailed?.Invoke(key); 108 | return; 109 | } 110 | 111 | if (_assets.ContainsKey(key)) 112 | { 113 | if (_assets[key] is T asset) 114 | { 115 | onSucceeded?.Invoke(key, asset); 116 | return; 117 | } 118 | 119 | 120 | if (!SuppressWarningLogs) 121 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 122 | 123 | onFailed?.Invoke(key); 124 | return; 125 | } 126 | 127 | try 128 | { 129 | var operation = reference.LoadAssetAsync(); 130 | operation.Completed += handle => OnLoadAssetCompleted(handle, key, true, onSucceeded, onFailed); 131 | } 132 | catch (Exception ex) 133 | { 134 | if (ExceptionHandle == ExceptionHandleType.Throw) 135 | throw ex; 136 | 137 | if (ExceptionHandle == ExceptionHandleType.Log) 138 | Debug.LogException(ex); 139 | 140 | onFailed?.Invoke(key); 141 | } 142 | } 143 | 144 | private static void ActivateScene(SceneInstance scene, int priority, Action onSucceeded) 145 | { 146 | var operation = scene.ActivateAsync(); 147 | operation.priority = priority; 148 | operation.completed += _ => onSucceeded?.Invoke(scene); 149 | } 150 | 151 | public static void LoadScene(string key, 152 | Action onSucceeded, 153 | Action onFailed = null, 154 | LoadSceneMode loadMode = LoadSceneMode.Single, 155 | bool activateOnLoad = true, 156 | int priority = 100) 157 | { 158 | if (!GuardKey(key, out key)) 159 | { 160 | onFailed?.Invoke(key); 161 | return; 162 | } 163 | 164 | if (_scenes.TryGetValue(key, out var scene)) 165 | { 166 | if (activateOnLoad) 167 | ActivateScene(scene, priority, onSucceeded); 168 | else 169 | onSucceeded?.Invoke(scene); 170 | 171 | return; 172 | } 173 | 174 | try 175 | { 176 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 177 | operation.Completed += handle => OnLoadSceneCompleted(handle, key, onSucceeded, onFailed); 178 | } 179 | catch (Exception ex) 180 | { 181 | if (ExceptionHandle == ExceptionHandleType.Throw) 182 | throw ex; 183 | 184 | if (ExceptionHandle == ExceptionHandleType.Log) 185 | Debug.LogException(ex); 186 | 187 | onFailed?.Invoke(key); 188 | } 189 | } 190 | 191 | public static void LoadScene(AssetReference reference, 192 | Action onSucceeded, 193 | Action onFailed = null, 194 | LoadSceneMode loadMode = LoadSceneMode.Single, 195 | bool activateOnLoad = true, 196 | int priority = 100) 197 | { 198 | if (!GuardKey(reference, out var key)) 199 | { 200 | onFailed?.Invoke(key); 201 | return; 202 | } 203 | 204 | if (_scenes.TryGetValue(key, out var scene)) 205 | { 206 | if (activateOnLoad) 207 | ActivateScene(scene, priority, onSucceeded); 208 | else 209 | onSucceeded?.Invoke(scene); 210 | 211 | return; 212 | } 213 | 214 | try 215 | { 216 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 217 | operation.Completed += handle => OnLoadSceneCompleted(handle, key, onSucceeded, onFailed); 218 | } 219 | catch (Exception ex) 220 | { 221 | if (ExceptionHandle == ExceptionHandleType.Throw) 222 | throw ex; 223 | 224 | if (ExceptionHandle == ExceptionHandleType.Log) 225 | Debug.LogException(ex); 226 | 227 | onFailed?.Invoke(key); 228 | } 229 | } 230 | 231 | public static void UnloadScene(string key, 232 | Action onSucceeded = null, 233 | Action onFailed = null, 234 | bool autoReleaseHandle = true) 235 | { 236 | if (!GuardKey(key, out key)) 237 | { 238 | onFailed?.Invoke(key); 239 | return; 240 | } 241 | 242 | if (!_scenes.TryGetValue(key, out var scene)) 243 | { 244 | onFailed?.Invoke(key); 245 | return; 246 | } 247 | 248 | _scenes.Remove(key); 249 | 250 | try 251 | { 252 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 253 | operation.Completed += handle => OnUnloadSceneCompleted(handle, key, onSucceeded, onFailed); 254 | } 255 | catch (Exception ex) 256 | { 257 | if (ExceptionHandle == ExceptionHandleType.Throw) 258 | throw ex; 259 | 260 | if (ExceptionHandle == ExceptionHandleType.Log) 261 | Debug.LogException(ex); 262 | 263 | onFailed?.Invoke(key); 264 | } 265 | } 266 | 267 | public static void UnloadScene(AssetReference reference, 268 | Action onSucceeded = null, 269 | Action onFailed = null) 270 | { 271 | if (!GuardKey(reference, out var key)) 272 | { 273 | onFailed?.Invoke(key); 274 | return; 275 | } 276 | 277 | if (!_scenes.ContainsKey(key)) 278 | { 279 | onFailed?.Invoke(key); 280 | return; 281 | } 282 | 283 | _scenes.Remove(key); 284 | 285 | try 286 | { 287 | var operation = reference.UnLoadScene(); 288 | operation.Completed += handle => OnUnloadSceneCompleted(handle, key, onSucceeded, onFailed); 289 | } 290 | catch (Exception ex) 291 | { 292 | if (ExceptionHandle == ExceptionHandleType.Throw) 293 | throw ex; 294 | 295 | if (ExceptionHandle == ExceptionHandleType.Log) 296 | Debug.LogException(ex); 297 | 298 | onFailed?.Invoke(key); 299 | } 300 | } 301 | 302 | public static void Instantiate(string key, 303 | Action onSucceeded, 304 | Action onFailed = null, 305 | Transform parent = null, 306 | bool inWorldSpace = false, 307 | bool trackHandle = true) 308 | { 309 | if (!GuardKey(key, out key)) 310 | { 311 | onFailed?.Invoke(key); 312 | return; 313 | } 314 | 315 | try 316 | { 317 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 318 | operation.Completed += handle => OnInstantiateCompleted(handle, key, false, onSucceeded, onFailed); 319 | } 320 | catch (Exception ex) 321 | { 322 | if (ExceptionHandle == ExceptionHandleType.Throw) 323 | throw ex; 324 | 325 | if (ExceptionHandle == ExceptionHandleType.Log) 326 | Debug.LogException(ex); 327 | 328 | onFailed?.Invoke(key); 329 | } 330 | } 331 | 332 | public static void Instantiate(AssetReference reference, 333 | Action onSucceeded, 334 | Action onFailed = null, 335 | Transform parent = null, 336 | bool inWorldSpace = false) 337 | { 338 | if (!GuardKey(reference, out var key)) 339 | { 340 | onFailed?.Invoke(key); 341 | return; 342 | } 343 | 344 | try 345 | { 346 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 347 | operation.Completed += handle => OnInstantiateCompleted(handle, key, true, onSucceeded, onFailed); 348 | } 349 | catch (Exception ex) 350 | { 351 | if (ExceptionHandle == ExceptionHandleType.Throw) 352 | throw ex; 353 | 354 | if (ExceptionHandle == ExceptionHandleType.Log) 355 | Debug.LogException(ex); 356 | 357 | onFailed?.Invoke(key); 358 | } 359 | } 360 | } 361 | } -------------------------------------------------------------------------------- /AddressablesManager/CallbackMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1484b9b8efea924478de13165d5d1a7b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/CoroutineMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEngine.ResourceManagement.ResourceProviders; 4 | using UnityEngine.SceneManagement; 5 | 6 | namespace UnityEngine.AddressableAssets 7 | { 8 | public static partial class AddressablesManager 9 | { 10 | public static IEnumerator InitializeCoroutine(Action onSucceeded = null, 11 | Action onFailed = null) 12 | { 13 | Clear(); 14 | 15 | var operation = Addressables.InitializeAsync(); 16 | operation.Completed += handle => OnInitializeCompleted(handle, onSucceeded, onFailed); 17 | 18 | yield return operation; 19 | } 20 | 21 | public static IEnumerator LoadLocationsCoroutine(object key, 22 | Action onSucceeded = null, Action onFailed = null) 23 | { 24 | if (key == null) 25 | { 26 | onFailed?.Invoke(key); 27 | } 28 | else 29 | { 30 | var operation = Addressables.LoadResourceLocationsAsync(key); 31 | yield return operation; 32 | 33 | OnLoadLocationsCompleted(operation, key, onSucceeded, onFailed); 34 | } 35 | } 36 | 37 | public static IEnumerator LoadAssetCoroutine(string key, 38 | Action onSucceeded = null, 39 | Action onFailed = null) 40 | where T : Object 41 | { 42 | if (!GuardKey(key, out key)) 43 | { 44 | onFailed?.Invoke(key); 45 | } 46 | else 47 | { 48 | if (!_assets.ContainsKey(key)) 49 | { 50 | var operation = Addressables.LoadAssetAsync(key); 51 | yield return operation; 52 | 53 | OnLoadAssetCompleted(operation, key, false, onSucceeded, onFailed); 54 | } 55 | else if (_assets[key] is T asset) 56 | { 57 | onSucceeded?.Invoke(key, asset); 58 | } 59 | else 60 | { 61 | if (!SuppressWarningLogs) 62 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 63 | 64 | onFailed?.Invoke(key); 65 | } 66 | } 67 | } 68 | 69 | public static IEnumerator LoadAssetCoroutine(AssetReferenceT reference, 70 | Action onSucceeded = null, 71 | Action onFailed = null) 72 | where T : Object 73 | { 74 | if (!GuardKey(reference, out var key)) 75 | { 76 | onFailed?.Invoke(key); 77 | } 78 | else 79 | { 80 | if (!_assets.ContainsKey(key)) 81 | { 82 | var operation = reference.LoadAssetAsync(); 83 | yield return operation; 84 | 85 | OnLoadAssetCompleted(operation, key, true, onSucceeded, onFailed); 86 | } 87 | else if (_assets[key] is T asset) 88 | { 89 | onSucceeded?.Invoke(key, asset); 90 | } 91 | else 92 | { 93 | if (!SuppressWarningLogs) 94 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 95 | 96 | onFailed?.Invoke(key); 97 | } 98 | } 99 | } 100 | 101 | private static IEnumerator ActivateSceneCoroutine(SceneInstance instance, int priority) 102 | { 103 | var operation = instance.ActivateAsync(); 104 | operation.priority = priority; 105 | 106 | yield return operation; 107 | } 108 | 109 | public static IEnumerator LoadSceneCoroutine(string key, 110 | LoadSceneMode loadMode = LoadSceneMode.Single, 111 | bool activateOnLoad = true, 112 | int priority = 100, 113 | Action onSucceeded = null, 114 | Action onFailed = null) 115 | { 116 | if (!GuardKey(key, out key)) 117 | { 118 | onFailed?.Invoke(key); 119 | } 120 | else 121 | { 122 | if (_scenes.TryGetValue(key, out var scene)) 123 | { 124 | if (activateOnLoad) 125 | { 126 | yield return ActivateSceneCoroutine(scene, priority); 127 | } 128 | 129 | onSucceeded?.Invoke(scene); 130 | } 131 | else 132 | { 133 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 134 | yield return operation; 135 | 136 | OnLoadSceneCompleted(operation, key, onSucceeded, onFailed); 137 | } 138 | } 139 | } 140 | 141 | public static IEnumerator LoadSceneCoroutine(AssetReference reference, 142 | LoadSceneMode loadMode = LoadSceneMode.Single, 143 | bool activateOnLoad = true, 144 | int priority = 100, 145 | Action onSucceeded = null, 146 | Action onFailed = null) 147 | { 148 | if (!GuardKey(reference, out var key)) 149 | { 150 | onFailed?.Invoke(string.Empty); 151 | } 152 | else 153 | { 154 | if (_scenes.TryGetValue(key, out var scene)) 155 | { 156 | if (activateOnLoad) 157 | { 158 | yield return ActivateSceneCoroutine(scene, priority); 159 | } 160 | 161 | onSucceeded?.Invoke(scene); 162 | } 163 | else 164 | { 165 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 166 | yield return operation; 167 | 168 | OnLoadSceneCompleted(operation, key, onSucceeded, onFailed); 169 | } 170 | } 171 | } 172 | 173 | public static IEnumerator UnloadSceneCoroutine(string key, 174 | bool autoReleaseHandle = true, 175 | Action onSucceeded = null, 176 | Action onFailed = null) 177 | { 178 | if (!GuardKey(key, out key)) 179 | { 180 | onFailed?.Invoke(key); 181 | } 182 | else 183 | { 184 | if (!_scenes.TryGetValue(key, out var scene)) 185 | { 186 | onFailed?.Invoke(key); 187 | } 188 | else 189 | { 190 | _scenes.Remove(key); 191 | 192 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 193 | yield return operation; 194 | 195 | OnUnloadSceneCompleted(operation, key, onSucceeded, onFailed); 196 | } 197 | } 198 | } 199 | 200 | public static IEnumerator UnloadSceneCoroutine(AssetReference reference, 201 | Action onSucceeded = null, 202 | Action onFailed = null) 203 | { 204 | if (!GuardKey(reference, out var key)) 205 | { 206 | onFailed?.Invoke(string.Empty); 207 | } 208 | else 209 | { 210 | if (!_scenes.ContainsKey(key)) 211 | { 212 | onFailed?.Invoke(key); 213 | } 214 | else 215 | { 216 | _scenes.Remove(key); 217 | 218 | var operation = reference.UnLoadScene(); 219 | yield return operation; 220 | 221 | OnUnloadSceneCompleted(operation, key, onSucceeded, onFailed); 222 | } 223 | } 224 | } 225 | 226 | public static IEnumerator InstantiateCoroutine(string key, 227 | Transform parent = null, 228 | bool inWorldSpace = false, 229 | bool trackHandle = true, 230 | Action onSucceeded = null, 231 | Action onFailed = null) 232 | { 233 | if (!GuardKey(key, out key)) 234 | { 235 | onFailed?.Invoke(key); 236 | } 237 | else 238 | { 239 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 240 | yield return operation; 241 | 242 | OnInstantiateCompleted(operation, key, false, onSucceeded, onFailed); 243 | } 244 | } 245 | 246 | public static IEnumerator InstantiateCoroutine(AssetReference reference, 247 | Transform parent = null, 248 | bool inWorldSpace = false, 249 | Action onSucceeded = null, 250 | Action onFailed = null) 251 | { 252 | if (!GuardKey(reference, out var key)) 253 | { 254 | onFailed?.Invoke(string.Empty); 255 | } 256 | else 257 | { 258 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 259 | yield return operation; 260 | 261 | OnInstantiateCompleted(operation, key, true, onSucceeded, onFailed); 262 | } 263 | } 264 | } 265 | } -------------------------------------------------------------------------------- /AddressablesManager/CoroutineMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0aecac96ee638fc4db5c7f3239374785 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityEngine.AddressableAssets 4 | { 5 | internal static class Exceptions 6 | { 7 | private const string _cannotFindAssetByKey = "Cannot find any asset by key={0}."; 8 | private const string _noInstanceKeyInitialized = "No instance with key={0} has been instantiated through AddressablesManager."; 9 | private const string _noInstanceReferenceInitialized = "No instance with key={0} has been instantiated through AddressablesManager."; 10 | private const string _assetKeyNotInstanceOf = "The asset with key={0} is not an instance of {1}."; 11 | private const string _assetReferenceNotInstanceOf = "The asset with reference={0} is not an instance of {1}."; 12 | private const string _noSceneKeyLoaded = "No scene with key={0} has been loaded through AddressablesManager."; 13 | private const string _noSceneReferenceLoaded = "No scene with reference={0} has been loaded through AddressablesManager."; 14 | private const string _cannotLoadAssetKey = "Cannot load any asset of type={0} by key={1}."; 15 | private const string _cannotLoadAssetReference = "Cannot load any asset of type={0} by reference={1}."; 16 | private const string _assetKeyExist = "An asset of type={0} has been already registered with key={1}."; 17 | private const string _assetReferenceExist = "An asset of type={0} has been already registered with reference={1}."; 18 | private const string _cannotInstantiateKey = "Cannot instantiate key={0}."; 19 | private const string _cannotInstantiateReference = "Cannot instantiate reference={0}."; 20 | 21 | public static readonly InvalidKeyException InvalidReference = new InvalidKeyException("Reference is invalid."); 22 | 23 | public static string CannotFindAssetByKey(string key) 24 | => string.Format(_cannotFindAssetByKey, key); 25 | 26 | public static string NoInstanceKeyInitialized(string key) 27 | => string.Format(_noInstanceKeyInitialized, key); 28 | 29 | public static string NoInstanceReferenceInitialized(string key) 30 | => string.Format(_noInstanceReferenceInitialized, key); 31 | 32 | public static string AssetKeyNotInstanceOf(string key) 33 | => string.Format(_assetKeyNotInstanceOf, key, typeof(T)); 34 | 35 | public static string AssetReferenceNotInstanceOf(string key) 36 | => string.Format(_assetReferenceNotInstanceOf, key, typeof(T)); 37 | 38 | public static string NoSceneKeyLoaded(string key) 39 | => string.Format(_noSceneKeyLoaded, key); 40 | 41 | public static string NoSceneReferenceLoaded(string key) 42 | => string.Format(_noSceneReferenceLoaded, key); 43 | 44 | public static string CannotLoadAssetKey(string key) 45 | => string.Format(_cannotLoadAssetKey, typeof(T), key); 46 | 47 | public static string CannotLoadAssetReference(string key) 48 | => string.Format(_cannotLoadAssetReference, typeof(T), key); 49 | 50 | public static string AssetKeyExist(Type type, string key) 51 | => string.Format(_assetKeyExist, type, key); 52 | 53 | public static string AssetReferenceExist(Type type, string key) 54 | => string.Format(_assetReferenceExist, type, key); 55 | 56 | public static string CannotInstantiateKey(string key) 57 | => string.Format(_cannotInstantiateKey, key); 58 | 59 | public static string CannotInstantiateReference(string key) 60 | => string.Format(_cannotInstantiateReference, key); 61 | } 62 | } -------------------------------------------------------------------------------- /AddressablesManager/Exceptions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c3f7cf50f37c8141830fe0d41c2ff61 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/OnCompletedMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace UnityEngine.AddressableAssets 5 | { 6 | using ResourceManagement.AsyncOperations; 7 | using ResourceManagement.ResourceProviders; 8 | using ResourceManagement.ResourceLocations; 9 | using ResourceLocators; 10 | 11 | public static partial class AddressablesManager 12 | { 13 | private static void OnInitializeCompleted(AsyncOperationHandle handle, 14 | Action onSucceeded = null, 15 | Action onFailed = null) 16 | { 17 | if (handle.Status != AsyncOperationStatus.Succeeded) 18 | { 19 | onFailed?.Invoke(); 20 | return; 21 | } 22 | 23 | _keys.AddRange(handle.Result.Keys); 24 | onSucceeded?.Invoke(); 25 | } 26 | 27 | private static void OnLoadLocationsCompleted(AsyncOperationHandle> handle, 28 | object key, 29 | Action onSucceeded = null, 30 | Action onFailed = null) 31 | { 32 | if (handle.Status != AsyncOperationStatus.Succeeded) 33 | { 34 | onFailed?.Invoke(key); 35 | return; 36 | } 37 | 38 | var succeeded = false; 39 | 40 | foreach (var location in handle.Result) 41 | { 42 | var primaryKey = location.PrimaryKey; 43 | 44 | if (!GuardKey(primaryKey, out primaryKey)) 45 | continue; 46 | 47 | if (!_locations.ContainsKey(primaryKey)) 48 | _locations.Add(primaryKey, new List()); 49 | 50 | var list = _locations[primaryKey]; 51 | var index = list.FindIndex(x => string.Equals(x.InternalId, location.InternalId)); 52 | 53 | if (index < 0) 54 | { 55 | list.Add(location); 56 | succeeded = true; 57 | } 58 | } 59 | 60 | if (succeeded) 61 | onSucceeded?.Invoke(key); 62 | } 63 | 64 | private static void OnLoadAssetCompleted(AsyncOperationHandle handle, 65 | string key, 66 | bool useReference, 67 | Action onSucceeded = null, 68 | Action onFailed = null) 69 | where T : Object 70 | { 71 | if (handle.Status != AsyncOperationStatus.Succeeded) 72 | { 73 | onFailed?.Invoke(key); 74 | return; 75 | } 76 | 77 | if (!handle.Result) 78 | { 79 | if (!SuppressErrorLogs) 80 | Debug.LogError(useReference ? Exceptions.CannotLoadAssetReference(key) : Exceptions.CannotLoadAssetKey(key)); 81 | 82 | onFailed?.Invoke(key); 83 | return; 84 | } 85 | 86 | if (_assets.ContainsKey(key)) 87 | { 88 | if (!(_assets[key] is T)) 89 | { 90 | if (!SuppressErrorLogs) 91 | { 92 | if (useReference) 93 | Debug.LogError(Exceptions.AssetReferenceExist(_assets[key].GetType(), key)); 94 | else 95 | Debug.LogError(Exceptions.AssetKeyExist(_assets[key].GetType(), key)); 96 | } 97 | 98 | onFailed?.Invoke(key); 99 | return; 100 | } 101 | } 102 | else 103 | { 104 | _assets.Add(key, handle.Result); 105 | } 106 | 107 | onSucceeded?.Invoke(key, handle.Result); 108 | } 109 | 110 | private static void OnInstantiateCompleted(AsyncOperationHandle handle, 111 | string key, 112 | bool useReference, 113 | Action onSucceeded = null, 114 | Action onFailed = null) 115 | { 116 | if (handle.Status != AsyncOperationStatus.Succeeded) 117 | { 118 | onFailed?.Invoke(key); 119 | return; 120 | } 121 | 122 | if (!handle.Result) 123 | { 124 | if (!SuppressErrorLogs) 125 | { 126 | if (useReference) 127 | Debug.LogError(Exceptions.CannotInstantiateReference(key)); 128 | else 129 | Debug.LogError(Exceptions.CannotInstantiateKey(key)); 130 | } 131 | 132 | onFailed?.Invoke(key); 133 | return; 134 | } 135 | 136 | if (!_instances.ContainsKey(key)) 137 | _instances.Add(key, GetInstanceList()); 138 | 139 | _instances[key].Add(handle.Result); 140 | onSucceeded?.Invoke(key, handle.Result); 141 | } 142 | 143 | private static void OnLoadSceneCompleted(AsyncOperationHandle handle, 144 | string key, 145 | Action onSucceeded = null, 146 | Action onFailed = null) 147 | { 148 | if (handle.Status == AsyncOperationStatus.Succeeded) 149 | { 150 | _scenes.Add(key, handle.Result); 151 | onSucceeded?.Invoke(handle.Result); 152 | } 153 | else if (handle.Status == AsyncOperationStatus.Failed) 154 | { 155 | onFailed?.Invoke(key); 156 | } 157 | } 158 | 159 | private static void OnUnloadSceneCompleted(AsyncOperationHandle handle, 160 | string key, 161 | Action onSucceeded, 162 | Action onFailed) 163 | { 164 | if (handle.Status == AsyncOperationStatus.Succeeded) 165 | { 166 | onSucceeded?.Invoke(key); 167 | } 168 | else if (handle.Status == AsyncOperationStatus.Failed) 169 | { 170 | onFailed?.Invoke(key); 171 | } 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /AddressablesManager/OnCompletedMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bff142f6bf36fa948a85f8a5607c7387 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/OperationResult.cs: -------------------------------------------------------------------------------- 1 | namespace UnityEngine.AddressableAssets 2 | { 3 | using ResourceManagement.AsyncOperations; 4 | 5 | public readonly struct OperationResult 6 | { 7 | public readonly bool Succeeded; 8 | public readonly object Key; 9 | public readonly T Value; 10 | 11 | public OperationResult(bool succeeded, object key, T value) 12 | { 13 | this.Succeeded = succeeded; 14 | this.Key = key; 15 | this.Value = value; 16 | } 17 | 18 | public OperationResult(bool succeeded, object key, in T value) 19 | { 20 | this.Succeeded = succeeded; 21 | this.Key = key; 22 | this.Value = value; 23 | } 24 | 25 | public OperationResult(in AsyncOperationHandle handle) : this() 26 | { 27 | this.Succeeded = handle.Status == AsyncOperationStatus.Succeeded; 28 | this.Value = handle.Result; 29 | } 30 | 31 | public OperationResult(object key, in AsyncOperationHandle handle) 32 | { 33 | this.Succeeded = handle.Status == AsyncOperationStatus.Succeeded; 34 | this.Key = key; 35 | this.Value = handle.Result; 36 | } 37 | 38 | public void Deconstruct(out bool succeeded, out T value) 39 | { 40 | succeeded = this.Succeeded; 41 | value = this.Value; 42 | } 43 | 44 | public void Deconstruct(out bool succeeded, out object key, out T value) 45 | { 46 | succeeded = this.Succeeded; 47 | key = this.Key; 48 | value = this.Value; 49 | } 50 | 51 | public static implicit operator T(in OperationResult result) 52 | => result.Value; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /AddressablesManager/OperationResult.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdbc1a2309e9d714e98d2707c5f3d609 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /AddressablesManager/SyncMethods.cs: -------------------------------------------------------------------------------- 1 | #if ADDRESSABLES_1_17 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using UnityEngine.SceneManagement; 6 | using UnityEngine.ResourceManagement.ResourceLocations; 7 | 8 | namespace UnityEngine.AddressableAssets 9 | { 10 | using ResourceManagement.ResourceProviders; 11 | using AddressableAssets.ResourceLocators; 12 | 13 | public static partial class AddressablesManager 14 | { 15 | public static IResourceLocator InitializeSync() 16 | { 17 | Clear(); 18 | 19 | try 20 | { 21 | var operation = Addressables.InitializeAsync(); 22 | var result = operation.WaitForCompletion(); 23 | OnInitializeCompleted(operation); 24 | 25 | return result; 26 | } 27 | catch (Exception ex) 28 | { 29 | if (ExceptionHandle == ExceptionHandleType.Throw) 30 | throw ex; 31 | 32 | if (ExceptionHandle == ExceptionHandleType.Log) 33 | Debug.LogException(ex); 34 | 35 | return default; 36 | } 37 | } 38 | 39 | public static bool TryInitializeSync(out IResourceLocator result) 40 | { 41 | Clear(); 42 | 43 | try 44 | { 45 | var operation = Addressables.InitializeAsync(); 46 | result = operation.WaitForCompletion(); 47 | OnInitializeCompleted(operation); 48 | 49 | return result != null; 50 | } 51 | catch (Exception ex) 52 | { 53 | if (ExceptionHandle == ExceptionHandleType.Throw) 54 | throw ex; 55 | 56 | if (ExceptionHandle == ExceptionHandleType.Log) 57 | Debug.LogException(ex); 58 | 59 | result = default; 60 | return false; 61 | } 62 | } 63 | 64 | public static bool TryInitializeSync() 65 | { 66 | Clear(); 67 | 68 | try 69 | { 70 | var operation = Addressables.InitializeAsync(); 71 | operation.WaitForCompletion(); 72 | OnInitializeCompleted(operation); 73 | 74 | return true; 75 | } 76 | catch (Exception ex) 77 | { 78 | if (ExceptionHandle == ExceptionHandleType.Throw) 79 | throw ex; 80 | 81 | if (ExceptionHandle == ExceptionHandleType.Log) 82 | Debug.LogException(ex); 83 | 84 | return false; 85 | } 86 | } 87 | 88 | public static IList LoadLocationsSync(object key) 89 | { 90 | if (key == null) 91 | throw new ArgumentNullException(nameof(key)); 92 | 93 | try 94 | { 95 | var operation = Addressables.LoadResourceLocationsAsync(key); 96 | var result = operation.WaitForCompletion(); 97 | OnLoadLocationsCompleted(operation, key); 98 | 99 | return result; 100 | } 101 | catch (Exception ex) 102 | { 103 | if (ExceptionHandle == ExceptionHandleType.Throw) 104 | throw ex; 105 | 106 | if (ExceptionHandle == ExceptionHandleType.Log) 107 | Debug.LogException(ex); 108 | 109 | return default; 110 | } 111 | } 112 | 113 | public static bool TryLoadLocationsSync(object key, out IList result) 114 | { 115 | if (key == null) 116 | { 117 | if (ExceptionHandle == ExceptionHandleType.Throw) 118 | throw new InvalidKeyException(key); 119 | 120 | if (ExceptionHandle == ExceptionHandleType.Log) 121 | Debug.LogException(new InvalidKeyException(key)); 122 | 123 | result = default; 124 | return false; 125 | } 126 | 127 | try 128 | { 129 | var operation = Addressables.LoadResourceLocationsAsync(key); 130 | result = operation.WaitForCompletion(); 131 | OnLoadLocationsCompleted(operation, key); 132 | 133 | return result != null; 134 | } 135 | catch (Exception ex) 136 | { 137 | if (ExceptionHandle == ExceptionHandleType.Throw) 138 | throw ex; 139 | 140 | if (ExceptionHandle == ExceptionHandleType.Log) 141 | Debug.LogException(ex); 142 | 143 | result = default; 144 | return false; 145 | } 146 | } 147 | 148 | public static T LoadAssetSync(string key) where T : Object 149 | { 150 | if (!GuardKey(key, out key)) 151 | { 152 | if (ExceptionHandle == ExceptionHandleType.Throw) 153 | throw new InvalidKeyException(key); 154 | 155 | if (ExceptionHandle == ExceptionHandleType.Log) 156 | Debug.LogException(new InvalidKeyException(key)); 157 | 158 | return default; 159 | } 160 | 161 | if (_assets.ContainsKey(key)) 162 | { 163 | if (_assets[key] is T assetT) 164 | return assetT; 165 | 166 | 167 | if (!SuppressWarningLogs) 168 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 169 | 170 | return default; 171 | } 172 | 173 | try 174 | { 175 | var operation = Addressables.LoadAssetAsync(key); 176 | var result = operation.WaitForCompletion(); 177 | OnLoadAssetCompleted(operation, key, false); 178 | 179 | return result; 180 | } 181 | catch (Exception ex) 182 | { 183 | if (ExceptionHandle == ExceptionHandleType.Throw) 184 | throw ex; 185 | 186 | if (ExceptionHandle == ExceptionHandleType.Log) 187 | Debug.LogException(ex); 188 | 189 | return default; 190 | } 191 | } 192 | 193 | public static bool TryLoadAssetSync(string key, out T result) where T : Object 194 | { 195 | if (!GuardKey(key, out key)) 196 | { 197 | if (ExceptionHandle == ExceptionHandleType.Throw) 198 | throw new InvalidKeyException(key); 199 | 200 | if (ExceptionHandle == ExceptionHandleType.Log) 201 | Debug.LogException(new InvalidKeyException(key)); 202 | 203 | result = default; 204 | return false; 205 | } 206 | 207 | if (_assets.ContainsKey(key)) 208 | { 209 | if (_assets[key] is T assetT) 210 | { 211 | result = assetT; 212 | return true; 213 | } 214 | 215 | 216 | if (!SuppressWarningLogs) 217 | Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf(key)); 218 | 219 | result = default; 220 | return false; 221 | } 222 | 223 | try 224 | { 225 | var operation = Addressables.LoadAssetAsync(key); 226 | result = operation.WaitForCompletion(); 227 | OnLoadAssetCompleted(operation, key, false); 228 | 229 | return result; 230 | } 231 | catch (Exception ex) 232 | { 233 | if (ExceptionHandle == ExceptionHandleType.Throw) 234 | throw ex; 235 | 236 | if (ExceptionHandle == ExceptionHandleType.Log) 237 | Debug.LogException(ex); 238 | 239 | result = default; 240 | return false; 241 | } 242 | } 243 | 244 | public static T LoadAssetSync(AssetReferenceT reference) where T : Object 245 | { 246 | if (!GuardKey(reference, out var key)) 247 | { 248 | if (ExceptionHandle == ExceptionHandleType.Throw) 249 | throw Exceptions.InvalidReference; 250 | 251 | if (ExceptionHandle == ExceptionHandleType.Log) 252 | Debug.LogException(new InvalidKeyException(key)); 253 | 254 | return default; 255 | } 256 | 257 | if (_assets.ContainsKey(key)) 258 | { 259 | if (_assets[key] is T assetT) 260 | return assetT; 261 | 262 | 263 | if (!SuppressWarningLogs) 264 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 265 | 266 | return default; 267 | } 268 | 269 | try 270 | { 271 | var operation = reference.LoadAssetAsync(); 272 | var result = operation.WaitForCompletion(); 273 | OnLoadAssetCompleted(operation, key, true); 274 | 275 | return result; 276 | } 277 | catch (Exception ex) 278 | { 279 | if (ExceptionHandle == ExceptionHandleType.Throw) 280 | throw ex; 281 | 282 | if (ExceptionHandle == ExceptionHandleType.Log) 283 | Debug.LogException(ex); 284 | 285 | return default; 286 | } 287 | } 288 | 289 | public static bool TryLoadAssetSync(AssetReferenceT reference, out T result) where T : Object 290 | { 291 | if (!GuardKey(reference, out var key)) 292 | { 293 | if (ExceptionHandle == ExceptionHandleType.Throw) 294 | throw Exceptions.InvalidReference; 295 | 296 | if (ExceptionHandle == ExceptionHandleType.Log) 297 | Debug.LogException(new InvalidKeyException(key)); 298 | 299 | result = default; 300 | return false; 301 | } 302 | 303 | if (_assets.ContainsKey(key)) 304 | { 305 | if (_assets[key] is T assetT) 306 | { 307 | result = assetT; 308 | return true; 309 | } 310 | 311 | if (!SuppressWarningLogs) 312 | Debug.LogWarning(Exceptions.AssetReferenceNotInstanceOf(key)); 313 | 314 | result = default; 315 | return false; 316 | } 317 | 318 | try 319 | { 320 | var operation = reference.LoadAssetAsync(); 321 | result = operation.WaitForCompletion(); 322 | OnLoadAssetCompleted(operation, key, true); 323 | 324 | return result; 325 | } 326 | catch (Exception ex) 327 | { 328 | if (ExceptionHandle == ExceptionHandleType.Throw) 329 | throw ex; 330 | 331 | if (ExceptionHandle == ExceptionHandleType.Log) 332 | Debug.LogException(ex); 333 | 334 | result = default; 335 | return false; 336 | } 337 | } 338 | 339 | private static void ActivateSceneSync(in SceneInstance instance, int priority) 340 | { 341 | var operation = instance.ActivateAsync(); 342 | operation.priority = priority; 343 | operation.WaitForCompletion(); 344 | } 345 | 346 | public static SceneInstance LoadSceneSync(string key, 347 | LoadSceneMode loadMode = LoadSceneMode.Single, 348 | bool activateOnLoad = true, 349 | int priority = 100) 350 | { 351 | if (!GuardKey(key, out key)) 352 | { 353 | if (ExceptionHandle == ExceptionHandleType.Throw) 354 | throw new InvalidKeyException(key); 355 | 356 | if (ExceptionHandle == ExceptionHandleType.Log) 357 | Debug.LogException(new InvalidKeyException(key)); 358 | 359 | return default; 360 | } 361 | 362 | if (_scenes.TryGetValue(key, out var scene)) 363 | { 364 | if (activateOnLoad) 365 | ActivateSceneSync(scene, priority); 366 | 367 | return scene; 368 | } 369 | 370 | try 371 | { 372 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 373 | var result = operation.WaitForCompletion(); 374 | OnLoadSceneCompleted(operation, key); 375 | 376 | return result; 377 | } 378 | catch (Exception ex) 379 | { 380 | if (ExceptionHandle == ExceptionHandleType.Throw) 381 | throw ex; 382 | 383 | if (ExceptionHandle == ExceptionHandleType.Log) 384 | Debug.LogException(ex); 385 | 386 | return default; 387 | } 388 | } 389 | 390 | public static bool TryLoadSceneSync(string key, out SceneInstance result, 391 | LoadSceneMode loadMode = LoadSceneMode.Single, 392 | bool activateOnLoad = true, 393 | int priority = 100) 394 | { 395 | if (!GuardKey(key, out key)) 396 | { 397 | if (ExceptionHandle == ExceptionHandleType.Throw) 398 | throw new InvalidKeyException(key); 399 | 400 | if (ExceptionHandle == ExceptionHandleType.Log) 401 | Debug.LogException(new InvalidKeyException(key)); 402 | 403 | result = default; 404 | return false; 405 | } 406 | 407 | if (_scenes.TryGetValue(key, out var scene)) 408 | { 409 | if (activateOnLoad) 410 | ActivateSceneSync(scene, priority); 411 | 412 | result = scene; 413 | return true; 414 | } 415 | 416 | try 417 | { 418 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 419 | result = operation.WaitForCompletion(); 420 | OnLoadSceneCompleted(operation, key); 421 | 422 | return true; 423 | } 424 | catch (Exception ex) 425 | { 426 | if (ExceptionHandle == ExceptionHandleType.Throw) 427 | throw ex; 428 | 429 | if (ExceptionHandle == ExceptionHandleType.Log) 430 | Debug.LogException(ex); 431 | 432 | result = default; 433 | return false; 434 | } 435 | } 436 | 437 | public static SceneInstance LoadSceneSync(AssetReference reference, 438 | LoadSceneMode loadMode = LoadSceneMode.Single, 439 | bool activateOnLoad = true, 440 | int priority = 100) 441 | { 442 | if (!GuardKey(reference, out var key)) 443 | { 444 | if (ExceptionHandle == ExceptionHandleType.Throw) 445 | throw Exceptions.InvalidReference; 446 | 447 | if (ExceptionHandle == ExceptionHandleType.Log) 448 | Debug.LogException(new InvalidKeyException(key)); 449 | 450 | return default; 451 | } 452 | 453 | if (_scenes.TryGetValue(key, out var scene)) 454 | { 455 | if (activateOnLoad) 456 | ActivateSceneSync(scene, priority); 457 | 458 | return scene; 459 | } 460 | 461 | try 462 | { 463 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 464 | var result = operation.WaitForCompletion(); 465 | OnLoadSceneCompleted(operation, key); 466 | 467 | return result; 468 | } 469 | catch (Exception ex) 470 | { 471 | if (ExceptionHandle == ExceptionHandleType.Throw) 472 | throw ex; 473 | 474 | if (ExceptionHandle == ExceptionHandleType.Log) 475 | Debug.LogException(ex); 476 | 477 | return default; 478 | } 479 | } 480 | 481 | public static bool LoadSceneSync(AssetReference reference, out SceneInstance result, 482 | LoadSceneMode loadMode = LoadSceneMode.Single, 483 | bool activateOnLoad = true, 484 | int priority = 100) 485 | { 486 | if (!GuardKey(reference, out var key)) 487 | { 488 | if (ExceptionHandle == ExceptionHandleType.Throw) 489 | throw Exceptions.InvalidReference; 490 | 491 | if (ExceptionHandle == ExceptionHandleType.Log) 492 | Debug.LogException(new InvalidKeyException(key)); 493 | 494 | result = default; 495 | return false; 496 | } 497 | 498 | if (_scenes.TryGetValue(key, out var scene)) 499 | { 500 | if (activateOnLoad) 501 | ActivateSceneSync(scene, priority); 502 | 503 | result = scene; 504 | return true; 505 | } 506 | 507 | try 508 | { 509 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 510 | result = operation.WaitForCompletion(); 511 | OnLoadSceneCompleted(operation, key); 512 | 513 | return true; 514 | } 515 | catch (Exception ex) 516 | { 517 | if (ExceptionHandle == ExceptionHandleType.Throw) 518 | throw ex; 519 | 520 | if (ExceptionHandle == ExceptionHandleType.Log) 521 | Debug.LogException(ex); 522 | 523 | result = default; 524 | return false; 525 | } 526 | } 527 | 528 | [Obsolete] 529 | public static bool TryLoadSceneSync(string key, LoadSceneMode loadMode, out SceneInstance result, 530 | bool activateOnLoad = true, int priority = 100) 531 | { 532 | if (!GuardKey(key, out key)) 533 | { 534 | if (ExceptionHandle == ExceptionHandleType.Throw) 535 | throw new InvalidKeyException(key); 536 | 537 | if (ExceptionHandle == ExceptionHandleType.Log) 538 | Debug.LogException(new InvalidKeyException(key)); 539 | 540 | result = default; 541 | return false; 542 | } 543 | 544 | if (_scenes.TryGetValue(key, out var scene)) 545 | { 546 | if (activateOnLoad) 547 | ActivateSceneSync(scene, priority); 548 | 549 | result = scene; 550 | return true; 551 | } 552 | 553 | try 554 | { 555 | var operation = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); 556 | result = operation.WaitForCompletion(); 557 | OnLoadSceneCompleted(operation, key); 558 | 559 | return true; 560 | } 561 | catch (Exception ex) 562 | { 563 | if (ExceptionHandle == ExceptionHandleType.Throw) 564 | throw ex; 565 | 566 | if (ExceptionHandle == ExceptionHandleType.Log) 567 | Debug.LogException(ex); 568 | 569 | result = default; 570 | return false; 571 | } 572 | } 573 | 574 | [Obsolete] 575 | public static bool LoadSceneSync(AssetReference reference, LoadSceneMode loadMode, out SceneInstance result, 576 | bool activateOnLoad = true, int priority = 100) 577 | { 578 | if (!GuardKey(reference, out var key)) 579 | { 580 | if (ExceptionHandle == ExceptionHandleType.Throw) 581 | throw Exceptions.InvalidReference; 582 | 583 | if (ExceptionHandle == ExceptionHandleType.Log) 584 | Debug.LogException(new InvalidKeyException(key)); 585 | 586 | result = default; 587 | return false; 588 | } 589 | 590 | if (_scenes.TryGetValue(key, out var scene)) 591 | { 592 | if (activateOnLoad) 593 | ActivateSceneSync(scene, priority); 594 | 595 | result = scene; 596 | return true; 597 | } 598 | 599 | try 600 | { 601 | var operation = reference.LoadSceneAsync(loadMode, activateOnLoad, priority); 602 | result = operation.WaitForCompletion(); 603 | OnLoadSceneCompleted(operation, key); 604 | 605 | return true; 606 | } 607 | catch (Exception ex) 608 | { 609 | if (ExceptionHandle == ExceptionHandleType.Throw) 610 | throw ex; 611 | 612 | if (ExceptionHandle == ExceptionHandleType.Log) 613 | Debug.LogException(ex); 614 | 615 | result = default; 616 | return false; 617 | } 618 | } 619 | 620 | public static SceneInstance UnloadSceneSync(string key, bool autoReleaseHandle = true) 621 | { 622 | if (!GuardKey(key, out key)) 623 | { 624 | if (ExceptionHandle == ExceptionHandleType.Throw) 625 | throw new InvalidKeyException(key); 626 | 627 | if (ExceptionHandle == ExceptionHandleType.Log) 628 | Debug.LogException(new InvalidKeyException(key)); 629 | 630 | return default; 631 | } 632 | 633 | if (!_scenes.TryGetValue(key, out var scene)) 634 | { 635 | if (!SuppressWarningLogs) 636 | Debug.LogWarning(Exceptions.NoSceneKeyLoaded(key)); 637 | 638 | return default; 639 | } 640 | 641 | _scenes.Remove(key); 642 | 643 | try 644 | { 645 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 646 | var result = operation.WaitForCompletion(); 647 | return result; 648 | } 649 | catch (Exception ex) 650 | { 651 | if (ExceptionHandle == ExceptionHandleType.Throw) 652 | throw ex; 653 | 654 | if (ExceptionHandle == ExceptionHandleType.Log) 655 | Debug.LogException(ex); 656 | 657 | return scene; 658 | } 659 | } 660 | 661 | public static bool TryUnloadSceneSync(string key, out SceneInstance result, 662 | bool autoReleaseHandle = true) 663 | { 664 | if (!GuardKey(key, out key)) 665 | { 666 | if (ExceptionHandle == ExceptionHandleType.Throw) 667 | throw new InvalidKeyException(key); 668 | 669 | if (ExceptionHandle == ExceptionHandleType.Log) 670 | Debug.LogException(new InvalidKeyException(key)); 671 | 672 | result = default; 673 | return false; 674 | } 675 | 676 | if (!_scenes.TryGetValue(key, out var scene)) 677 | { 678 | if (!SuppressWarningLogs) 679 | Debug.LogWarning(Exceptions.NoSceneKeyLoaded(key)); 680 | 681 | result = default; 682 | return false; 683 | } 684 | 685 | _scenes.Remove(key); 686 | 687 | try 688 | { 689 | var operation = Addressables.UnloadSceneAsync(scene, autoReleaseHandle); 690 | result = operation.WaitForCompletion(); 691 | return true; 692 | } 693 | catch (Exception ex) 694 | { 695 | if (ExceptionHandle == ExceptionHandleType.Throw) 696 | throw ex; 697 | 698 | if (ExceptionHandle == ExceptionHandleType.Log) 699 | Debug.LogException(ex); 700 | 701 | result = scene; 702 | return false; 703 | } 704 | } 705 | 706 | public static SceneInstance UnloadSceneSync(AssetReference reference) 707 | { 708 | if (!GuardKey(reference, out var key)) 709 | { 710 | if (ExceptionHandle == ExceptionHandleType.Throw) 711 | throw Exceptions.InvalidReference; 712 | 713 | if (ExceptionHandle == ExceptionHandleType.Log) 714 | Debug.LogException(new InvalidKeyException(key)); 715 | 716 | return default; 717 | } 718 | 719 | if (!_scenes.TryGetValue(key, out var scene)) 720 | { 721 | if (!SuppressWarningLogs) 722 | Debug.LogWarning(Exceptions.NoSceneReferenceLoaded(key)); 723 | 724 | return default; 725 | } 726 | 727 | _scenes.Remove(key); 728 | 729 | try 730 | { 731 | var operation = reference.UnLoadScene(); 732 | var result = operation.WaitForCompletion(); 733 | return result; 734 | } 735 | catch (Exception ex) 736 | { 737 | if (ExceptionHandle == ExceptionHandleType.Throw) 738 | throw ex; 739 | 740 | if (ExceptionHandle == ExceptionHandleType.Log) 741 | Debug.LogException(ex); 742 | 743 | return scene; 744 | } 745 | } 746 | 747 | public static bool TryUnloadSceneSync(AssetReference reference, out SceneInstance result) 748 | { 749 | if (!GuardKey(reference, out var key)) 750 | { 751 | if (ExceptionHandle == ExceptionHandleType.Throw) 752 | throw Exceptions.InvalidReference; 753 | 754 | if (ExceptionHandle == ExceptionHandleType.Log) 755 | Debug.LogException(new InvalidKeyException(key)); 756 | 757 | result = default; 758 | return false; 759 | } 760 | 761 | if (!_scenes.TryGetValue(key, out var scene)) 762 | { 763 | if (!SuppressWarningLogs) 764 | Debug.LogWarning(Exceptions.NoSceneReferenceLoaded(key)); 765 | 766 | result = default; 767 | return false; 768 | } 769 | 770 | _scenes.Remove(key); 771 | 772 | try 773 | { 774 | var operation = reference.UnLoadScene(); 775 | result = operation.WaitForCompletion(); 776 | return true; 777 | } 778 | catch (Exception ex) 779 | { 780 | if (ExceptionHandle == ExceptionHandleType.Throw) 781 | throw ex; 782 | 783 | if (ExceptionHandle == ExceptionHandleType.Log) 784 | Debug.LogException(ex); 785 | 786 | result = scene; 787 | return false; 788 | } 789 | } 790 | 791 | public static GameObject InstantiateSync(string key, 792 | Transform parent = null, 793 | bool inWorldSpace = false, 794 | bool trackHandle = true) 795 | { 796 | if (!GuardKey(key, out key)) 797 | { 798 | if (ExceptionHandle == ExceptionHandleType.Throw) 799 | throw Exceptions.InvalidReference; 800 | 801 | if (ExceptionHandle == ExceptionHandleType.Log) 802 | Debug.LogException(new InvalidKeyException(key)); 803 | 804 | return default; 805 | } 806 | 807 | try 808 | { 809 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 810 | var result = operation.WaitForCompletion(); 811 | OnInstantiateCompleted(operation, key, false); 812 | 813 | return result; 814 | } 815 | catch (Exception ex) 816 | { 817 | if (ExceptionHandle == ExceptionHandleType.Throw) 818 | throw ex; 819 | 820 | if (ExceptionHandle == ExceptionHandleType.Log) 821 | Debug.LogException(ex); 822 | 823 | return default; 824 | } 825 | } 826 | 827 | public static bool TryInstantiateSync(string key, out GameObject result, 828 | Transform parent = null, 829 | bool inWorldSpace = false, 830 | bool trackHandle = true) 831 | { 832 | if (!GuardKey(key, out key)) 833 | { 834 | if (ExceptionHandle == ExceptionHandleType.Throw) 835 | throw Exceptions.InvalidReference; 836 | 837 | if (ExceptionHandle == ExceptionHandleType.Log) 838 | Debug.LogException(new InvalidKeyException(key)); 839 | 840 | result = default; 841 | return false; 842 | } 843 | 844 | try 845 | { 846 | var operation = Addressables.InstantiateAsync(key, parent, inWorldSpace, trackHandle); 847 | result = operation.WaitForCompletion(); 848 | OnInstantiateCompleted(operation, key, false); 849 | 850 | return result; 851 | } 852 | catch (Exception ex) 853 | { 854 | if (ExceptionHandle == ExceptionHandleType.Throw) 855 | throw ex; 856 | 857 | if (ExceptionHandle == ExceptionHandleType.Log) 858 | Debug.LogException(ex); 859 | 860 | result = default; 861 | return false; 862 | } 863 | } 864 | 865 | public static GameObject InstantiateSync(AssetReference reference, 866 | Transform parent = null, 867 | bool inWorldSpace = false) 868 | { 869 | if (!GuardKey(reference, out var key)) 870 | { 871 | if (ExceptionHandle == ExceptionHandleType.Throw) 872 | throw Exceptions.InvalidReference; 873 | 874 | if (ExceptionHandle == ExceptionHandleType.Log) 875 | Debug.LogException(new InvalidKeyException(key)); 876 | 877 | return default; 878 | } 879 | 880 | try 881 | { 882 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 883 | var result = operation.WaitForCompletion(); 884 | OnInstantiateCompleted(operation, key, true); 885 | 886 | return result; 887 | } 888 | catch (Exception ex) 889 | { 890 | if (ExceptionHandle == ExceptionHandleType.Throw) 891 | throw ex; 892 | 893 | if (ExceptionHandle == ExceptionHandleType.Log) 894 | Debug.LogException(ex); 895 | 896 | return default; 897 | } 898 | } 899 | 900 | public static bool TryInstantiateSync(AssetReference reference, out GameObject result, 901 | Transform parent = null, 902 | bool inWorldSpace = false) 903 | { 904 | if (!GuardKey(reference, out var key)) 905 | { 906 | if (ExceptionHandle == ExceptionHandleType.Throw) 907 | throw Exceptions.InvalidReference; 908 | 909 | if (ExceptionHandle == ExceptionHandleType.Log) 910 | Debug.LogException(new InvalidKeyException(key)); 911 | 912 | result = default; 913 | return false; 914 | } 915 | 916 | try 917 | { 918 | var operation = reference.InstantiateAsync(parent, inWorldSpace); 919 | result = operation.WaitForCompletion(); 920 | OnInstantiateCompleted(operation, key, true); 921 | 922 | return result; 923 | } 924 | catch (Exception ex) 925 | { 926 | if (ExceptionHandle == ExceptionHandleType.Throw) 927 | throw ex; 928 | 929 | if (ExceptionHandle == ExceptionHandleType.Log) 930 | Debug.LogException(ex); 931 | 932 | result = default; 933 | return false; 934 | } 935 | } 936 | } 937 | 938 | internal static partial class AsyncOperationExtensions 939 | { 940 | public static void WaitForCompletion(this AsyncOperation operation) 941 | { 942 | new SyncOperationAwaiter(operation).WaitForCompletion(); 943 | } 944 | } 945 | 946 | internal readonly struct SyncOperationAwaiter 947 | { 948 | private readonly AsyncOperation operation; 949 | 950 | public SyncOperationAwaiter(AsyncOperation operation) 951 | { 952 | this.operation = operation; 953 | } 954 | 955 | public bool IsCompleted 956 | { 957 | get 958 | { 959 | if (this.operation == null) 960 | return true; 961 | 962 | return this.operation.isDone; 963 | } 964 | } 965 | 966 | public void WaitForCompletion() 967 | { 968 | while (!this.IsCompleted) { } 969 | } 970 | } 971 | } 972 | 973 | #endif -------------------------------------------------------------------------------- /AddressablesManager/SyncMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe0746a51e814a74f90d04ec8904e379 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Laicasaane 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 NONINFRINGEMENT. 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. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab52417911dc2cd4f81a0040c6d12ca0 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Addressables Manager 2 | 3 | - The APIs provided by `AddressablesManager` are equivalent to that of `Addressables`, with 3 kinds of overloading: callback, coroutine, and async. 4 | - Loaded assets, scenes, and instances will be cached for later uses. 5 | 6 | # Changelog 7 | 8 | ## 1.3.2 9 | 10 | - Support the usecase of disabled Domain Reload 11 | 12 | ## 1.3.1 13 | 14 | - Correct all async APIs 15 | 16 | ## 1.3.0 17 | 18 | - Fix exception: Attempting to use an invalid operation handle 19 | - Add `onFailed` invocation at the end of `catch` blocks 20 | - Improve `OperationResult` struct and the way async APIs return the result 21 | - BREAKING CHANGE: some constructors are removed from `OperationResult` as deemed redundant 22 | 23 | ## 1.2.2 24 | 25 | - `LoadScene` methods will now activate scene if `activateOnLoad` param is `true` 26 | - **Breaking changes:** Correct the signature of `onSucceeded` callbacks on `LoadSceneCoroutine` and some `LoadScene` methods. 27 | - **Note:** Regarding the behaviour of `activateOnLoad`, please read this documentation: 28 | https://docs.unity3d.com/Packages/com.unity.addressables@1.16/manual/LoadSceneAsync.html 29 | 30 | 31 | ## 1.2.0 32 | 33 | - Support synchronous APIs in Addressables 1.17 34 | - Improve exceptions and logs handling 35 | - Exceptions and logs handling behaviours can be changed via `AddressablesManager.ExceptionHandle`, `AddressablesManager.SuppressErrorLogs` and `AddressablesManager.SuppressWarningLogs` properties 36 | 37 | ## 1.1.0 38 | 39 | - Use UniTask when it is included in the project 40 | - Add InitializeAsync methods 41 | - Breaking change: Rename AsyncResult to OperationResult -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b591f46bcace5484c9a68b75b5e826d1 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Unity.AddressablesManager.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.AddressablesManager", 3 | "references": [ 4 | "Unity.Addressables", 5 | "Unity.ResourceManager", 6 | "UniTask", 7 | "UniTask.Addressables" 8 | ], 9 | "includePlatforms": [], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [ 17 | { 18 | "name": "com.cysharp.unitask", 19 | "expression": "", 20 | "define": "ADDRESSABLES_UNITASK" 21 | }, 22 | { 23 | "name": "com.unity.addressables", 24 | "expression": "1.17", 25 | "define": "ADDRESSABLES_1_17" 26 | } 27 | ], 28 | "noEngineReferences": false 29 | } -------------------------------------------------------------------------------- /Unity.AddressablesManager.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92401658c2e35d94c93ddb991c046b12 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.laicasaane.unity-addressables-manager", 3 | "displayName": "Unity Addressables Manager", 4 | "version": "1.3.2", 5 | "unity": "2019.1", 6 | "license": "MIT", 7 | "description": "Unity Addressables Manager", 8 | "category": "library", 9 | "author": "Laicasaane (https://github.com/laicasaane)", 10 | "dependencies": { 11 | "com.unity.addressables": "1.6.0" 12 | } 13 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa355f7adf9d5cb4c93a48f456dbd579 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------