// Block synchronously until the given coroutine completes public static void SyncWait(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { } }
public static T SyncWaitGet <T>(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { } return((T)coroutine.ReturnValue); }
public void TestObjectTrace() { try { var runner = new CoRoutine( Runner() ); while ( runner.Pump() ) { } } catch ( Exception e ) { // Should print out a readable object trace Debug.LogException( e ); } }
public static IEnumerable <CoRoutine> ContinueWith <T>(this IEnumerable <CoRoutine> coroutines, Func <T> routine) { foreach (CoRoutine coroutine in coroutines) { yield return(coroutine); } foreach (CoRoutine coroutine in CoRoutine <T> .coroutine(routine)) { yield return(coroutine); } }
// Block synchronously until the given coroutine completes // And give up after a timeout public static void SyncWaitWithTimeout(IEnumerator runner, float timeout) { var startTime = DateTime.UtcNow; var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { if ((DateTime.UtcNow - startTime).TotalSeconds > timeout) { throw new TimeoutException(); } } }
public void TestObjectTrace() { try { var runner = new CoRoutine(Runner()); while (runner.Pump()) { } } catch (Exception e) { // Should print out a readable object trace Debug.LogException(e); } }
/// <summary> /// Starts a new co-routine /// </summary> /// <param name="routine">The routine to start.</param> public void Start(CoRoutine routine) { if (routine == null) { return; } var enumerable = routine(); if (enumerable == null) { return; } this.runningRoutines.Add(new CoRoutineState() { IsFinished = false, Executor = enumerable.GetEnumerator() }); }
// This can be used to make an untyped coroutine typed // (it's nice sometimes to work with untyped coroutines so you can yield other coroutines) public static IEnumerator <T> Wrap <T>(IEnumerator runner) { var coroutine = new CoRoutine(runner); while (coroutine.Pump()) { yield return(default(T)); } if (coroutine.ReturnValue != null) { if (!typeof(T).IsAssignableFrom(coroutine.ReturnValue.GetType())) { throw new CoRoutine.AssertException( string.Format("Unexpected type returned from coroutine! Expected '{0}' and found '{1}'", typeof(T).Name, coroutine.ReturnValue.GetType().Name)); } } yield return((T)coroutine.ReturnValue); }
public void setRotationModiferAndBuild( float buildFrom, float duration ) { rotationModifier = buildFrom; rotationModifierBuildTime = duration / (1f - buildFrom); if(buildRotation != null) buildRotation.Stop(); buildRotation = new CoRoutine( buildRotationModifier() ); }
void checkScreenSize() { if( screenSize.x != Screen.width || screenSize.y != Screen.height ) screenResize(); screenSizeChecker = CoRoutine.AfterWait( 1f, checkScreenSize ); }
public static IEnumerable <CoRoutine> AsCoRoutine <T>(this Func <T> routine) { return(CoRoutine <T> .coroutine(routine)); }
void Awake() { shooter.SendMessage( "ShotActivated", SendMessageOptions.DontRequireReceiver ); destroyOnTime = CoRoutine.AfterWait( maxTime, () => Destroy( this.gameObject ) ); }
protected override void DoRender(DeviceContext context) { UpdateScene(context); CoRoutine.StartCoRoutine(RenderRoutine(context)); context.Rasterizer.State = normalState; }
/// <summary> /// Starts a co-routine. /// </summary> /// <param name="routine">The co-routine to start.</param> public void StartCoRoutine(CoRoutine routine) { this.coRoutineHost.Start(routine); }