Advertisement
Guest User

Untitled

a guest
Dec 11th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. /*
  2. *
  3. * Adventure Creator
  4. * by Chris Burton, 2013-2020
  5. *
  6. * "ActionTemplate.cs"
  7. *
  8. * This is a blank action template.
  9. *
  10. */
  11. using System.Collections;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. using UnityEngine.UI;
  15. #if UNITY_EDITOR
  16. using UnityEditor;
  17. #endif
  18.  
  19. namespace AC
  20. {
  21.  
  22. [System.Serializable]
  23. public class ActionChangeEmotionAnimation: Action
  24. {
  25.  
  26. // Declare variables here
  27.  
  28. public string[] options = new string[] { "Angry", "Sad", "Loopy", "Romantic", "Neutral"};
  29. public int index = 0;
  30. Animator m_Animator;
  31. GameObject Animator;
  32.  
  33. public int constantID;bool isLoopy;
  34. bool isAngry;
  35. bool isHappy;
  36. bool isSad;
  37. bool isRomantic;
  38.  
  39. public ActionChangeEmotionAnimation ()
  40. {
  41. this.isDisplayed = true;
  42. category = ActionCategory.Custom;
  43. title = "Change Emotion Animation";
  44. description = "Choose an emotion animation and it'll turn off all the others.";
  45. }
  46.  
  47.  
  48. override public float Run()
  49. {
  50. /*
  51. * This function is called when the action is performed.
  52. *
  53. * The float to return is the time that the game
  54. * should wait before moving on to the next action.
  55. * Return 0f to make the action instantenous.
  56. *
  57. * For actions that take longer than one frame,
  58. * you can return "defaultPauseTime" to make the game
  59. * re-run this function a short time later. You can
  60. * use the isRunning boolean to check if the action is
  61. * being run for the first time, eg:
  62. */
  63.  
  64.  
  65. m_Animator = Animator.GetComponent<Animator>();
  66.  
  67. switch (index)
  68. {
  69. case 0:
  70. m_Animator.SetBool("isAngry", true);
  71. m_Animator.SetBool("isLoopy", false);
  72. m_Animator.SetBool("isSad", false);
  73. m_Animator.SetBool("isRomantic", false);
  74. m_Animator.SetBool("isHappy", false);
  75. break;
  76. case 1:
  77. m_Animator.SetBool("isAngry", false);
  78. m_Animator.SetBool("isLoopy", false);
  79. m_Animator.SetBool("isSad", true);
  80. m_Animator.SetBool("isRomantic", false);
  81. m_Animator.SetBool("isHappy", false);
  82. break;
  83. case 2:
  84. m_Animator.SetBool("isAngry", false);
  85. m_Animator.SetBool("isLoopy", true);
  86. m_Animator.SetBool("isSad", false);
  87. m_Animator.SetBool("isRomantic", false);
  88. m_Animator.SetBool("isHappy", false);
  89. break;
  90. case 3:
  91. m_Animator.SetBool("isAngry", false);
  92. m_Animator.SetBool("isLoopy", false);
  93. m_Animator.SetBool("isSad", false);
  94. m_Animator.SetBool("isRomantic", true);
  95. m_Animator.SetBool("isHappy", false);
  96. break;
  97. case 4:
  98. m_Animator.SetBool("isAngry", false);
  99. m_Animator.SetBool("isLoopy", false);
  100. m_Animator.SetBool("isSad", false);
  101. m_Animator.SetBool("isRomantic", false);
  102. m_Animator.SetBool("isHappy", true);
  103. break;
  104. default:
  105. Debug.LogError("Unrecognized Option");
  106. break;
  107. }
  108.  
  109.  
  110. return 0f;
  111. }
  112.  
  113.  
  114.  
  115. public override void Skip ()
  116. {
  117. /*
  118. * This function is called when the Action is skipped, as a
  119. * result of the player invoking the "EndCutscene" input.
  120. *
  121. * It should perform the instructions of the Action instantly -
  122. * regardless of whether or not the Action itself has been run
  123. * normally yet. If this method is left blank, then skipping
  124. * the Action will have no effect. If this method is removed,
  125. * or if the Run() method call is left below, then skipping the
  126. * Action will cause it to run itself as normal.
  127. */
  128.  
  129. Run ();
  130. }
  131.  
  132. override public void AssignValues ()
  133. {
  134. Animator = AssignFile(constantID, Animator);
  135. }
  136.  
  137.  
  138. #if UNITY_EDITOR
  139.  
  140. public override void ShowGUI ()
  141. {
  142. Animator = (GameObject)EditorGUILayout.ObjectField("NPC",Animator, typeof(Object), true);
  143. index = EditorGUILayout.Popup("Emotion",index, options);
  144. constantID = FieldToID(Animator, constantID);
  145. Animator = IDToField(Animator, constantID, true);
  146.  
  147.  
  148. AfterRunningOption ();
  149. }
  150.  
  151.  
  152. public override string SetLabel ()
  153. {
  154. // (Optional) Return a string used to describe the specific action's job.
  155.  
  156. return string.Empty;
  157. }
  158.  
  159. #endif
  160.  
  161. }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement