protected IEnumerator TestInterceptException() { ProgressResult <float, bool> result = new ProgressResult <float, bool>(true); /* Register a callback */ result.Callbackable().OnProgressCallback(p => Debug.LogFormat("Progress:{0}%", p * 100)); result.Callbackable().OnCallback((r) => { Debug.LogFormat("The task is finished. IsCancelled:{0} Result:{1} Exception:{2}", r.IsCancelled, r.Result, r.Exception); }); InterceptableEnumerator routine = new InterceptableEnumerator(DoTask(result)); routine.RegisterCatchBlock((e) => { Debug.LogError(e); }); routine.RegisterFinallyBlock(() => { Debug.Log("this is a finally block."); }); /* Start the task */ this.StartCoroutine(routine); yield break; }
protected IEnumerator TestInterceptMoveNextMethod() { ProgressResult <float, bool> result = new ProgressResult <float, bool>(true); /* Register a callback */ result.Callbackable().OnProgressCallback(p => Debug.LogFormat("Progress:{0}%", p * 100)); result.Callbackable().OnCallback((r) => { Debug.LogFormat("The task is finished. IsCancelled:{0} Result:{1} Exception:{2}", r.IsCancelled, r.Result, r.Exception); }); InterceptableEnumerator routine = new InterceptableEnumerator(DoTask(result)); /* if result.IsCancellationRequested == true ,the task will be cancelled. */ routine.RegisterConditionBlock(() => !(result.IsCancellationRequested)); routine.RegisterFinallyBlock(() => { Debug.Log("this is a finally block."); }); /* Start the task */ this.StartCoroutine(routine); yield return(new WaitForSeconds(0.5f)); result.Cancel(); }
private void InternalOpen <T>(Type type, ProgressResult <float, T> promise, ViewModel viewModel) where T : View { View view = null; var path = (GetClassData(type).Attribute as UIAttribute).Path; promise.Callbackable().OnCallback(progressResult => { Sort(view); view.Show(); }); if (openedSingleViews.TryGetValue(type, out var view1)) { promise.UpdateProgress(1); promise.SetResult(view1); } else { view = ReflectionHelper.CreateInstance(type) as View; Executors.RunOnCoroutineNoReturn(CreateViewGo(promise, view, path, viewModel)); } openedViews.Add(view); if (view.IsSingle) { openedSingleViews[type] = view; } }
void Start() { ProgressResult <float, bool> result = new ProgressResult <float, bool>(); /* Register a callback */ result.Callbackable().OnProgressCallback(p => { Debug.LogFormat("Progress:{0}%", p * 100); }); result.Callbackable().OnCallback((r) => { if (r.Exception != null) { Debug.LogFormat("The task is finished.IsDone:{0} Exception:{1}", r.IsDone, r.Exception); return; } Debug.LogFormat("The task is finished. IsDone:{0} Result:{1}", r.IsDone, r.Result); }); /* Start the task */ this.StartCoroutine(DoTask(result)); }
public override IProgressResult <float, GameObject> InstantiateAsync(string key, Vector3 position, Quaternion rotation, Transform parent = null, bool trackHandle = true) { ProgressResult <float, GameObject> progressResult = new ProgressResult <float, GameObject>(); progressResult.Callbackable().OnCallback((result => { var ins = Object.Instantiate(result.Result); SetTransform(ins, position, rotation, parent, trackHandle); progressResult.SetResult(ins); })); loadAssetAsync(key, progressResult); return(progressResult); }
public override IProgressResult <float, GameObject> InstantiateAsync(string key, Transform parent = null, bool instantiateInWorldSpace = false, bool trackHandle = true) { ProgressResult <float, GameObject> progressResult = new ProgressResult <float, GameObject>(); progressResult.Callbackable().OnCallback((result => { var ins = Object.Instantiate(result.Result); SetTransform(ins, parent, instantiateInWorldSpace); progressResult.SetResult(ins); })); loadAssetAsync(key, progressResult); return(progressResult); }
public IProgressResult <float, GameObject> InstantiateAsync(string key, Transform parent = null, bool instantiateInWorldSpace = false) { ProgressResult <float, GameObject> loadProgress = new ProgressResult <float, GameObject>(true); ProgressResult <float, GameObject> resultProgress = new ProgressResult <float, GameObject>(true); loadProgress.Callbackable().OnCallback((result => { if (loadProgress.IsCancelled) { return; } var go = Object.Instantiate(result.Result); go.transform.SetParent(parent, instantiateInWorldSpace); resultProgress.SetResult(go); })); loadAssetAsync(key, loadProgress); return(resultProgress); }
public IProgressResult <float, GameObject> InstantiateAsync(string key, Vector3 position, Quaternion rotation, Transform parent = null) { ProgressResult <float, GameObject> loadProgress = new ProgressResult <float, GameObject>(true); ProgressResult <float, GameObject> resultProgress = new ProgressResult <float, GameObject>(true); loadProgress.Callbackable().OnCallback((result => { if (loadProgress.IsCancelled) { return; } var trans = Object.Instantiate(result.Result).transform; trans.SetParent(parent); trans.localPosition = position; trans.localRotation = rotation; resultProgress.SetResult(trans.gameObject); })); loadAssetAsync(key, loadProgress); return(resultProgress); }
private void InternalOpen <T>(Type type, ProgressResult <float, T> promise, ViewModel viewModel) where T : View { promise.Callbackable().OnCallback(progressResult => { var _view = progressResult.Result; Sort(_view); _view.Show(); if (_view.IsSingle) { _openedViews[type] = _view; } }); if (_openedViews.TryGetValue(type, out var view)) { promise.UpdateProgress(1); promise.SetResult(view); } else { Executors.RunOnCoroutineNoReturn(CreateView(promise, type, viewModel)); } }