Custom Nodes
Discourse comes packed with just about everything you’d need to get a dialogue or cutscene event up and running, but it can’t handle everything - you might want to hook into the specifics of your game. That’s where custom nodes come in.
Creating a custom node:
- Create a Custom Action.
- Create a new class inside an Editor folder (typically, Node class names are prefaced with ‘Node’).
- Inherit the class from
Node
. - Make sure you include
using Montebearo.Discourse.Editor;
at the top of the file. - Override the ActionType property to point to
typeof(YourCustomAction)
- That’s it! Just open the Search Widget and it’ll appear under Custom/YourCustomAction.
Example:
using System;
using Montebearo.Discourse.Editor;
public class NodeCustomAction : Node
{
protected override Type ActionType => typeof(CustomAction).
}
Note: Typically, you will want to add a pass-through property for your Action that casts it to the appropriate type. This is useful if you want to pass a property of your Action into the Subtitle of your node, for instance. To do this, you will need to cast the ‘EmbeddedAction’ field. For example:
private CustomAction MyCustomAction => EmbeddedAction as CustomAction;
Changing the appearance of your Node
To change the appearance of your node, such as its dimensions, tab colour or whether its title should appear on its body, you must override the SettingsTemplate
property to point to a new NodeSettings
struct. Don’t worry about caching this, that’s taken care of behind the scenes.
In this example, we’ll just override the colour:
using System;
using Montebearo.Discourse.Editor;
public class NodeCustomAction : Node
{
protected override Type ActionType => typeof(CustomAction).
protected override NodeSettings SettingsTemplate => new NodeSettings(new Colour(0.35f, 0.65f, 0.75f));
}
Changing the Title and Subtitle of the Node
The Title of a node is the text that will appear in bold at the top of the Node’s body, whereas the Subtitle is a smaller line at the bottom of the body, used to summarise the state of that Action. Both the Title and Subtitle can be overridden. For example, in the Speech node the Title is used to indicate the Speaker of that line, and the Subtitle shows a preview of its text.
Here we override Title and Subtitle:
using System;
using Montebearo.Discourse.Editor;
public class NodeCustomAction : Node
{
protected override Type ActionType => typeof(CustomAction).
protected override NodeSettings SettingsTemplate => new NodeSettings(new Colour(0.35f, 0.65f, 0.75f));
protected override string Title => "New Title!";
protected override string Subtitle => "Some Subtitle..."
}