Create a GameObject with the DialogueController component. This GameObject requires 2 children; 1 named MessageBox and the other named Choices.
- The
MessageBoxGameObject needs 2 children; 1 namedMessageTextand the other namedName. IfMessageBoxhas anAnimatorcomponent, it will set a parameter namedOpento true/false when openning/closing.MessageTextrequires a component that inherits fromITextAnimatorand aText MeshPro UGUIcomponentNamerequires aText MeshPro UGUIcomponent
- The
ChoicesGameObject needs 1 child.- The child needs a Button component and a child with a
Text MeshPro UGUIcomponent
- The child needs a Button component and a child with a
A prefab of this is already setup in the Prefabs folder.
First create a Dialogue Flow click on Assets > Create > Dialogue Flow > Dialogue Flow Asset. Then open the Dialogue Flow Window Window > Dialogue Flow now select your Dialogue Flow Asset if it isn't selected and you should see a node labeled "Start".
To create new nodes, just right click and select the type of node to add; Dialogue, Choice or Event.
- Dialogue - Shows the message in the message box
- Choice - Shows a list of choices to select from
- Event - Calls the
OnFlowEventmessage and passes the name value as the parameter
The nodes values can be modified in the inspector.
To run a dialogue you just need to call a function in the DialogueController singleton:
// where flowAsset is type DialogueFlow.DialogueFlowAsset
DialogueFlow.DialogueController.current.SetFlow(flowAsset);If a flow is already running it will be replaced with the new one.
Dialogue Flow sends 3 messages to a GameObject
OnFlowChange- Is called when the flow changes indexvoid OnFlowChange(int index) { Debug.Log("Now starting index " + index); }
OnFlowEvent- Is called when the flow reaches anEventnodevoid OnFlowEvent(string name) { Debug.Log("The event name was " + name); }
OnFlowEnded- Is called when the flow ended or was replacedvoid OnFlowEnded(DialogueFlow.DialogueFlowAsset flow) { Debug.Log(flow.name + " just ended"); }
In order to receive these messages you need to pass call the SetFlow function like:
// where flowAsset is type DialogueFlowAsset
DialogueFlow.DialogueController.current.SetFlow(flowAsset, gameObject);The messages will be sent to the gameObject passed in the 2nd parameter.