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 | Update () |
Called by Dialogue Controllers to run queued up Tasks. | |
void | AddTask (Task task) |
Adds a task to the current queue. | |
void | ExecutionCompleted (AsyncNode asyncNode) |
Creates a Task to call AsyncExecutionCompleted on the main thread. | |
void | DisplayLine (ConversationLine line) |
Queues up a Task to call OnDisplayLine on the node handler's Dialogue Listener. Normally, this will cause a line of dialogue to be displayed. | |
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. | |
Node | GetNextNode () |
Returns the next node along the Dialogue flow path. | |
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 local variables in the Dialogue to either a file, or to the PlayerPrefs. | |
void | SaveGlobalVariableValues (string prefix="", bool saveToPlayerPrefs=false) |
Saves global variable values to PlayerPrefs or a JSON file. | |
void | LoadVariableValues (string prefix="", bool loadFromPlayerPrefs=false) |
Loads variable values for the dialogue from a save if available. | |
void | LoadGlobalVariableValues (string prefix="", bool loadFromPlayerPrefs=false) |
Loads global variable values from a save if available. | |
NodeVariableValueCollection | GetVariableValues () |
Returns a new NodeVariableValueCollection containing the current values of each variable in the Dialogue. | |
NodeVariableValueCollection | GetGlobalVariableValues () |
Returns a new NodeVariableValueCollection containing the current values of all global dialogue variables. | |
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. | |
void | InitializeGlobalVariables (DialogueRegistry registry=null) |
Attempts to initialize all global variables, if they can be found in either the DialogueRegistry provided, or in a DialogueRegistry in the current Dialogue Settings, or in the Dialogue Settings of a Dialogue Display in the Hierarchy. | |
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. | |
Static Protected Attributes | |
static Dictionary< string, NodeVariable > | globalVariables = new Dictionary<string, NodeVariable>() |
A mapping of global variable names to their definitions and values. | |
Properties | |
DialogueListener | Listener [get] |
Gets the Dialogue Listener of the node handler. | |
EasyTalkDialogueSettings | DialolgueSettings [get, set] |
Gets or sets the Dialogue Settings used by the node handler. | |
Private Member Functions | |
void | AsyncExecutionCompleted (AsyncNode asyncNode) |
Called whenever asynchronous execution of an AsyncNode has been completed. | |
Node | 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. | |
Node | 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. | |
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. | |
void | CreateVariable (Type type, string variableName, object initialValue, object currentValue, bool resetOnEntry, bool isGlobal) |
Creates a variable for use by the node handler. Global variables persist for use by all node handlers. | |
void | SaveVariableValues (NodeVariableValueCollection variableValues, string suffix, string prefix="", bool saveToPlayerPrefs=false) |
Saves variable values from the provided NodeVariableValueCollection to PlayerPrefs or a JSON file. | |
NodeVariableValueCollection | LoadVariableValueCollection (string suffix, string prefix="", bool loadFromPlayerPrefs=false) |
Loads the states of variables from a save if available. | |
void | LoadVariableValues (NodeVariableValueCollection valueCollection) |
Loads the variable values from the specified NodeVariableValueCollection into the Dialogue. | |
void | LoadGlobalVariableValues (NodeVariableValueCollection valueCollection) |
Loads the values from the specified NodeVariableValueCollection into the collection of global variables. | |
void | LoadVariableValuesFromCollection (NodeVariableValueCollection valueCollection, Dictionary< string, NodeVariable > dialogueVariables) |
Loads the values from the specified NodeVariableValueCollection into the provided Dictionary of variable names mapped to NodeVariable values. | |
NodeVariableValueCollection | CreateNodeVariableValueCollection (Dictionary< string, NodeVariable > dialogueVariables) |
Creates and returns a new NodeVariableValueCollection containing the current values of all of the variables in the provided Dictionary. | |
void | SaveVariables () |
void | SaveGlobalVariables () |
void | LoadVariables () |
void | LoadGlobalVariables () |
Private Attributes | |
Dialogue | dialogue |
The dialogue to process. | |
DialogueListener | listener |
The Dialogue Listener to use for callbacks as events happen during dialogue processing. | |
bool | isProcessingAsyncNode = false |
Keeps track of whether the node handler is currently processing and waiting for an asynchronous node to finish. | |
bool | isWaitingForNodeValueDetermination = false |
Keeps track of whether the node handler waiting for an output value to be determined for the current node. | |
Dictionary< int, object > | nodeValues = new Dictionary<int, object>() |
A Dictionary which maps node and output IDs to the values output by the respective components. | |
EasyTalkDialogueSettings | dialogueSettings = null |
The Dialogue Settings currently in use. | |
List< Task > | tasks = new List<Task>() |
A List of Tasks. | |
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.AddTask | ( | Task | task | ) |
Adds a task to the current queue.
task | The Task to add to the queue. |
|
private |
Called whenever asynchronous execution of an AsyncNode has been completed.
asyncNode | The AsyncNode which execution completed on. |
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 and returns a new NodeVariableValueCollection containing the current values of all of the variables in the provided Dictionary.
dialogueVariables | The variable dictionary to populate from. |
|
private |
Creates a new string type NodeVariable from the provided string variable node.
node | The node to use. |
|
private |
Creates a variable for use by the node handler. Global variables persist for use by all node handlers.
type | The type of the variable (int, float, string, or bool). |
variableName | The name of the variable. |
initialValue | The initial/default value of the variable. |
currentValue | The current value of the variable. |
resetOnEntry | Whether the variable should be reset whenever the dialogue is entered (only applicable for local variables, not global). |
isGlobal | Whether the variable is global (persists to all dialogues). |
|
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.DisplayLine | ( | ConversationLine | line | ) |
Queues up a Task to call OnDisplayLine on the node handler's Dialogue Listener. Normally, this will cause a line of dialogue to be displayed.
line | The line of dialogue to queue up. |
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. |
void EasyTalk.Controller.NodeHandler.ExecutionCompleted | ( | AsyncNode | asyncNode | ) |
Creates a Task to call AsyncExecutionCompleted on the main thread.
asyncNode | The AsyncNode which has completed execution. |
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.
NodeVariableValueCollection EasyTalk.Controller.NodeHandler.GetGlobalVariableValues | ( | ) |
Returns a new NodeVariableValueCollection containing the current values of all global dialogue variables.
Node EasyTalk.Controller.NodeHandler.GetNextNode | ( | ) |
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. |
void EasyTalk.Controller.NodeHandler.InitializeGlobalVariables | ( | DialogueRegistry | registry = null | ) |
Attempts to initialize all global variables, if they can be found in either the DialogueRegistry provided, or in a DialogueRegistry in the current Dialogue Settings, or in the Dialogue Settings of a Dialogue Display in the Hierarchy.
registry | A Dialogue Registry to initialize global variables from. |
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. |
|
private |
|
private |
Loads the values from the specified NodeVariableValueCollection into the collection of global variables.
valueCollection | The collection of global variable values to load. |
void EasyTalk.Controller.NodeHandler.LoadGlobalVariableValues | ( | string | prefix = "", |
bool | loadFromPlayerPrefs = false ) |
Loads global variable values from a save if available.
prefix | The prefix to use when loading. This prefix is appended to '_global' or '_global.json', depending on whether values are to be loaded from player prefs or a JSON file. |
loadFromPlayerPrefs | If true, variable states will be loaded from PlayerPrefs rather than a JSON file. |
|
private |
|
private |
Loads the states of variables from a save if available.
suffix | The suffix to use when loading the values. |
prefix | The prefix to use when loading the values. |
loadFromPlayerPrefs | If true, variable states will be loaded from PlayerPrefs rather than a JSON file. |
|
private |
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 variable values for the dialogue from a save if available.
prefix | The prefix to use when loading. This prefix is appended to ('_' + the dialogue name) or )'_' + the dialogue name + '.json'), depending on whether values are to be loaded from PlayerPrefs or a JSON file. |
loadFromPlayerPrefs |
|
private |
Loads the values from the specified NodeVariableValueCollection into the provided Dictionary of variable names mapped to NodeVariable values.
valueCollection | The collection of variable values to load. |
dialogueVariables | The Dictionary to load variables into. |
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".
|
private |
void EasyTalk.Controller.NodeHandler.SaveGlobalVariableValues | ( | string | prefix = "", |
bool | saveToPlayerPrefs = false ) |
Saves global variable values to PlayerPrefs or a JSON file.
prefix | The prefix to use when saving. The prefix is appended before '_global' or '_global.json'. |
saveToPlayerPrefs | Whether variable values should be saved to PlayerPrefs rather than a JSON file. |
|
private |
|
private |
Saves variable values from the provided NodeVariableValueCollection to PlayerPrefs or a JSON file.
variableValues | The collection of variable values to save. |
suffix | The suffix to use when saving the values. |
prefix | The prefix to use when saving the values. |
saveToPlayerPrefs | Whether the values should be saved to PlayerPrefs rather than a JSON file. |
void EasyTalk.Controller.NodeHandler.SaveVariableValues | ( | string | prefix = "", |
bool | saveToPlayerPrefs = false ) |
Saves the values of all local 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. |
void EasyTalk.Controller.NodeHandler.Update | ( | ) |
Called by Dialogue Controllers to run queued up Tasks.
|
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.
|
private |
The Dialogue Settings currently in use.
|
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.
|
staticprotected |
A mapping of global variable names to their definitions and values.
|
protected |
A mapping of node input IDs to the nodes which those inputs belong to.
|
private |
Keeps track of whether the node handler is currently processing and waiting for an asynchronous node to finish.
|
private |
Keeps track of whether the node handler waiting for an output value to be determined for the current node.
|
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.
|
private |
A Dictionary which maps node and output IDs to the values output by the respective components.
|
protected |
A mapping of node output IDs to the nodes which those inputs belong to.
|
protected |
The GameObject this NodeHandler is being used by.
|
private |
A List of Tasks.
|
protected |
A mapping of variable names to their definitions and values.
|
getset |
Gets or sets the Dialogue Settings used by the node handler.
|
get |
Gets the Dialogue Listener of the node handler.