public static IEnumerator ToUnity(this WaitCommand waitCommand, StartRoutine startRoutine) { if (waitCommand.IsRoutine) { var runningRoutines = new UnityEngine.Coroutine[waitCommand.RoutineCount]; for (int i = 0; i < waitCommand.RoutineCount; i++) { var routine = waitCommand.GetRoutine(i).ToUnity(startRoutine); var runningRoutine = startRoutine(routine); runningRoutines[i] = runningRoutine; } for (int i = 0; i < runningRoutines.Length; i++) { var runningRoutine = runningRoutines[i]; yield return(runningRoutine); } } else { if (waitCommand.Duration.Value.Seconds > 0f) { yield return(new WaitForSeconds(waitCommand.Duration.Value.Seconds)); } else { for (int i = 0; i < waitCommand.Duration.Value.FrameCount; i++) { yield return(null); } } } }