FlowCanvas Forums › Support › Working With ScriptableObjects › Reply To: Working With ScriptableObjects
Hey,
Bellow, I have created some barebones dialogue nodes for you to try out and expand. They are just simple examples of course 🙂
There is one node for Saying Dialogue and another for what would be a MultipleChoice. None of the two really work right now because they both need some sort of UI code to forward the calls to. The relevant parts are commented to give you an idea of what I mean.
In the end, it can look something like this:
Following are the nodes’ code.
Dialogue.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; namespace FlowCanvas.Nodes{ [Category("Dialogue")] public class Dialogue : FlowNode { private FlowOutput fOut; protected override void RegisterPorts(){ var actorInput = AddValueInput<GameObject>("Actor"); var textInput = AddValueInput<string>("Text"); fOut = AddFlowOutput("Out"); AddFlowInput("In", (f)=> { // Some code to tell UI to display dialogue, that should have a callback so that node knows when to continue. // For example: // DialogueUI.ShowDialogue(actorInput.value, textInput.value, OnDialogueContinue); }); } void OnDialogueContinue(){ fOut.Call( new Flow(1) ); } } } |
MultipleChoice.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using UnityEngine; using System.Collections.Generic; using ParadoxNotion.Design; namespace FlowCanvas.Nodes{ [Category("Dialogue")] public class MultipleChoice : FlowNode { public List<string> choices = new List<string>(); private List<FlowOutput> choiceOutputs = new List<FlowOutput>(); protected override void RegisterPorts(){ for (var i = 0; i < choices.Count; i++){ var displayName = string.Format("\"{0}\"", choices<em class="d4pbbc-italic"></em>); var choiceOutput = AddFlowOutput(displayName, i.ToString() ); choiceOutputs.Add(choiceOutput); } AddFlowInput("In", (f) => { // Some code to show the choices on UI which should also have a callback to let the node know when to continue. // For example: // DialogueUI.ShowMultipleChoices(choices, OnChoiceSelected) }); } void OnChoiceSelected(int choiceIndex){ choiceOutputs[choiceIndex].Call( new Flow(1) ); } //////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR protected override void OnNodeInspectorGUI(){ if (GUILayout.Button("Refresh")){ GatherPorts(); } base.OnNodeInspectorGUI(); } #endif } } |
I hope this helps in kickstarting what you want to achieve. If you need any clarification on the code above or have any questions, let me know.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh