public static IPromise <T> Race(IEnumerable <IPromise <T> > promises) { Promise <T> promise = Create(); foreach (IPromise <T> p in promises) { p.Then(r => { if (promise.CurrentState == PromiseState.Pending) { promise.Resolve(r); } }) .Catch(e => { if (promise.CurrentState == PromiseState.Pending) { promise.Reject(e); } }); } return(promise); }
public virtual IPromise <T> Load() { if (loadPromise != null) { return(loadPromise); } loadPromise = Promise <T> .Create(); if (IsGenerated()) { loadPromise.Resolve(Value); return(loadPromise); } if (HasValue == false) { loadPromise.Reject(new EntryPointNotFoundException($"Link doesn't have any value: {GetPath()}")); return(loadPromise); } #if USE_ADDRESSABLES if (loaded || AssetCache.Loaded(Path)) { loadPromise.Resolve(Value); return(loadPromise); } loadHandle = Addressables.LoadAssetAsync <ScriptableObject>(Path); loadHandle.Value.Completed += a => { if (Loaded == false) { if (a.Status == AsyncOperationStatus.Succeeded) { cachedAsset = a.Result as T; Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(cachedAsset); } else { loadPromise.Reject(new EntryPointNotFoundException($"Cannot load value from link: {Path}")); } } }; #else if (loaded) { loadPromise.Resolve(Value); return(loadPromise); } loadHandle = Resources.LoadAsync <ScriptableObject>(Path); loadHandle.completed += a => { if (Loaded == false) { if (a.isDone) { cachedAsset = loadHandle.asset as T; Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(cachedAsset); } else { loadPromise.Reject(new EntryPointNotFoundException($"Cannot load value from link: {Path}")); } } }; #endif return(loadPromise); }
public virtual IPromise <T> Load() { if (loadPromise != null) { return(loadPromise); } loadPromise = Promise <T> .Create(); if (HasValue == false) { loadPromise.Reject(new EntryPointNotFoundException("Link doesn't have any value")); return(loadPromise); } #if USE_ADDRESSABLES if (loaded || AssetCache.Loaded(Path)) { loadPromise.Resolve(Value); return(loadPromise); } if (IsGenerated()) { cachedAsset = App.Core.Storage.Load <T>(this); Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(cachedAsset); return(loadPromise); } loadHandle = Addressables.LoadAssetAsync <T>(Path); loadHandle.Value.Completed += a => { if (Loaded == false) { if (a.Status == AsyncOperationStatus.Succeeded) { cachedAsset = a.Result; Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(a.Result); } else { var e = new EntryPointNotFoundException($"Cannot load value from link: {Path}"); UnityEngine.Debug.LogException(e); loadPromise.Reject(e); } } }; #else if (loaded) { loadPromise.Resolve(Value); return(loadPromise); } if (IsGenerated()) { cachedAsset = App.Core.Storage.Load <T>(this); Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(cachedAsset); return(loadPromise); } loadHandle = Resources.LoadAsync <T>(Path); loadHandle.completed += r => { if (Loaded == false && loadHandle.isDone && loadHandle.asset) { cachedAsset = loadHandle.asset as T; Initialize(cachedAsset); loaded = cachedAsset != null; loadPromise.Resolve(cachedAsset); } else { loadPromise.Reject(new EntryPointNotFoundException($"Cannot load resource of type {typeof(T)} at path {Path}")); } }; #endif return(loadPromise); }
private IEnumerator WaitForCoroutine(float seconds, Promise promise) { yield return(new WaitForSeconds(seconds)); promise.Resolve(); }
private IEnumerator WaitForUnscaledCoroutine(float seconds, Promise promise) { yield return(new WaitForSecondsRealtime(seconds)); promise.Resolve(); }
private IEnumerator WaitForNextFrameCoroutine(Promise promise) { yield return(new WaitForEndOfFrame()); promise.Resolve(); }
private IEnumerator WaitForFixedUpdateCoroutine(Promise promise) { yield return(new WaitForFixedUpdate()); promise.Resolve(); }