public static void Save() { Task save = new ActionTask(() => { Services.SaveManager.SaveData(); }); Task wait = new WaitTask(.5f); Task finish = new ActionTask(() => { UnityEngine.SceneManagement.SceneManager.LoadScene(1); }); save.Then(wait).Then(finish); _taskManager.Do(save); }
public async Task MergingTwoChainsWorks() { var callOrder = new List <string>(); var dependsOrder = new List <ITask>(); var innerChainTask1 = new ActionTask(TaskEx.FromResult(LogAndReturnResult(callOrder, "chain2 completed1", true))); var innerChainTask2 = innerChainTask1.Then(_ => { callOrder.Add("chain2 FuncTask<string>"); return("1"); }); var innerChainTask3 = innerChainTask2 .Finally((s, e, d) => { callOrder.Add("chain2 Finally"); return(d); }); var outerChainTask1 = new FuncTask <int>(Token, _ => { callOrder.Add("chain1 FuncTask<int>"); return(1); }); var outerChainTask2 = outerChainTask1.Then(innerChainTask3); var outerChainTask3 = outerChainTask2 .Finally((s, e) => { callOrder.Add("chain1 Finally"); }); await outerChainTask3.StartAwait(); var dependsOn = outerChainTask3; while (dependsOn != null) { dependsOrder.Add(dependsOn); dependsOn = dependsOn.DependsOn; } Assert.AreEqual(innerChainTask3, outerChainTask2); CollectionAssert.AreEqual(new ITask[] { outerChainTask1, innerChainTask1, innerChainTask2, innerChainTask3, outerChainTask3 }, dependsOrder.Reverse <ITask>().ToArray()); CollectionAssert.AreEqual(new string[] { "chain2 completed1", "chain1 FuncTask<int>", "chain2 FuncTask<string>", "chain2 Finally", "chain1 Finally" }, callOrder); }
public void SetQuestlogText(string questTag, string newText) { Logger.Debug($"tag = {questTag} text = {newText}"); if (_questTagToLog.ContainsKey(questTag) && _questTagToLog[questTag] == null) { return; } if (newText.Equals("") || newText.Equals("Find out what happened to the forest")) { _questTagToLog[questTag].text = newText; return; } Task displayHolder = new ActionTask(() => { DisplayQuestLogUI(); }); Task wait1 = new WaitTask(.5f); Task triggerTextAnim = new ActionTask(() => { HideUI(_questTagToLog[questTag]); }); Task wait2 = new WaitTask(.5f); Task setText = new ActionTask(() => { _questTagToLog[questTag].text = newText; DisplayUI(_questTagToLog[questTag]); }); Task wait3 = new WaitTask(5.5f); Task hideHolder = new ActionTask(() => { HideQuestLogUI(); _updatingQuestLog = false; }); if (_updatingQuestLog) { wait1.Then(triggerTextAnim).Then(wait2).Then(setText); _taskManager.Do(wait1); } else { _updatingQuestLog = true; displayHolder.Then(wait1).Then(triggerTextAnim).Then(wait2).Then(setText).Then(wait3).Then(hideHolder); _taskManager.Do(displayHolder); } }
public void GetTopMostTask() { var task1 = new ActionTask(TaskEx.FromResult(true)); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetTopMostTask(); Assert.AreSame(task1, top); }
public void GetFirstStartableTask_ReturnsTopTaskWhenNotStarted() { var task1 = new ActionTask(Token, () => { }); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetFirstStartableTask(); Assert.AreSame(task1, top); }
public async Task GetTopMostTaskInCreatedState() { var task1 = new ActionTask(Token, () => { }); await task1.StartAwait(); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetTopMostTaskInCreatedState(); Assert.AreSame(task2, top); }
public async Task GetFirstStartableTask_ReturnsNullWhenItsAlreadyStarted() { var task1 = new ActionTask(Token, () => { }); await task1.StartAwait(); var task2 = new TestActionTask(Token, _ => { }); var task3 = new TestActionTask(Token, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetFirstStartableTask(); Assert.AreSame(task2, top); }
public void GetFirstStartableTask_ReturnsTopTaskWhenNotStarted() { using (var test = StartTest()) { var task1 = new ActionTask(test.TaskManager, () => { }); var task2 = new TestActionTask(test.TaskManager, _ => { }); var task3 = new TestActionTask(test.TaskManager, _ => { }); task1.Then(task2).Then(task3); var top = task3.Test_GetFirstStartableTask(); Assert.AreSame(task1, top); } }
private void IntroTasks() { Task Start = new ActionTask(() => { Context.HideUI(Context._startOverlay); }); fadeInStartTask = new FadeInStartMenu(this); Task StartMusic = new ActionTask(() => { /* maybe start music here? */ // Highlight start button }); Start.Then(fadeInStartTask).Then(StartMusic); Context._taskManager.Do(Start); }
private Task DefineSequence() { Task start = new ActionTask(() => { Context.ResetInputs(); }); Task wait2Secs = new WaitTask(2f); Task forceFinalTransform = new ActionTask(() => { Context.ForceTransform(Services.QuestItemRepository.TargetStep3PlayerPosition.position, Services.QuestItemRepository.TargetStep3PlayerPosition.rotation); Context.ForceTransform(Vector3.zero, Services.QuestItemRepository.TargetStep3PlayerPosition.rotation); }); start.Then(wait2Secs).Then(forceFinalTransform); return(start); }
public IEnumerator GetTopOfChain_ReturnsTopMostInCreatedState() { using (var test = StartTest()) { var task = new ActionTask(test.TaskManager, () => { }); // wait for the tasks to finish foreach (var frame in StartAndWaitForCompletion(task)) { yield return(frame); } var task2 = new TestActionTask(test.TaskManager, _ => { }); var task3 = new TestActionTask(test.TaskManager, _ => { }); task.Then(task2).Then(task3); var top = task3.GetTopOfChain(); Assert.AreSame(task2, top); } }
public IEnumerator MultipleFinallyOrder() { using (var test = StartTest()) { var results = new List <string>(); var beforeProcess = new ActionTask(test.TaskManager, _ => results.Add("BeforeProcess")) { Name = "BeforeProcess" }; var processTask = new HelperProcessTask(test.TaskManager, test.ProcessManager, TestApp, "-x") { Name = "Process" }; // this will never run because the process throws an exception var processOutputTask = new FuncTask <string, int>(test.TaskManager, (success, previous) => { results.Add(previous); results.Add("ProcessOutput"); return(1234); }); var innerChain = processTask.Then(processOutputTask).Finally((b, exception) => results.Add("ProcessFinally"), "ProcessFinally"); var outerChain = beforeProcess.Then(innerChain).Finally((b, exception) => results.Add("AfterProcessFinally"), "AfterProcessFinally"); // wait for the tasks to finish foreach (var frame in StartAndWaitForCompletion(innerChain, outerChain)) { yield return(frame); } results.MatchesUnsorted(new[] { "BeforeProcess", "ProcessFinally", "AfterProcessFinally" }); Assert.AreEqual("BeforeProcess", results[0]); var expected = new List <string> { "ProcessFinally", "AfterProcessFinally" }; results.Skip(1).MatchesUnsorted(expected); } }
public IEnumerator GetFirstStartableTask_ReturnsNullWhenItsAlreadyStarted() { using (var test = StartTest()) { var task = new ActionTask(test.TaskManager, () => { }); // wait for the tasks to finish foreach (var frame in StartAndWaitForCompletion(task)) { yield return(frame); } var task2 = new TestActionTask(test.TaskManager, _ => { }); var task3 = new TestActionTask(test.TaskManager, _ => { }); task.Then(task2).Then(task3); var top = task3.Test_GetFirstStartableTask(); Assert.AreSame(null, top); } }
public IEnumerator NestedProcessShouldChainCorrectly() { using (var test = StartTest()) { var expected = new List <string> { "BeforeProcess", "ok", "AfterProcess", "ProcessFinally", "AfterProcessFinally" }; var results = new List <string>(); var beforeProcess = new ActionTask(test.TaskManager, _ => results.Add("BeforeProcess")) { Name = "BeforeProcess" }; var processTask = new HelperProcessTask(test.TaskManager, test.ProcessManager, TestApp, @"--sleep 1000 --data ""ok"""); var processOutputTask = new FuncTask <string, int>(test.TaskManager, (b, previous) => { results.Add(previous); results.Add("AfterProcess"); return(1234); }) { Name = "AfterProcess" }; var innerChain = processTask.Then(processOutputTask).Finally((b, exception) => results.Add("ProcessFinally"), "ProcessFinally"); var outerChain = beforeProcess.Then(innerChain).Finally((b, exception) => results.Add("AfterProcessFinally"), "AfterProcessFinally"); // wait for the tasks to finish foreach (var frame in StartAndWaitForCompletion(innerChain, outerChain)) { yield return(frame); } results.Matches(expected); } }
private Task DefineSequence() { Task start = new ActionTask(() => { Context.ResetInputs(); Context.inPlaceForSequence = false; }); Task moveToInitPos = Context.PlayerMoveToTransform( Services.QuestItemRepository.TargetStep1PlayerPosition, // Position target for player Services.QuestItemRepository.TargetItemPosition, // direction target for player Services.QuestItemRepository.TargetItemPosition); // Not totally sure. start.Then(moveToInitPos); Task phase2Start = Context.LastTask(moveToInitPos); Task reset1 = new ActionTask(() => { Context.inPlaceForSequence = false; }); Task moveToMidPos = Context.PlayerMoveToTransform( Services.QuestItemRepository.TargetStep2PlayerPosition, Services.QuestItemRepository.TargetItemPosition, Services.QuestItemRepository.TargetItemPosition); phase2Start.Then(reset1).Then(moveToMidPos); Task phase3Start = Context.LastTask(moveToMidPos); Task reset2 = new ActionTask(() => { Context.inPlaceForSequence = false; }); Task wait4Secs = new WaitTask(4f); Task forceFinalTransform = new ActionTask(() => { Context.ForceTransform(Services.QuestItemRepository.TargetStep4PlayerPosition.position, Services.QuestItemRepository.TargetStep4PlayerPosition.rotation); Services.UIManager.HideItemPickupPrompt(); }); phase3Start.Then(reset2).Then(wait4Secs).Then(forceFinalTransform); return(start); }
private static Task DefineEndSequence() { ActionTask firstSequence = new ActionTask(() => { Services.UIManager.CutsceneFadeIn(); inCutscene = true; }); Task waitForTime1 = new WaitTask(2f); ActionTask secondSequence = new ActionTask(() => { Services.UIManager.CutsceneFadeOut(); Services.UIManager.HideAllUI(); PlayerAnimation.Sitting(true); FModMusicManager.EndCutscene(); cutsceneObjectsManager.EndNPCs(); }); Task waitForTime2 = new WaitTask(14f); ActionTask thirdSequence = new ActionTask(() => { Services.UIManager.CutsceneFadeIn(); }); Task waitForTime3 = new WaitTask(4f); Task endGame = new ActionTask(() => { inCutscene = false; FModMusicManager.EndMusicLayers(); UnityEngine.SceneManagement.SceneManager.LoadScene(2); }); firstSequence.Then(waitForTime1).Then(secondSequence).Then(waitForTime2).Then(thirdSequence).Then(waitForTime3).Then(endGame); return(firstSequence); }