/// <summary> /// Load the referenced asset as type TObject. /// </summary> /// <typeparam name="TObject">The object type.</typeparam> /// <returns>The load operation.</returns> public virtual AsyncOperationHandle <TObject> LoadAssetAsync <TObject>() { AsyncOperationHandle <TObject> result = Addressables.LoadAssetAsync <TObject>(RuntimeKey); m_Operation = result; return(result); }
public static IEnumerator LoadAssetCoroutine <T>(string key, Action <string, T> onSucceeded = null, Action <string> onFailed = null) where T : Object { if (!GuardKey(key, out key)) { onFailed?.Invoke(key); } else { if (!_assets.ContainsKey(key)) { var operation = Addressables.LoadAssetAsync <T>(key); yield return(operation); OnLoadAssetCompleted(operation, key, false, onSucceeded, onFailed); } else if (_assets[key] is T asset) { onSucceeded?.Invoke(key, asset); } else { if (!SuppressWarningLogs) { Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf <T>(key)); } onFailed?.Invoke(key); } } }
public static void LoadAsset <T>(string key, Action <string, T> onSucceeded, Action <string> onFailed = null) where T : Object { if (!GuardKey(key, out key)) { onFailed?.Invoke(key); return; } if (!_assets.ContainsKey(key)) { var operation = Addressables.LoadAssetAsync <T>(key); operation.Completed += handle => OnLoadAssetCompleted(handle, key, onSucceeded, onFailed); return; } if (_assets[key] is T asset) { onSucceeded?.Invoke(key, asset); } else { Debug.LogWarning($"The asset with key={key} is not an instance of {typeof(T)}."); onFailed?.Invoke(key); } }
public static IEnumerator LoadAssetCoroutine <T>(string key, Action <string, T> onSucceeded = null, Action <string> onFailed = null) where T : Object { if (!GuardKey(key, out key)) { onFailed?.Invoke(key); } else { if (!_assets.ContainsKey(key)) { var operation = Addressables.LoadAssetAsync <T>(key); yield return(operation); OnLoadAssetCompleted(operation, key, onSucceeded, onFailed); } else if (_assets[key] is T asset) { onSucceeded?.Invoke(key, asset); } else { Debug.LogWarning($"The asset with key={key} is not an instance of {typeof(T)}."); onFailed?.Invoke(key); } } }
/// <summary> /// Load the referenced asset as type TObject. /// </summary> /// <typeparam name="TObject">The object type.</typeparam> /// <returns>The load operation if there is not a valid cached operation, otherwise return default operation.</returns> public virtual AsyncOperationHandle <TObject> LoadAssetAsync <TObject>() { AsyncOperationHandle <TObject> result = default(AsyncOperationHandle <TObject>); if (m_Operation.IsValid()) { Debug.LogError("Attempting to load AssetReference that has already been loaded. Handle is exposed through getter OperationHandle"); } else { result = Addressables.LoadAssetAsync <TObject>(RuntimeKey); m_Operation = result; } return(result); }
public static void LoadAsset <T>(string key) where T : Object { if (!GuardKey(key, out key)) { if (ExceptionHandle == ExceptionHandleType.Throw) { throw new InvalidKeyException(key); } if (ExceptionHandle == ExceptionHandleType.Log) { Debug.LogException(new InvalidKeyException(key)); } return; } if (_assets.ContainsKey(key)) { if (!(_assets[key] is T)) { if (!SuppressWarningLogs) { Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf <T>(key)); } } return; } try { var operation = Addressables.LoadAssetAsync <T>(key); operation.Completed += handle => OnLoadAssetCompleted(handle, key, false); } catch (Exception ex) { if (ExceptionHandle == ExceptionHandleType.Throw) { throw ex; } if (ExceptionHandle == ExceptionHandleType.Log) { Debug.LogException(ex); } } }
public static void LoadAsset <T>(string key) where T : Object { if (!GuardKey(key, out key)) { return; } if (!_assets.ContainsKey(key)) { var operation = Addressables.LoadAssetAsync <T>(key); operation.Completed += handle => OnLoadAssetCompleted(handle, key); return; } if (!(_assets[key] is T)) { Debug.LogWarning($"The asset with key={key} is not an instance of {typeof(T)}."); } }
public static void LoadAsset <T>(string key, Action <string, T> onSucceeded, Action <string> onFailed = null) where T : Object { if (!GuardKey(key, out key)) { onFailed?.Invoke(key); return; } if (_assets.ContainsKey(key)) { if (_assets[key] is T asset) { onSucceeded?.Invoke(key, asset); return; } if (!SuppressWarningLogs) { Debug.LogWarning(Exceptions.AssetKeyNotInstanceOf <T>(key)); } onFailed?.Invoke(key); return; } try { var operation = Addressables.LoadAssetAsync <T>(key); operation.Completed += handle => OnLoadAssetCompleted(handle, key, false, onSucceeded, onFailed); } catch (Exception ex) { if (ExceptionHandle == ExceptionHandleType.Throw) { throw ex; } if (ExceptionHandle == ExceptionHandleType.Log) { Debug.LogException(ex); } } }