Last active
November 1, 2021 17:09
-
-
Save AldeRoberge/a121bf1ccaa04a2827934ae5f7cca398 to your computer and use it in GitHub Desktop.
Coroutine version of custom Bolt Unit
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 System.Collections; | |
using System.Collections.Generic; | |
using Bolt; | |
using UnityEngine; | |
using System; | |
using DefaultNamespace; | |
using Ludiq; | |
[UnitTitle("Dialogue")] | |
[UnitShortTitle("Dialogue")] | |
[UnitSubtitle("A dialogue element.")] | |
[UnitCategory("Nadagam")] | |
public class DialogueUnit : Unit | |
{ | |
[DoNotSerialize] | |
public ControlInput inputTrigger; | |
[DoNotSerialize] | |
public ControlOutput outputTrigger; | |
[DoNotSerialize] | |
public ValueInput character; | |
[DoNotSerialize] | |
public ValueInput dialogueText; | |
protected override void Definition() | |
{ | |
//The lambda to execute our node action when the inputTrigger port is triggered. | |
inputTrigger = ControlInputCoroutine("inputTrigger", (flow) => | |
{ | |
Talk(flow); | |
return Delay(flow); | |
}); | |
outputTrigger = ControlOutput("outputTrigger"); | |
character = ValueInput<Character>("Character", null); | |
dialogueText = ValueInput<string>("Text", String.Empty); | |
//To display that we need the myValueB value to be set to let the node process | |
Requirement(dialogueText, inputTrigger); | |
Requirement(character, inputTrigger); | |
} | |
public IEnumerator Delay(Flow flow) | |
{ | |
yield return new WaitForSeconds(3); | |
yield return outputTrigger; | |
} | |
private void Talk(Flow flow) | |
{ | |
var Saying = flow.GetValue<string>(dialogueText); | |
var Character = flow.GetValue<Character>(character); | |
Debug.Log(Character.Name + " says " + Saying); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment