/// <summary> /// Start this instance. /// </summary> void Start() { if (timeLeft > 0f) { cooldownCoroutine = coroutineContainer.StartCoroutine(CooldownCoroutine()); } }
/// <summary> /// Calls the drag and drop event manually from script. /// </summary> /// <param name="sourceCell">Source cell.</param> /// <param name="destinationCell">Destination cell.</param> public void CallDadEventManually(StackCell sourceCell, StackCell destinationCell) { if (myState == MyState.WaitForRequest) { if (sourceCell != null && destinationCell != null) { DadCell.DadEventDescriptor desc = new DadCell.DadEventDescriptor(); desc.sourceCell = sourceCell.GetComponent <DadCell>(); desc.destinationCell = destinationCell.GetComponent <DadCell>(); myState = MyState.Busy; // Operate item's drop eventHandkerCoroutine = coroutineContainer.StartCoroutine(EventHandler(desc)); } } }
public void TestTaskDelay() { var i = 0; var run = true; var thread = Thread.CurrentThread.ManagedThreadId; var co = CoroutineContainer.StartCoroutine(Run); Assert.AreEqual(0, i); while (run && co.IsRunning()) { TimerManager.Update(TimerManager.Now + TimeSpan.FromMilliseconds(100)); CoroutineManager.OneLoop(); Thread.Yield(); } Assert.IsTrue(co.IsSuccess()); Assert.AreEqual(3, i); async IWaitable Run() { i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); await Task.Delay(1); i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); await Task.Delay(1); i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); run = false; } }
public void TestCascade() { var i = 0; var co = CoroutineContainer.StartCoroutine(RunFather()); Assert.IsTrue(co.IsRunning()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(4, i); Assert.IsTrue(co.IsSuccess()); Tick(); Assert.IsTrue(co.IsSuccess()); IEnumerable RunFather() { i++; yield return(CoroutineContainer.StartCoroutine(RunChild())); i++; } IEnumerable RunChild() { i++; yield return(null); i++; } }
public void TestClear() { var i = 0; CoroutineContainer.StartCoroutine(Run()); CoroutineContainer.StartCoroutine(Run()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineContainer.ClearAllCoroutines(); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); IEnumerable Run() { while (true) { yield return(null); i++; } } }
public void Test2() { var i = 0; var co = CoroutineContainer.StartCoroutine(Run()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); Tick(); co.Throw(); Assert.AreEqual(1, i); Assert.IsTrue(co.IsSuccess()); IEnumerable Run() { Assert.AreEqual(0, i); yield return(null); Assert.AreEqual(0, i); i++; Assert.AreEqual(1, i); } }
public void TestCascadeThrow3() { var i = 0; CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); Tick(); //handle Assert.AreEqual(-10, i); IEnumerable RunFather() { i++; yield return(CoroutineContainer.StartCoroutine(RunChild()).Catch(e => { i = -10; })); Assert.Fail(); } IEnumerable RunChild() { i++; yield return(null); i++; throw new ArgumentException(); } }
public void TestAbort1() { var i = 0; CoroutineContainer.StartCoroutine(RunFather()).With(out var co); Assert.AreEqual(0, i); for (var tick = 0; tick < 1000; tick++) { CoroutineManager.OneLoop(); if (i == 10) { co.Abort(); } } Assert.AreEqual(10, i); IEnumerable RunFather() { while (true) { i++; yield return(null); } } }
public void TestCascadeThrow2() { var i = 0; var co = CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); Assert.IsTrue(co.IsError()); Tick(); //handle Assert.AreEqual(3, i); IEnumerable RunFather() { i++; yield return(CoroutineContainer.StartCoroutine(RunChild())); Assert.Fail(); } IEnumerable RunChild() { i++; yield return(null); i++; throw new ArgumentException(); } }
public void TestYield() { var i = 0; var co = CoroutineContainer.StartCoroutine(Run()); Assert.AreEqual(0, i); Assert.IsTrue(co.IsRunning()); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); Assert.IsTrue(co.IsSuccess()); IEnumerable Run() { i++; yield return(WaitFor.Yield()); i++; yield return(WaitFor.Yield()); i++; } }
public void TestCascadeThrow1() { var i = 0; var co = CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); Assert.IsTrue(co.IsRunning()); Tick(); Assert.AreEqual(1, i); Assert.IsTrue(co.IsError()); IEnumerable RunFather() { i++; yield return(CoroutineContainer.StartCoroutine(RunChild(true))); Assert.Fail(); } IEnumerable RunChild(bool b) { if (b) { throw new ArgumentException(); } yield break; } }
public void TestAwait() { var i = 0; var co = CoroutineContainer.StartCoroutine(Run); Assert.AreEqual(0, i); Assert.IsTrue(co.IsRunning()); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); Assert.IsTrue(co.IsSuccess()); async IWaitable Run() { i++; await WaitFor.Yield(); i++; await WaitFor.Yield(); i++; } }
/// <summary> /// Starts the highlight. /// </summary> public void StartHighlight() { if (inited == false) { Init(); } highlightCoroutine = coroutineContainer.StartCoroutine(HighlightCoroutine()); }
public void TestAbort3() { var i = 0; var j = 0; var co2 = CoroutineContainer.StartCoroutine(RunChild()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); var co1 = CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); //father++ child++ Assert.AreEqual(4, i); CoroutineManager.OneLoop(); //father wait child++ Assert.AreEqual(5, i); co2.Abort(); Assert.AreEqual(6, i); Assert.AreEqual(1, j); CoroutineManager.OneLoop(); //father++ child abort Assert.IsTrue(co2.IsAborted()); Assert.AreEqual(6, i); Tick(); Assert.AreEqual(6, i); Assert.AreEqual(1, j); Assert.AreEqual(WaitableStatus.Abort, co2.Status); Assert.AreEqual(WaitableStatus.Success, co1.Status); IEnumerable RunFather() { i++; yield return(co2.Catch(e => j++)); i++; } IEnumerable RunChild() { while (true) { i++; yield return(null); } } }
public void TestAbort4() { var i = 0; var co2 = CoroutineContainer.StartCoroutine(RunChild()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); var co1 = CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(4, i); co1.Abort(false); Assert.AreEqual(4, i); CoroutineManager.OneLoop(); Assert.AreEqual(5, i); CoroutineManager.OneLoop(); Assert.AreEqual(6, i); IEnumerable RunFather() { i++; yield return(co2); i++; } IEnumerable RunChild() { while (true) { i++; yield return(null); } } }
public void Test1() { var i = 0; var co = CoroutineContainer.StartCoroutine(Run()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); Tick(); Assert.AreEqual(1, i); Assert.IsTrue(co.IsSuccess()); IEnumerable Run() { i++; yield break; } }
public void TestAbort2() { var i = 0; IWaitable co2 = null; var co1 = CoroutineContainer.StartCoroutine(RunFather()); Assert.AreEqual(0, i); CoroutineManager.OneLoop(); Assert.AreEqual(1, i); CoroutineManager.OneLoop(); Assert.AreEqual(2, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); co1.Abort(); Assert.AreEqual(3, i); CoroutineManager.OneLoop(); Assert.AreEqual(3, i); Tick(); Assert.AreEqual(3, i); Assert.AreEqual(WaitableStatus.Abort, co1.Status); Assert.AreEqual(WaitableStatus.Abort, co2.Status); Assert.IsTrue(co1.IsAborted()); Assert.IsTrue(co2.IsAborted()); IEnumerable RunFather() { i++; co2 = CoroutineContainer.StartCoroutine(RunChild()); yield return(co2); i++; } IEnumerable RunChild() { while (true) { i++; yield return(null); } } }
public void TestThrow() { var i = 0; Assert.AreEqual(0, i); var co = CoroutineContainer.StartCoroutine(Run(true)); Assert.AreEqual(0, i); Tick(); Assert.AreEqual(0, i); Assert.IsTrue(co.IsError()); IEnumerable Run(bool t) { if (t) { throw new ArgumentException(); } i++; yield return(null); i++; } }
public void Test1() { var i = 0; var thread = Thread.CurrentThread.ManagedThreadId; var co = CoroutineContainer.StartCoroutine(Run); Assert.AreEqual(0, i); Tick(); Assert.AreEqual(3, i); Assert.IsTrue(co.IsSuccess()); async IWaitable Run() { i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); await WaitFor.Seconds(TimerManager, 0.1); i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); await WaitFor.Seconds(TimerManager, 0.1); i++; Assert.AreEqual(thread, Thread.CurrentThread.ManagedThreadId); } }
/// <summary> /// Starts the highlight. /// </summary> public void StartHighlight() { Init(); highlightCoroutine = coroutineContainer.StartCoroutine(HighlightCoroutine()); }
public static Coroutine StartACoroutine(ConditionPredicate ConditionToSatisfy, System.Action ActionUntilCondtionSatisfied, System.Action OnSatisfied) { RequestInstanceCreation(); return(Instance.StartCoroutine(GenericRoutine(ConditionToSatisfy, ActionUntilCondtionSatisfied, OnSatisfied))); }