KaiClavier

STMDrawstring.cs

Dec 13th, 2019
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Copyright (c) 2019 Kai Clavier [kaiclavier.com] Do Not Distribute
  2. using UnityEngine;
  3. using System.Collections;
  4. using Fleece;
  5.  
  6. public class STMDrawstring : MonoBehaviour {
  7.  
  8.     private Drawstring drawstring = new Drawstring(); //used for managing dialogue trees
  9.     public Jumper startPassageRef; //works as a reference to the starting passage
  10.     public SuperTextMesh stm;
  11.  
  12.     //subscribe and unsubscrbe to STM's OnCompleteEvent
  13.     void OnEnable()
  14.     {
  15.         stm.OnCompleteEvent += TextIsDoneReading;
  16.     }
  17.     void OnDisable()
  18.     {
  19.         stm.OnCompleteEvent -= TextIsDoneReading;
  20.     }
  21.  
  22.     public void TextIsDoneReading()
  23.     {
  24.         if(drawstring.passage != null)
  25.         {
  26.         //This can be used to invoke...
  27.         //drawstring.GetChoices()
  28.         //when STM is done reading!
  29.             Debug.Log(drawstring.GetChoices().Length);
  30.         }
  31.     }
  32.    
  33.     [ContextMenu("Begin")]
  34.     public void Begin()
  35.     {
  36.         //start at default passage
  37.         Begin(startPassageRef.passage);
  38.     }
  39.     public void Begin(Passage passage)
  40.     {
  41.         //start at specified passage
  42.         stm.text = drawstring.Begin(passage);
  43.     }
  44.     [ContextMenu("Continue")]
  45.     public void Continue()
  46.     {
  47.         stm.text = drawstring.Continue(); //
  48.     }
  49. }
RAW Paste Data