Loading and Executing in Unity

Loading Scripts

  • Use Unity standard systems like AssetDatabase, Resources, external paths, or remote servers

  • Integrate into MonoBehaviour components or custom managers

Interpreting and Executing

  • Use DSL Forge’s Interpreter module

  • Convert text or Assets into executable Flows

  • Supports async execution, perfect for tasks, dialogues, or event systems

Integrating with Game Systems

  • Call flows from quest managers, dialogue systems, or event systems

  • Dynamically update game state, trigger events, or modify variables

// Assigned in the Inspector
public DSLScriptAsset dslAsset;

// Called from a MonoBehaviour
async void Start()
{
    var interpreter = new DSLInterpreter();

    // Parse the script text from the Asset into flows
    var flows = DSLFlowGenerator.GenerateFlows(dslAsset.scriptText);
    interpreter.SetFlows(flows);

    // Execute a specific flow (e.g. @Init)
    if (flows.TryGetValue("@Init", out var initFlow))
    {
        await interpreter.ExecuteFlow(initFlow);
    }
}
  • DSLScriptAsset is a custom ScriptableObject that stores your DSL text

  • DSLFlowGenerator.GenerateFlows parses text into a dictionary of flows

  • interpreter.SetFlows registers the flows with the interpreter

  • ExecuteFlow is an async method, making it easy to handle tasks, dialogues, or events

Last updated