diff --git a/Docs/Docs.mdproj b/Docs/Docs.mdproj index 4ae4c537..2c0fd870 100644 --- a/Docs/Docs.mdproj +++ b/Docs/Docs.mdproj @@ -299,5 +299,6 @@ + \ No newline at end of file diff --git a/Docs/fungus_docs/coding_tips.md b/Docs/fungus_docs/coding_tips.md new file mode 100644 index 00000000..eb8ec080 --- /dev/null +++ b/Docs/fungus_docs/coding_tips.md @@ -0,0 +1,95 @@ +# Coding Tips # {#coding_tips} +[TOC] + +This is a collection of quick tips for scripting %Fungus from code. + +# Executing Blocks # {#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 # {#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 # {#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"); + } + } +} +``` + diff --git a/Docs/top_pages/mainpage.md b/Docs/top_pages/mainpage.md index 77f12af4..d27a37d3 100644 --- a/Docs/top_pages/mainpage.md +++ b/Docs/top_pages/mainpage.md @@ -16,6 +16,7 @@ There's a wide range of training material available here, suitable for both begi * @subpage conversation_system * @subpage community_tutorials * @subpage narrative_text_tags +* @subpage coding_tips * @subpage glossary * @subpage faq * @subpage changelog