DialogueRunner
public class DialogueRunnerInherits from MonoBehaviour
Implements Yarn.Unity.IActionRegistration, Yarn.IDialogueResponder
#Fields
#autoStart
public bool autoStart = false;Type Boolean
Yarn.Unity.DialogueRunner.Start is called and then start dialogue.
This one frame wait is due to some timing issues that can occur but if it is an issue disable this and manually call RunDialogue(string,CancellationToken) yourself on the first frame.#runSelectedOptionAsLine
public bool runSelectedOptionAsLine = false;Type Boolean
#startNode
public string startNode = "Start";Type String
See also
Yarn.Unity.DialogueRunner.YarnProjectRunDialogue
#verboseLogging
public bool verboseLogging = false;Type Boolean
#Properties
#Dialogue
#DialoguePresenters
public IEnumerable<DialoguePresenterBase?> DialoguePresenters { get; set; }Type IEnumerable
#IsDialogueRunning
public bool IsDialogueRunning { get }Type Boolean
#IsInPlaymode
public static bool IsInPlaymode { get; }Type Boolean
#LineProvider
public ILineProvider LineProvider { get; }Type ILineProvider
#NoOptionSelected
public static YarnTask<DialogueOption?> NoOptionSelected { get; }Type YarnTask
#VariableStorage
public VariableStorageBehaviour VariableStorage { get; set; }#YarnProject
public YarnProject? YarnProject { get }Type YarnProject
See also
#Methods
#AddCommandHandler(string, Delegate)
public void AddCommandHandler(string commandName, Delegate handler);Parameters
commandNamestringThe name of the command.handlerDelegateTheCommandHandlerthat will be invoked when the command is called.
You can also register commands via the YarnCommandAttribute attribute on your methods.
When this command handler has been added, it can be called from your Yarn scripts like so:
<<commandName param1 param2>>
If handler is a method that returns a YarnTask, Task, Awaitable, or UniTask when the command is run, the DialogueRunner will wait for the task to finish before delivering any more content.
If handler is a method that returns a Coroutine, when the command is run, the DialogueRunner will wait for the returned coroutine to stop before delivering any more content.
If handler is a method that returns an System.Collections.IEnumerator, when the command is run, the DialogueRunner will start a coroutine using that method and wait for that coroutine to stop before delivering any more content.
#AddCommandHandler(string, MethodInfo)
public void AddCommandHandler(string commandName, MethodInfo method);Parameters
commandNamestringThe name of the command.handler(unknown)TheCommandHandlerthat will be invoked when the command is called.commandName(unknown)The name of the command.methodInfo(unknown)The method that will be invoked when the command is called.methodMethodInfo
You can also register commands via the YarnCommandAttribute attribute on your methods.
When this command handler has been added, it can be called from your Yarn scripts like so:
<<commandName param1 param2>>
If handler is a method that returns a YarnTask, Task, Awaitable, or UniTask when the command is run, the DialogueRunner will wait for the task to finish before delivering any more content.
If handler is a method that returns a Coroutine, when the command is run, the DialogueRunner will wait for the returned coroutine to stop before delivering any more content.
If handler is a method that returns an System.Collections.IEnumerator, when the command is run, the DialogueRunner will start a coroutine using that method and wait for that coroutine to stop before delivering any more content.
#AddFunction(string, Delegate)
public void AddFunction(string name, Delegate implementation);Parameters
namestringThe name of the function to add.implementationDelegateTheSystem.Delegatethat should be invoked when this function is called.
You can also register functions via the YarnFunctionAttribute attribute on your methods.
When this function has been registered, it can be called from your Yarn scripts like so:
<<if myFunction(1, 2) == true>>
myFunction returned true!
<<endif>>
See also
Library
#AddPresenter(DialoguePresenterBase)
public void AddPresenter(DialoguePresenterBase presenter)Parameters
presenterYarn.Unity.DialoguePresenterBasethe new presenter to add
#CanCallFunction(string)
public bool CanCallFunction(string functionName)Parameters
functionNamestring
Returns Boolean
#FindRunner(Component)
public static DialogueRunner? FindRunner(Component component)Parameters
componentComponentThe component whos dialogue runner we are after
Returns DialogueRunner: The runner, or null if one couldn't be found
#HandleCommand(Command, CancellationToken)
public async ValueTask HandleCommand(Command command, CancellationToken token)Parameters
commandYarn.CommandtokenCancellationToken
Returns ValueTask
#HandleDialogueComplete()
public async ValueTask HandleDialogueComplete()Returns ValueTask
#HandleLine(Line, CancellationToken)
public async ValueTask HandleLine(Line line, CancellationToken token)Parameters
lineYarn.LinetokenCancellationToken
Returns ValueTask
#HandleNodeComplete(string, CancellationToken)
public async ValueTask HandleNodeComplete(string node, CancellationToken token)Parameters
nodestringtokenCancellationToken
Returns ValueTask
#HandleNodeStart(string, CancellationToken)
public async ValueTask HandleNodeStart(string node, CancellationToken token)Parameters
nodestringtokenCancellationToken
Returns ValueTask
#HandleOptions(OptionSet, CancellationToken)
public async ValueTask<int> HandleOptions(OptionSet options, CancellationToken token)Parameters
optionsYarn.OptionSettokenCancellationToken
Returns ValueTask
#InvokeFunction(string, IConvertible[], CancellationToken)
public async ValueTask<IConvertible> InvokeFunction(string functionName, IConvertible[] parameters, CancellationToken token)Parameters
functionNamestringparametersIConvertible[]tokenCancellationToken
Returns ValueTask
#LoadStateFromPersistentStorage(string)
public bool LoadStateFromPersistentStorage(string saveFileName)Parameters
saveFileNamestringthe name the save file should have on disc, including any file extension
Returns Boolean: true if the variables were successfully
loaded from the player preferences; false
otherwise.
This method loads the file saveFileName from the
persistent data storage and attempts to read it as JSON. This is
then deserialised and loaded into the VariableStorage.
The loaded information can be stored via the SaveStateToPersistentStorage(string) method.
#PrepareForLines(List<string>, CancellationToken)
public async ValueTask PrepareForLines(List<string> lineIDs, CancellationToken token)Parameters
lineIDsList<string>tokenCancellationToken
Returns ValueTask
#RemoveCommandHandler(string)
public void RemoveCommandHandler(string commandName);Parameters
commandNamestringThe name of the command to remove.
#RemoveFunction(string)
public void RemoveFunction(string name);Parameters
namestringThe name of the function to remove.
After a function has been removed, it cannot be called from Yarn scripts.
This does not impact the compiled Yarn program, only the runtime actions. The Yarn VM will still attempt to call the function when it encounters it, likely resulting in an exception being thrown. In general you should only remove functions if you know they won't be needed.
See also
#RemovePresenter(DialoguePresenterBase)
public bool RemovePresenter(DialoguePresenterBase presenter)Parameters
presenterYarn.Unity.DialoguePresenterBasethe presenter to remove
Returns Boolean: true if the presenter was in the collection, false otherwise
#RequestHurryUpContent()
public void RequestHurryUpContent()The specific behaviour of what happens when this method is called depends on the implementation of the Dialogue Runner's current dialogue presenters.
If the dialogue runner is not currently running dialogue this method has no effect.
#RequestHurryUpLine() Obsolete
This method has been superceded by RequestHurryUpContent and now forwards calls to that
public void RequestHurryUpLine()#RequestHurryUpOption() Obsolete
This method has been superceded by RequestHurryUpContent and now forwards calls to that
public void RequestHurryUpOption()#RequestNextContent()
public void RequestNextContent()The specific behaviour of what happens when this method is called depends on the implementation of the Dialogue Runner's current dialogue presenters.
If the dialogue runner is not currently running dialogue at all, this method has no effect.
#RequestNextLine() Obsolete
This method has been superceded by RequestNextContent and now forwards calls to that
public void RequestNextLine()#RunDialogue(string, CancellationToken)
public async YarnTask RunDialogue(string nodeName, CancellationToken cancellationToken = default)Parameters
nodeNamestringThe name of the node to run.cancellationTokenCancellationToken
Returns YarnTask
nodeName must be the name of a node in YarnProject.This task that starts will run the entire duration of the dialogue. Essentially this task will only complete once the dialogue ends or Stop() is called.
#SaveStateToPersistentStorage(string)
public bool SaveStateToPersistentStorage(string saveFileName)Parameters
saveFileNamestringthe name the save file should have on disc, including any file extension
Returns Boolean: true if the variables were successfully
written into the player preferences; false
otherwise.
This method attempts to writes the contents of VariableStorage as a JSON file and saves it to the
persistent data storage under the file name saveFileName. The saved information can be loaded via the
LoadStateFromPersistentStorage(string) method.
If saveFileName already exists, it will be
overwritten, not appended.
#SetProject(YarnProject)
public void SetProject(YarnProject project)Parameters
projectYarn.Unity.YarnProjectThe new YarnProject to be used.
Exceptions
System.InvalidOperationExceptionThrown when attempting to set a new project while a dialogue is currently running.
true), an System.InvalidOperationException is thrown.#SplitCommandText(string)
public static IEnumerable<string> SplitCommandText(string input)Parameters
inputstringThe string to split.
Returns IEnumerable: A collection of sub-strings.
System.String.Split(System.Char[],System.StringSplitOptions) method with the System.StringSplitOptions parameter set to System.StringSplitOptions.RemoveEmptyEntries, with the following
differences:- Text that appears inside a pair of double-quote characters will not be split.
- Text that appears after a double-quote character and before the end of the input will not be split (that is, an unterminated double-quoted string will be treated as though it had been terminated at the end of the input.)
- When inside a pair of double-quote characters, the string
\\will be converted to\, and the string\"will be converted to".
#StartDialogue(string) Obsolete
This method kicks off dialogue but doesn't await it's completion. Prefer RunDialogue where possible
public void StartDialogue(string nodeName)Parameters
nodeNamestringThe node to start dialogue from
This method asks the runner to begin dialogue and then returns immediately. This means your presenters may not yet have been told that dialogue has started by the time this method finishes.
Where possible we recommend that you initiate dialogue with RunDialogue(string,CancellationToken) which holds until the dialogue finishes entirely before returning.
#Stop()
public async YarnTask Stop()Returns YarnTask
Generated from Yarn Spinner for Unity 3.3.