KaiClavier

SuperSayDialog.cs quickfix

Nov 14th, 2019
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using Fungus;
  4. using System;
  5.  
  6. public class SuperSayDialog : SayDialog {
  7.  
  8.     public enum DisappearMode { fadeOnly, undrawThenFade, undrawOnly }
  9.  
  10.     public DisappearMode disappearMode;
  11.  
  12.     protected bool undrawWhenDone=false;
  13.  
  14.     protected SuperTextMeshWriter superWriter;
  15.  
  16.     protected SuperTextMeshWriter GetSuperWriter()
  17.     {
  18.         GetWriter();
  19.         if (superWriter != null)
  20.         {
  21.             return superWriter;
  22.         }
  23.        
  24.         superWriter = GetComponent<SuperTextMeshWriter>();
  25.        
  26.         if (writer == null)
  27.         {
  28.             superWriter = gameObject.AddComponent<SuperTextMeshWriter>();
  29.         }
  30.         writer = superWriter;
  31.  
  32.         return superWriter;
  33.     }
  34.  
  35.  
  36.     public override IEnumerator DoSay(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, bool waitForVO, AudioClip voiceOverClip, Action onComplete)
  37.     {
  38.         SuperTextMeshWriter writer = GetSuperWriter();
  39.  
  40.         if (writer.IsWriting || writer.IsWaitingForInput)
  41.         {
  42.             writer.Stop();
  43.             while (writer.IsWriting || writer.IsWaitingForInput)
  44.             {
  45.                 yield return null;
  46.             }
  47.         }
  48.  
  49.         switch (disappearMode)
  50.         {
  51.             case DisappearMode.fadeOnly:
  52.                 this.fadeWhenDone = fadeWhenDone;
  53.                 undrawWhenDone = false;
  54.                 break;
  55.             case DisappearMode.undrawOnly:
  56.                 undrawWhenDone = fadeWhenDone;
  57.                 this.fadeWhenDone = false;
  58.                 break;
  59.             case DisappearMode.undrawThenFade:
  60.                 undrawWhenDone = fadeWhenDone;
  61.                 this.fadeWhenDone = fadeWhenDone;
  62.                 break;
  63.         }
  64.         writer.disappearMode = disappearMode;
  65.        
  66.  
  67.         // Voice over clip takes precedence over a character sound effect if provided
  68.  
  69.         AudioClip soundEffectClip = null;
  70.         if (voiceOverClip != null)
  71.         {
  72.             WriterAudio writerAudio = GetWriterAudio();
  73.             writerAudio.OnVoiceover(voiceOverClip);
  74.         }
  75.         else if (speakingCharacter != null)
  76.         {
  77.            
  78.             CharacterSuperAudio charSuper =  speakingCharacter.gameObject.GetComponent<CharacterSuperAudio>();
  79.             SuperTextMesh superText = GetComponent<SuperTextMeshWriter>().getSuperText();
  80.             if (charSuper != null && superText!=null)
  81.             {
  82.                 setSuperAudioFromCharacter(superText,charSuper);
  83.             }
  84.             else
  85.             {
  86.                 text = "<v=" + speakingCharacter.name + ">" + text;
  87.                 //soundEffectClip = speakingCharacter.soundEffect;
  88.             }
  89.         }
  90.         StartCoroutine(writer.Write(text, clearPrevious, waitForInput, stopVoiceover, waitForVO, soundEffectClip, onComplete));
  91.  
  92.     }
  93.  
  94.     //Gets properties from charSuper and applies them to the SuperTextMesh
  95.     public static void setSuperAudioFromCharacter(SuperTextMesh stm, CharacterSuperAudio charSuper)
  96.     {
  97.         stm.audioClips = charSuper.audioClips;
  98.         stm.stopPreviousSound = charSuper.stopPreviousSound;
  99.         stm.minPitch = charSuper.minPitch;
  100.         stm.maxPitch = charSuper.maxPitch;
  101.     }
  102. }
Add Comment
Please, Sign In to add comment