Skip to content

mushakushi/yarn-spinner-utility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yarn Spinner

License: MIT

Utilities for Yarn Spinner. The motivation for creating this is to be a replacement for the default dialogue output that comes with the Unity integration, which is, arguably, too opinionated and tightly coupled.

⚙ Installation

With UPM

from the Add package from git URL option, enter:

https://github.com/mushakushi/yarn-spinner-utility.git?path=Assets/YarnSpinnerUtility

If you are specifying a version, append #{VERSION} to the end of the git URL.

https://github.com/mushakushi/yarn-spinner-utility.git?path=Assets/YarnSpinnerUtility#{VERSION}

Git Dependencies

🚀 Usage

Dialogue Parser

A modified version of Yarn's Minimal Dialogue Runner that allows further separation of concerns using the Scriptable Object observer pattern and makes no assumptions about how the game will be run. Because of this, it can work across scenes using a DialogueObserver.

View Controllers

For the recommended setup for displaying dialogue lines and options, see the OptionViewController and LineViewController classes, respectively.

Views

Modify its views in the inspector, which is recalculated on each dialogue line and removed when the dialogue is completed.

You can create a new view by marking any class that inherits from IView with the [System.Serializable] attribute.

[System.Serializable] public class View: IView

Command Handling

You can handle commands as you'd usually do by using YarnCommandDispatcher.AddCommandHandler. The dialogue is must be continued manually after the command is handled.

public class ExampleCommandHandler: MonoBehaviour
{
    [SerializeField] private YarnCommandDispatcher commandDispatcher;

    private void Start()
    {
        // Please note that the "wait" command is the only command
        // that is handled for you. 
        commandDispatcher.AddCommandHandler<float>("wait", HandleWaitCommand);
    }

    private void HandleWaitCommand(float waitDuration)
    {
        // handle the command ...
        // the continue the dialogue (note: this can be done asynchronously)
        commandDispatcher.dialogueParser.TryContinue();
    }
}