Skip to content

Instantly share code, notes, and snippets.

@jonas-johansson
Last active November 26, 2020 15:05
Show Gist options
  • Save jonas-johansson/12e2c6d68ea023c5ec47a7cbcd50a798 to your computer and use it in GitHub Desktop.
Save jonas-johansson/12e2c6d68ea023c5ec47a7cbcd50a798 to your computer and use it in GitHub Desktop.
This Bolt unit runs a coroutine by name on a MonoBehaviour.
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