1. Conventions
1.1 Namespaces and reference assembly
The namespaces listed in the following table belong to the engine assembly.
| Namespace | Content |
|---|---|
MySys22.Engine.API | static facade Dialogue, IDialogueView — game usage namespace |
MySys22.DialogueEngine | GameSetup, DialogueBridge |
MySys22.DialogueEngine.Core | data, loading, actions, variables, quests, position |
MySys22.DialogueEngine.UI | DialogueUICanvas, DialogueOverlayUI |
MySys22.DialogueEngine.Audio | DialogueAudio, IDialogueAudioProvider |
Reference rule: game code uses Dialogue.*; the Core namespaces are used to extend the engine.
1.2 Naming conventions
- Action identifiers are strings declared in the
[DialogueAction("Id")]attribute; the identifier value is the value reported in the Function node of the graph.
- The serialized fields of the components (
GameSetup,DialogueBridge,DialogueUICanvas,DialogueOverlayUI) are named with the_prefix.
- The members exposed by the static facade
Dialoguecorrespond to the members of the activeDialogueBridge; the facade and the component adopt the same naming.
- Diagnostic codes are three-digit numeric values, reported in square brackets in the message.
1.3 Error handling
- Message logging is centralized in
DialogueLogger. Qualified error messages use the formDialogueLogger.LogError(code, description, detail = null), with code[3xx].
- The evaluation of an invalid expression produces the log
[324]and the return valuefalse.
- Project validation is exposed by
Validate(), which returns aDialogueProjectValidator.Reportwith theErrors,Warnings,Infoscollections and theNodesChecked,LinesCheckedcounters.
1.4 Threading model
- The execution of actions occurs on the Unity main thread.
- The asynchronous work inside an action is expressed by means of
ExecuteAsync(DialogueActionContext context, CancellationToken cancellationToken).
Cancel()is invoked when the dialogue stops or changes node.
- On the mobile platform, initialization requires
InitializeAsync();Initialize()is synchronous and is intended for desktop.
Reload()is asynchronous on the mobile platform.
1.5 Initialization preconditions
- The active bridge is resolved automatically by
Dialogue.Bridge; explicit setting is performed by means ofDialogue.SetBridge(DialogueBridge).
- Adding
GameSetupto the scene initializes the engine and starts the dialogue; in the absence ofGameSetup,DialogueBridgeinitializes itself.
StartDialogue()may also be invoked before initialization completes: under that condition the start is deferred.
- The loaded data (
Project,Graph,GraphPath,Manifest) are available after initialization.
2. Startup and lifecycle
2.1 Startup by means of components
Adding the GameSetup component to the scene causes complete initialization of the engine and the start of the dialogue. The presence of GameSetup excludes double starts, since the start is managed by the component itself.
2.2 Startup by means of code
The following example subscribes to the bridge events and starts the dialogue.
using MySys22.Engine.API;
public class MyGame : MonoBehaviour
{
void Start()
{
Dialogue.Bridge.OnLine += (speaker, text) => Debug.Log($"{speaker}: {text}");
Dialogue.Bridge.OnChoices += choices => Dialogue.Bridge.Choose(0);
Dialogue.Bridge.OnDialogueEnd += () => Debug.Log("done");
Dialogue.Bridge.StartDialogue();
}
}
2.3 Lifecycle sequence
The expected sequence is the following:
- Initialization of the bridge by means of
Initialize()orInitializeAsync().
- Loading of the data:
Project,Graph,GraphPath,Manifest.
- Start of the dialogue by means of
StartDialogue().
- Advancement by means of
Continue()or selection of an option by means ofChoose(int index).
- Stop by means of
StopDialogue(), restart by means ofRestart(), reload by means ofReload().