Last active
November 26, 2020 15:05
-
-
Save jonas-johansson/12e2c6d68ea023c5ec47a7cbcd50a798 to your computer and use it in GitHub Desktop.
This Bolt unit runs a coroutine by name on a MonoBehaviour.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Bolt; | |
using Ludiq; | |
using System.Collections; | |
using UnityEngine; | |
namespace Neuston.Bolt | |
{ | |
public class CoroutineRunnerUnit : Unit | |
{ | |
[DoNotSerialize] public ControlInput start; | |
[DoNotSerialize] public ValueInput methodName; | |
[DoNotSerialize] public ValueInput subject; | |
[DoNotSerialize] public ControlOutput complete; | |
protected override void Definition() | |
{ | |
start = ControlInputCoroutine("start", RunCoroutine); | |
methodName = ValueInput<string>("methodName", string.Empty); | |
subject = ValueInput<MonoBehaviour>("subject", null); | |
complete = ControlOutput("complete"); | |
} | |
IEnumerator RunCoroutine(Flow flow) | |
{ | |
var c = flow.GetValue<MonoBehaviour>(subject); | |
var meth = flow.GetValue<string>(methodName); | |
yield return c.StartCoroutine(meth); | |
yield return complete; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment