diff --git a/Convention/[Runtime]/Config.cs b/Convention/[Runtime]/Config.cs index 88bdbeb..94b6f1f 100644 --- a/Convention/[Runtime]/Config.cs +++ b/Convention/[Runtime]/Config.cs @@ -1319,28 +1319,30 @@ namespace Convention public class ActionStepCoroutineWrapper { - private class YieldInstructionWrapper + private struct YieldInstructionWrapper { public YieldInstruction UnityYieldInstruction; public CustomYieldInstruction CustomYieldInstruction; - public YieldInstructionWrapper() - { - - } - - public YieldInstructionWrapper(YieldInstruction unityYieldInstruction) + public YieldInstructionWrapper(YieldInstruction unityYieldInstruction, CustomYieldInstruction customYieldInstruction) { this.UnityYieldInstruction = unityYieldInstruction; + this.CustomYieldInstruction = customYieldInstruction; } - public YieldInstructionWrapper(CustomYieldInstruction customYieldInstruction) + public static YieldInstructionWrapper Make(YieldInstruction unityYieldInstruction) { - this.CustomYieldInstruction = customYieldInstruction; + return new(unityYieldInstruction, null); + } + + public static YieldInstructionWrapper Make(CustomYieldInstruction customYieldInstruction) + { + return new(null, customYieldInstruction); } } private List> steps = new(); + public ActionStepCoroutineWrapper Update(Action action) { steps.Add(new(new(), action)); @@ -1348,33 +1350,33 @@ namespace Convention } public ActionStepCoroutineWrapper Wait(float time, Action action) { - steps.Add(new(new(new WaitForSeconds(time)), action)); + steps.Add(new(YieldInstructionWrapper.Make(new WaitForSeconds(time)), action)); return this; } public ActionStepCoroutineWrapper FixedUpdate(Action action) { - steps.Add(new(new (new WaitForFixedUpdate()), action)); + steps.Add(new(YieldInstructionWrapper.Make(new WaitForFixedUpdate()), action)); return this; } public ActionStepCoroutineWrapper Next(Action action) { - steps.Add(new(new(new WaitForEndOfFrame()), action)); + steps.Add(new(YieldInstructionWrapper.Make(new WaitForEndOfFrame()), action)); return this; } public ActionStepCoroutineWrapper Until(Func pr, Action action) { - steps.Add(new(new(new WaitUntil(pr)), action)); + steps.Add(new(YieldInstructionWrapper.Make(new WaitUntil(pr)), action)); return this; } private static IEnumerator Execute(List> steps) { foreach (var (waiting, action) in steps) { - action(); if (waiting.UnityYieldInstruction != null) yield return waiting.UnityYieldInstruction; else yield return waiting.CustomYieldInstruction; + action(); } } ~ActionStepCoroutineWrapper()