Advertisement
MrKeks

Character speech gesture custom action

Mar 13th, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. namespace AC
  7. {
  8.     public class ActionPlayCharacterGesture : Action
  9.     {
  10.         public int AssociatedSpeechID;        
  11.         public string Clip;
  12.         public int MecanimLayer;
  13.         public float Delay;
  14.  
  15.         public override ActionCategory Category { get { return ActionCategory.Character; } }
  16.         public override string Title { get { return "Play Gesture"; } }
  17.         public override string Description { get { return "Plays gesture animation."; } }
  18.  
  19.         override public float Run()
  20.         {
  21.             CoroutineController.Start(Gesture(AssociatedSpeechID, Clip, MecanimLayer, Delay));
  22.             return 0;
  23.         }
  24.  
  25.         IEnumerator Gesture(int associatedSpeechID, string clip, int mecanimLayer, float delay)
  26.         {
  27.             yield return new WaitForSeconds(delay);
  28.  
  29.             Speech speech = KickStarter.dialog.GetLiveSpeechWithID(associatedSpeechID);
  30.             if (speech is null) yield break;
  31.  
  32.             speech.speaker.GetAnimator().Play(clip, mecanimLayer);
  33.         }
  34.  
  35.         #if UNITY_EDITOR
  36.         override public void ShowGUI(List<ActionParameter> parameters)
  37.         {
  38.             AssociatedSpeechID = EditorGUILayout.IntField("Associated Speech ID:", AssociatedSpeechID);
  39.             Clip = EditorGUILayout.TextField("Clip:", Clip);
  40.             MecanimLayer = EditorGUILayout.IntField("Mecanim Layer:", MecanimLayer);
  41.             Delay = EditorGUILayout.FloatField("Delay:", Delay);
  42.         }
  43.         #endif
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement