Advertisement
KaiClavier

SuperTextMeshWriter.cs quickfix

Nov 14th, 2019
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.56 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System;
  7. using System.Reflection;
  8.  
  9. namespace Fungus
  10. {
  11.     public class SuperTextMeshWriter : Writer
  12.     {
  13.        
  14.         new protected SuperTextAdapter textAdapter;
  15.         protected SuperTextMesh superText;
  16.  
  17.         protected string lastText = "";
  18.  
  19.         [Tooltip("Extra delay in seconds if it's not waiting for input.")]
  20.         public float extraDelay = 0.5f;
  21.  
  22.         [HideInInspector]
  23.         public SuperSayDialog.DisappearMode disappearMode;
  24.  
  25.         public SuperTextMesh getSuperText() {
  26.            
  27.             if (superText != null)
  28.                 return superText;
  29.            
  30.             if (targetTextObject != null)
  31.             {
  32.                 superText = targetTextObject.GetComponent<SuperTextMesh>();
  33.                
  34.                 return superText;
  35.             }
  36.             superText = GetComponentInChildren<SuperTextMesh>();
  37.            
  38.             return superText;
  39.         }
  40.  
  41.         protected override void Awake()
  42.         {
  43.             GameObject go = targetTextObject;
  44.             if (go == null)
  45.             {
  46.                 go = gameObject;
  47.             }
  48.  
  49.             textAdapter.InitFromGameObject(go);
  50.  
  51.             // Cache the list of child writer listeners
  52.             foreach (Component component in GetComponentsInChildren<Component>())
  53.             {
  54.                 IWriterListener writerListener = component as IWriterListener;
  55.                 if (writerListener != null)
  56.                 {
  57.                     writerListeners.Add(writerListener);
  58.                 }
  59.             }
  60.         }
  61.  
  62.         protected override void Start()
  63.         {
  64.            
  65.         }
  66.         /*
  67.         public override bool HasTextObject()
  68.         {
  69.             return (textUI != null || inputField != null || textMesh != null || textComponent != null || superText != null);
  70.         }
  71.         */
  72.        
  73. /*
  74.         public override void SetTextColor(Color textColor)
  75.         {
  76.             textAdapter.SetTextColor(textColor);
  77.         }
  78.        
  79.         public override void SetTextAlpha(float textAlpha)
  80.         {
  81.             textAdapter.SetTextAlpha(textAlpha);
  82.         }
  83. */
  84.  
  85.         public override IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, bool waitForVO, AudioClip audioClip, Action onComplete)
  86.         {
  87.  
  88.             if (!textAdapter.HasTextObject())
  89.             {
  90.                 yield break;
  91.             }
  92.  
  93.             isWriting = true;
  94.  
  95.             gameObject.SetActive(true);
  96.  
  97.            
  98.            
  99.            
  100.             NotifyStart(audioClip);
  101.  
  102.             UnityAction action = null;
  103.             UnityAction action2 = null;
  104.  
  105.             if (disappearMode == SuperSayDialog.DisappearMode.fadeOnly)
  106.             {
  107.                 action = () =>
  108.                 {
  109.                     superText.onCompleteEvent.RemoveListener(action2);
  110.                     isWriting = false;
  111.                     onComplete();
  112.                 };
  113.             }
  114.             else
  115.             {
  116.                 //it starts fading when isWriting is false, so we might need to postpone that until the undraw is complete
  117.                 action = () =>
  118.                 {
  119.                     superText.onCompleteEvent.RemoveListener(action2);
  120.                     action2 = () =>
  121.                     {
  122.                         isWriting = false;
  123.                         onComplete();
  124.                     };
  125.                     superText.onUndrawnEvent.AddListener(action2);
  126.                     superText.UnRead();
  127.                    
  128.                    
  129.                 };
  130.             }
  131.  
  132.  
  133.  
  134.             if (waitForInput)
  135.             {
  136.                 action2 = () =>
  137.                 {
  138.                     StartCoroutine(DoWaitForInputOnComplete(clear, action));
  139.                 };
  140.                 superText.onCompleteEvent.AddListener(action2);
  141.                 //superText.onUndrawnEvent.AddListener(action2);
  142.  
  143.             }
  144.             else
  145.             {
  146.                 action2 = () =>
  147.                 {
  148.                     StartCoroutine(DoWaitForTimeOnComplete(clear, action));
  149.                 };
  150.                 superText.onCompleteEvent.AddListener(action2);
  151.                 //superText.onCompleteEvent.AddListener(action);
  152.             }
  153.  
  154.             if (clear)
  155.             {
  156.                 superText.Text = content;
  157.                 //superText.Rebuild();
  158.             }
  159.             else
  160.             {
  161.                 superText.Append(content);
  162.             }
  163.            
  164.            
  165.            
  166.  
  167.         }
  168.        
  169.  
  170. /*      public override string GetTagHelp()
  171.         {
  172.             return "";
  173.         }*/
  174.  
  175.  
  176.  
  177.  
  178.         protected virtual IEnumerator DoWaitForTimeOnComplete(bool clear, UnityAction onComplete)
  179.         {
  180.             NotifyPause();
  181.  
  182.             yield return new WaitForSeconds(extraDelay);
  183.  
  184.             if (clear)
  185.             {
  186.                 //superText.text = "";
  187.             }
  188.  
  189.             NotifyResume();
  190.             onComplete();
  191.         }
  192.  
  193.         protected virtual IEnumerator DoWaitForInputOnComplete(bool clear, UnityAction onComplete)
  194.         {
  195.             NotifyPause();
  196.  
  197.             inputFlag = false;
  198.             isWaitingForInput = true;
  199.  
  200.            
  201.             while (!inputFlag && !exitFlag)
  202.             {
  203.                 yield return null;
  204.             }
  205.  
  206.             isWaitingForInput = false;
  207.             inputFlag = false;
  208.  
  209.             if (clear)
  210.             {
  211.                 //superText.text = "";
  212.             }
  213.  
  214.             NotifyResume();
  215.             onComplete();
  216.         }
  217.  
  218.  
  219.         public override void OnNextLineEvent()
  220.         {
  221.            
  222.             inputFlag = true;
  223.             superText.SkipToEnd();
  224.  
  225.             if (isWriting)
  226.             {
  227.                 NotifyInput();
  228.             }
  229.         }
  230.        
  231.     }
  232.  
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement