ArtTaskAction.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using BeinLab.Util;
  2. using ShadowStudio.Model;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using XRTool.Util;
  7. using static ArtTaskInfo;
  8. public class ArtTaskAction : MonoBehaviour
  9. {
  10. public ArtContainerHandler artContainerHandler;
  11. /// <summary>
  12. /// 资源类型,后续扩展
  13. /// </summary>
  14. public enum ArtActionType
  15. {
  16. /// <summary>
  17. /// 未完成
  18. /// </summary>
  19. WAIT = -1,
  20. /// <summary>
  21. /// 未完成
  22. /// </summary>
  23. ACTION = 0,
  24. /// <summary>
  25. /// 完成
  26. /// </summary>
  27. FINISH = 1,
  28. }
  29. public ArtActionType aaType;
  30. public TaskType ttype;
  31. public GameObject actionGame;
  32. public GameObject startAction;
  33. public GameObject Action;
  34. public GameObject finishAction;
  35. public GameObject endAction;
  36. public GameObject playBt;
  37. public GameObject effect;
  38. public GameObject Tip1;
  39. public GameObject TipError;
  40. private void OnDestroy()
  41. {
  42. ArtTaskInfo.removeTask(this);
  43. }
  44. public void ShowTipError()
  45. {
  46. Action.GetComponentInChildren<Animator>().enabled = false;
  47. Tip1.SetActive(false);
  48. TipError.SetActive(true);
  49. TimerMgr.Instance.CreateTimer(() => {
  50. Tip1.SetActive(true);
  51. TipError.SetActive(false);
  52. }, 3f);
  53. }
  54. public void showPlayBt(bool isShow)
  55. {
  56. if(CommonMethod.isLookRoom())
  57. {
  58. playBt.SetActive(false);
  59. }
  60. else
  61. {
  62. playBt.SetActive(isShow);
  63. }
  64. }
  65. private void Start()
  66. {
  67. if(!isInit)
  68. {
  69. // initAction();
  70. setType(ArtActionType.WAIT);
  71. showPlayBt(true);
  72. }
  73. ArtTaskInfo.addTask(this);
  74. }
  75. BoxCollider box;
  76. private void initAction()
  77. {
  78. box = playBt.GetComponentInChildren<BoxCollider>();
  79. startAction.GetComponentInChildren<Animator>().enabled = false;
  80. startAction.SetActive(true);
  81. Action.SetActive(false);
  82. finishAction.SetActive(false);
  83. endAction.SetActive(false);
  84. TimerMgr.Instance.CreateTimer(() => {
  85. box.enabled = true;
  86. }, 1f);
  87. }
  88. public void playAction()
  89. {
  90. effect.SetActive(false);
  91. startAction.GetComponentInChildren<Animator>().enabled = true;
  92. startAction.SetActive(true);
  93. Action.SetActive(false);
  94. finishAction.SetActive(false);
  95. endAction.SetActive(false);
  96. TimerMgr.Instance.CreateTimer(() => {
  97. showPlayBt(true);
  98. effect.SetActive(true);
  99. }, 8f);
  100. showPlayBt(false);
  101. }
  102. public void playStartAction()
  103. {
  104. showPlayBt(false);
  105. if (!startAction.GetComponentInChildren<Animator>().enabled)
  106. {
  107. artContainerHandler.ArtState("task", "Play");
  108. playAction();
  109. }
  110. else
  111. {
  112. StartAction();
  113. artContainerHandler.ArtState("task", "start");
  114. }
  115. }
  116. private void setType(ArtActionType tp)
  117. {
  118. Debug.Log("setType"+tp);
  119. aaType = tp ;
  120. }
  121. public void StartAction()
  122. {
  123. showPlayBt(false);
  124. effect.SetActive(false);
  125. startAction.SetActive(false);
  126. Action.SetActive(true);
  127. finishAction.SetActive(false);
  128. endAction.SetActive(false);
  129. setType(ArtActionType.ACTION);
  130. }
  131. public void showStartAction(bool isSend = false)
  132. {
  133. showPlayBt(false);
  134. startAction.SetActive(true);
  135. Action.SetActive(false);
  136. finishAction.SetActive(false);
  137. endAction.SetActive(false);
  138. }
  139. public void showFinishAction(bool isSend = false)
  140. {
  141. showPlayBt(false);
  142. startAction.SetActive(false);
  143. Action.SetActive(false);
  144. finishAction.SetActive(true);
  145. endAction.SetActive(false);
  146. StartCoroutine(checkFinish(isSend));
  147. if (isSend)
  148. artContainerHandler.ArtState("task", "finish");
  149. setType(ArtActionType.FINISH);
  150. }
  151. IEnumerator checkFinish(bool isSend = false)
  152. {
  153. yield return new WaitForSeconds(0.5f);
  154. AnimatorStateInfo animatorStateInfo = finishAction.GetComponentInChildren<Animator>().GetCurrentAnimatorStateInfo(0);
  155. // 判断动画是否播放完成
  156. if (animatorStateInfo.normalizedTime >= 1.0f)
  157. {
  158. showEndAction(isSend);
  159. }
  160. else
  161. {
  162. StartCoroutine(checkFinish(isSend));
  163. }
  164. }
  165. public void showEndAction(bool isSend=false)
  166. {
  167. showPlayBt(false);
  168. startAction.SetActive(false);
  169. Action.SetActive(false);
  170. finishAction.SetActive(false);
  171. endAction.SetActive(true);
  172. if(isSend)
  173. artContainerHandler.ArtState("task", "end");
  174. }
  175. private bool isInit;
  176. public void showType(string type)
  177. {
  178. switch (type)
  179. {
  180. case "start":
  181. StartAction();
  182. break;
  183. case "finish":
  184. showFinishAction();
  185. break;
  186. case "end":
  187. showEndAction();
  188. break;
  189. case "Play":
  190. playAction();
  191. break;
  192. }
  193. isInit = true;
  194. }
  195. }