FlowCanvas Forums › Support › Working With ScriptableObjects
I was thinking about doing some experiments with creating a barebones dialogue system with FlowCanvas, using ScriptableObjects for the overall conversation and the individual pieces of dialogue.
I was just wondering if you have a recommended technique for getting started?
Hello,
I just want to clarify first, whether or not this is a “without coding” or “with coding” question, because you will definitely need to create some custom nodes to support such a system to be intuitive (which I can help with) 🙂
Let me know.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Apologies for the confusion! I’m fine with having to create custom nodes. I’m not sure I understand the documentation very well, though.
So I brainstormed a little diagram of a custom node just to check if I’m going in the right direction. I’m guessing it would be an Event node? A node that can specify up to a certain number of inputs. For instance, I call the node “Conversation” because I was thinking that you could have a different number of participants in the conversation. Also, I added two different versions. I wasn’t sure which one made more sense.
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
Thank you so much, this helps a ton and is a lot more help than I was even expecting! I am a little confused about the multiple choice node. How does that work when the player is making the decision?
You are very welcome! I am glad that it helps.
I am not sure I understand your question about MultipleChoice though 🙂
Hmm. The MultipleChoice node above when it is called, it is meant to tell some GUI code like an imaginary “DialoguGUI” manager class, to show the options on the screen. When in that shown GUI, an option is made, the DialogueGUI should then “callback” the delegate that it was given in ‘ShowMultipleChoices’ method before, so that the node continues execution.
I am not sure if that answers your question. Let me know if not.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Sorry, I just meant, does the node connect itself from the choice the user makes to the next node?
It took me a while, but I understand what you mean now! Thanks again for the head start.
Hey,
Oh, I am very sorry I didn’t reply to your previous post in time! :/
If something is still not clear, or need any further help or clarification with this, please let me know.
Join us on Discord: https://discord.gg/97q2Rjh