You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.9 KiB
1.9 KiB
Coding Tips
[TOC]
This is a collection of quick tips for scripting %Fungus from code.
Executing Blocks
You first need to get a reference to your flowchart object. Add a public Flowchart property to your component and set it to reference your flowchart in the inspector.
using UnityEngine;
using Fungus;
class MyComponent : public MonoBehaviour
{
public Flowchart flowchart;
}
To execute a named Block in the Flowchart:
flowchart.ExecuteBlock("BlockName");
To start execution at a specific command index:
flowchart.ExecuteBlock("BlockName", 3);
To tell if a Flowchart has any executing Blocks:
if (flowchart.HasExecutingBlocks())
{
// Do something
}
Block Signals
You can use the BlockSignals class to listen for events from the Block execution system.
using Fungus;
public MyComponent : MonoBehaviour
{
void OnEnable()
{
// Register as listener for Block events
BlockSignals.OnBlockStart += OnBlockStart;
}
void OnDisable()
{
// Unregister as listener for Block events
BlockSignals.OnBlockStart -= OnBlockStart;
}
void OnBlockStart(Block block)
{
Debug.Log("Block started " + block.BlockName);
}
}
Writer Signals
You can use the WriterSignals class to listen for a variety of events from the text writing system.
using Fungus;
public MyComponent : MonoBehaviour
{
void OnEnable()
{
// Register as listener for Writer state change events
WriterSignals.OnWriterState += OnWriterState;
}
void OnDisable()
{
// Unregister as listener for Writer state change events
WriterSignals.OnWriterState -= OnWriterState;
}
void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.Start)
{
Debug.Log("Writing started");
}
}
}