![]() |
EasyTalk API
|
This class is used to process a collection of linked nodes, such as a dialogue and handles all of the logic for moving from one node to the next, evaluating variable values, and sending messages (via callbacks) about what is happening in a dialogue as it is processed. More...
Public Member Functions | |
NodeHandler (GameObject owner) | |
Creates a new NodeHandler. | |
void | Initialize (Dialogue dialogue) |
Initializes the NodeHandler by setting the dialogue, clearing various mappings, determining the default 'entry' node, and creating variables. | |
void | ForceExit () |
Forces an exit to be triggered immediately on the Dialogue. | |
IEnumerator | JumpToNodeAfterDelay (float delay, Node node) |
Jumps to the specified node after a certain amount of time. | |
void | ChooseOption (int optionIdx) |
Chooses the option, and thus continues down the corresponding path, of the option specified. | |
void | ProcessNode (Node node) |
Processes the node specified according to its type. | |
void | HandleWaitNode () |
Waits for the configured duration of the wait node currently being processed before continuing. | |
void | HandlePauseNode () |
Triggers the OnPause() callback on the Dialogue Listener and waits for a continue. | |
void | HandleStoryNode () |
Triggers the OnStory() callback on the Dialogue Listener and waits for a continue. | |
void | ProcessCurrentNode () |
Processes the current node, determining any dependent values used by the node and setting values as necessary on outputs. Once the node is processed, the next node will be determined and processed. | |
void | HandleJump () |
Handles the 'jump out' node by finding the associated 'jump in' node and moving to the next node after the 'jump in'. | |
void | HandleConversation () |
Handles the current 'conversation' node, sending a signal via the onDisplayConversationLine callback to display the first line in the 'conversation' node. If the 'conversation' node only has 1 line, the atConversationNodeEnding callback will also be triggered. | |
void | HandlePathSelectorNode () |
Evaluates the current 'path select' node to determine which path to continue down and the moves along that path. | |
void | HandleOptionNode () |
Builds a List of DialogueOptions to present to the player based on the current 'option' node. This method handles 'option modifier' nodes and also deals with variable injection, translation, and tag extraction. Once the List of DialogueOptions is created, this method calls the onDisplayOptions callback so that the options can be used by anything registered with the delegate. | |
string | Translate (string text) |
Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language. | |
string | Translate (string text, out string preTranslationText) |
Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language. This method also sets the provided preTranslationText string to the string being translated, immediately prior to translation. The preTranslationText may differ from the originally provided text if the EasyTalkDialogueSettings.Instance.TranslationEvaluationMode is set to TRANSLATE_AFTER_VARIABLE_EVALUATION, since in that mode, all variable tags are replaced with their values prior to translation. | |
void | HandleExit () |
Handles the current 'exit' node by exiting the dialogue and triggering the onDialogueExited callback. | |
string | ReplaceVariablesInString (string text) |
This method does variable value injection, replacing all variable references in the specified string with their associated values. | |
object | GetVariableValue (string variableName) |
Returns the value of the variable specified, if available; otherwise returns null. | |
void | SetVariableValue (string variableName, object variableValue) |
Sets the value of the specified variable. | |
NodeVariable | GetVariable (string variableName) |
Returns the NodeVariable associated with the specified variable name. | |
EntryNode | FindEntryNode () |
Finds and returns the first 'entry' node in the Dialogue. | |
void | EnterDialogue (string entryPointName=null) |
Enters and begins processing the Dialogue. If no entry point is specified, the Dialogue will enter at the first 'entry' node found in the Dialogue. | |
void | Continue () |
Continues along to the next line of dialogue, or the next node if the last line is currently being displayed. | |
void | ResetVariablesOnEntry () |
Resets the values of each variable which is set to "reset on entry". | |
void | SaveVariableValues (string prefix="", bool saveToPlayerPrefs=false) |
Saves the values of all variables in the Dialogue to either a file, or to the PlayerPrefs. | |
void | LoadVariableValues (string prefix="", bool loadFromPlayerPrefs=false) |
Loads the states of the Dialogue's variables from a save if available. | |
void | LoadVariableValues (NodeVariableValueCollection valueCollection) |
Loads the variable values from the specified NodeVariableValueCollection into the Dialogue. | |
NodeVariableValueCollection | GetVariableValues () |
Returns a new NodeVariableValueCollection containing the current values of each variable in the Dialogue. | |
string | TranslateText (string text) |
Translates the specified string to a localized string using the TranslationLibrary of the Dialogue. | |
void | SetListener (DialogueListener listener) |
Sets the Dialogue Listener which the node handler should send events to during Dialogue processing. | |
Protected Attributes | |
Dictionary< int, Node > | inputIdToNodeMap = new Dictionary<int, Node>() |
A mapping of node input IDs to the nodes which those inputs belong to. | |
Dictionary< int, Node > | outputIdToNodeMap = new Dictionary<int, Node>() |
A mapping of node output IDs to the nodes which those inputs belong to. | |
Dictionary< string, Node > | jumpMap = new Dictionary<string, Node>() |
A mapping of jump keys/IDs to the 'jump in' nodes they belong to. | |
Dictionary< string, NodeVariable > | variables = new Dictionary<string, NodeVariable>() |
A mapping of variable names to their definitions and values. | |
Dictionary< string, Node > | entryMap = new Dictionary<string, Node>() |
A mapping of entry IDs to the 'entry' nodes they belong to. | |
Node | entryNode |
The default 'entry' node which is used if an entry ID is not provided, or the 'entry' node with the ID specified can't be found. | |
Node | currentNode |
The current node being processed/displayed. | |
int | convoIdx = 0 |
The line index of the conversation when a 'conversation' node is being processed. | |
GameObject | owner = null |
The GameObject this NodeHandler is being used by. | |
Private Member Functions | |
void | Propagate (Dictionary< int, object > nodeOutputValues, Node node) |
Evaluates the specified node to determine its output value based on its configuration and any incoming values that it depends upon, then pushes the evaluated final value to any nodes connected along the output value path. | |
void | DetermineNodeValue (Dictionary< int, object > nodeOutputValues, Node node) |
Recursively determines the output value of the specified node. | |
ConversationLine | GetConversationLine () |
Builds a ConversationLine object containing information about the current line of dialogue to be displayed. This method handles variable injection, tag extraction, and translation on the text in the 'conversation' node's current line of dialogue. | |
Node | GetNextNode () |
Returns the next node along the Dialogue flow path. | |
void | CreateBoolVariable (Node node) |
Creates a new bool type NodeVariable from the provided bool variable node. | |
void | CreateIntVariable (Node node) |
Creates a new int type NodeVariable from the provided int variable node. | |
void | CreateFloatVariable (Node node) |
Creates a new float type NodeVariable from the provided float variable node. | |
void | CreateStringVariable (Node node) |
Creates a new string type NodeVariable from the provided string variable node. | |
Private Attributes | |
Dialogue | dialogue |
The dialogue to process. | |
DialogueListener | listener |
The Dialogue Listener to use for callbacks as events happen during dialogue processing. | |
This class is used to process a collection of linked nodes, such as a dialogue and handles all of the logic for moving from one node to the next, evaluating variable values, and sending messages (via callbacks) about what is happening in a dialogue as it is processed.
EasyTalk.Controller.NodeHandler.NodeHandler | ( | GameObject | owner | ) |
Creates a new NodeHandler.
owner | The GameObject which the NodeHandler is associated with. |
void EasyTalk.Controller.NodeHandler.ChooseOption | ( | int | optionIdx | ) |
Chooses the option, and thus continues down the corresponding path, of the option specified.
optionIdx | The option index to choose. This should be the index of the option as it was originally in the 'option' node, which may differ from the index of the option as it occurs in the List of options displayed to the player. It is recommended to use DialogueOption.OptionIndex for reliability. |
void EasyTalk.Controller.NodeHandler.Continue | ( | ) |
Continues along to the next line of dialogue, or the next node if the last line is currently being displayed.
|
private |
Creates a new bool type NodeVariable from the provided bool variable node.
node | The node to use. |
|
private |
Creates a new float type NodeVariable from the provided float variable node.
node | The node to use. |
|
private |
Creates a new int type NodeVariable from the provided int variable node.
node | The node to use. |
|
private |
Creates a new string type NodeVariable from the provided string variable node.
node | The node to use. |
|
private |
Recursively determines the output value of the specified node.
nodeOutputValues | A map of node IDs and connection IDs to the output values that those IDs correspond to. |
node | The node to evaluate. |
void EasyTalk.Controller.NodeHandler.EnterDialogue | ( | string | entryPointName = null | ) |
Enters and begins processing the Dialogue. If no entry point is specified, the Dialogue will enter at the first 'entry' node found in the Dialogue.
entryPointName | The optional name of the entry point where the Dialogue should start being processed. |
EntryNode EasyTalk.Controller.NodeHandler.FindEntryNode | ( | ) |
Finds and returns the first 'entry' node in the Dialogue.
void EasyTalk.Controller.NodeHandler.ForceExit | ( | ) |
Forces an exit to be triggered immediately on the Dialogue.
|
private |
Builds a ConversationLine object containing information about the current line of dialogue to be displayed. This method handles variable injection, tag extraction, and translation on the text in the 'conversation' node's current line of dialogue.
|
private |
Returns the next node along the Dialogue flow path.
NodeVariable EasyTalk.Controller.NodeHandler.GetVariable | ( | string | variableName | ) |
Returns the NodeVariable associated with the specified variable name.
variableName | The name of the variable to retrieve. |
object EasyTalk.Controller.NodeHandler.GetVariableValue | ( | string | variableName | ) |
Returns the value of the variable specified, if available; otherwise returns null.
variableName | The name of the variable to retrieve the value of. |
NodeVariableValueCollection EasyTalk.Controller.NodeHandler.GetVariableValues | ( | ) |
Returns a new NodeVariableValueCollection containing the current values of each variable in the Dialogue.
void EasyTalk.Controller.NodeHandler.HandleConversation | ( | ) |
Handles the current 'conversation' node, sending a signal via the onDisplayConversationLine callback to display the first line in the 'conversation' node. If the 'conversation' node only has 1 line, the atConversationNodeEnding callback will also be triggered.
void EasyTalk.Controller.NodeHandler.HandleExit | ( | ) |
Handles the current 'exit' node by exiting the dialogue and triggering the onDialogueExited callback.
void EasyTalk.Controller.NodeHandler.HandleJump | ( | ) |
Handles the 'jump out' node by finding the associated 'jump in' node and moving to the next node after the 'jump in'.
void EasyTalk.Controller.NodeHandler.HandleOptionNode | ( | ) |
Builds a List of DialogueOptions to present to the player based on the current 'option' node. This method handles 'option modifier' nodes and also deals with variable injection, translation, and tag extraction. Once the List of DialogueOptions is created, this method calls the onDisplayOptions callback so that the options can be used by anything registered with the delegate.
void EasyTalk.Controller.NodeHandler.HandlePathSelectorNode | ( | ) |
Evaluates the current 'path select' node to determine which path to continue down and the moves along that path.
void EasyTalk.Controller.NodeHandler.HandlePauseNode | ( | ) |
Triggers the OnPause() callback on the Dialogue Listener and waits for a continue.
void EasyTalk.Controller.NodeHandler.HandleStoryNode | ( | ) |
Triggers the OnStory() callback on the Dialogue Listener and waits for a continue.
void EasyTalk.Controller.NodeHandler.HandleWaitNode | ( | ) |
Waits for the configured duration of the wait node currently being processed before continuing.
void EasyTalk.Controller.NodeHandler.Initialize | ( | Dialogue | dialogue | ) |
Initializes the NodeHandler by setting the dialogue, clearing various mappings, determining the default 'entry' node, and creating variables.
dialogue | The Dialogue to use. |
IEnumerator EasyTalk.Controller.NodeHandler.JumpToNodeAfterDelay | ( | float | delay, |
Node | node ) |
Jumps to the specified node after a certain amount of time.
delay | The delay, in seconds. |
node | The node to jump to. |
void EasyTalk.Controller.NodeHandler.LoadVariableValues | ( | NodeVariableValueCollection | valueCollection | ) |
Loads the variable values from the specified NodeVariableValueCollection into the Dialogue.
valueCollection | The collection of node variable values to load. |
void EasyTalk.Controller.NodeHandler.LoadVariableValues | ( | string | prefix = "", |
bool | loadFromPlayerPrefs = false ) |
Loads the states of the Dialogue's variables from a save if available.
prefix | The prefix to use when loading. This prefix is appended to the beginning of the dialogue name. |
loadFromPlayerPrefs | If true, variable states will be loaded from PlayerPrefs rather than a JSON file. |
void EasyTalk.Controller.NodeHandler.ProcessCurrentNode | ( | ) |
Processes the current node, determining any dependent values used by the node and setting values as necessary on outputs. Once the node is processed, the next node will be determined and processed.
void EasyTalk.Controller.NodeHandler.ProcessNode | ( | Node | node | ) |
Processes the node specified according to its type.
node | The node to process. |
|
private |
Evaluates the specified node to determine its output value based on its configuration and any incoming values that it depends upon, then pushes the evaluated final value to any nodes connected along the output value path.
nodeOutputValues | A map of node IDs and connection IDs to the output values that those IDs correspond to. |
node | The node to evaluate. |
string EasyTalk.Controller.NodeHandler.ReplaceVariablesInString | ( | string | text | ) |
This method does variable value injection, replacing all variable references in the specified string with their associated values.
text | The string to inject variable values into. |
void EasyTalk.Controller.NodeHandler.ResetVariablesOnEntry | ( | ) |
Resets the values of each variable which is set to "reset on entry".
void EasyTalk.Controller.NodeHandler.SaveVariableValues | ( | string | prefix = "", |
bool | saveToPlayerPrefs = false ) |
Saves the values of all variables in the Dialogue to either a file, or to the PlayerPrefs.
prefix | The prefix to use when saving. This prefix is appended to the beginning of the dialogue name. |
saveToPlayerPrefs | Whether the variable states should be saved to PlayerPrefs. If set to false, the variable states will be saved to a JSON file instead. |
void EasyTalk.Controller.NodeHandler.SetListener | ( | DialogueListener | listener | ) |
Sets the Dialogue Listener which the node handler should send events to during Dialogue processing.
listener | The Dialogue Listener to use. |
void EasyTalk.Controller.NodeHandler.SetVariableValue | ( | string | variableName, |
object | variableValue ) |
Sets the value of the specified variable.
variableName | The name of the variable to set. |
variableValue | The value to set on the variable. |
string EasyTalk.Controller.NodeHandler.Translate | ( | string | text | ) |
Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language.
text | The text to translate. |
string EasyTalk.Controller.NodeHandler.Translate | ( | string | text, |
out string | preTranslationText ) |
Performs a lookup in the active Translation Library for the text provided and returns a translation, if there is one. The text is attempted to be translated into whatever langauge is set on EasyTalkGameState.Instance.Language. This method also sets the provided preTranslationText string to the string being translated, immediately prior to translation. The preTranslationText may differ from the originally provided text if the EasyTalkDialogueSettings.Instance.TranslationEvaluationMode is set to TRANSLATE_AFTER_VARIABLE_EVALUATION, since in that mode, all variable tags are replaced with their values prior to translation.
text | The text to translate. |
preTranslationText | A string to store the text value which was translated in. This value is the text which is ultimately translated and may differ from the provided text string. |
string EasyTalk.Controller.NodeHandler.TranslateText | ( | string | text | ) |
Translates the specified string to a localized string using the TranslationLibrary of the Dialogue.
text | The line of text to translate. |
|
protected |
The line index of the conversation when a 'conversation' node is being processed.
|
protected |
The current node being processed/displayed.
|
private |
The dialogue to process.
|
protected |
A mapping of entry IDs to the 'entry' nodes they belong to.
|
protected |
The default 'entry' node which is used if an entry ID is not provided, or the 'entry' node with the ID specified can't be found.
|
protected |
A mapping of node input IDs to the nodes which those inputs belong to.
|
protected |
A mapping of jump keys/IDs to the 'jump in' nodes they belong to.
|
private |
The Dialogue Listener to use for callbacks as events happen during dialogue processing.
|
protected |
A mapping of node output IDs to the nodes which those inputs belong to.
|
protected |
The GameObject this NodeHandler is being used by.
|
protected |
A mapping of variable names to their definitions and values.