GuangkejiAnimator.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class GuangkejiAnimator : MonoBehaviour
  5. {
  6. public Animator anim;
  7. private float startTimer;
  8. private bool isStart;//动画是否开始播放
  9. public Animator Line;//线条动画组件
  10. public GameObject fanguang;//反光动画
  11. public GameObject[] textGamesLisr;
  12. private bool isLook;//是否看着对象
  13. private void Start()
  14. {
  15. //anim = this.GetComponent<Animator>();
  16. startTimer = 2f;
  17. ShowOrHeidGames(-1);
  18. }
  19. private void ShowOrHeidGames(int index)
  20. {
  21. for (int i = 0; i < textGamesLisr.Length; i++)
  22. {
  23. if (i == index)//如果等于传入的参数
  24. {
  25. PlaySounds(i);
  26. textGamesLisr[i].SetActive(true);
  27. //文字动画的三个动画组件
  28. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame").GetComponent<Animator>().Play("frame_Appear");
  29. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (2)").GetComponent<Animator>().Play("frame_Appear");
  30. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (1)").GetComponent<Animator>().Play("frame_Appear");
  31. }
  32. else
  33. {
  34. StartCoroutine(WaitForTiemrs(0.8f, textGamesLisr[i]));
  35. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame").GetComponent<Animator>().Play("frame_Disappear");
  36. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (2)").GetComponent<Animator>().Play("frame_Disappear");
  37. textGamesLisr[i].transform.Find("TP/Galaxy Renamer (1)/frame (1)").GetComponent<Animator>().Play("frame_Disappear");
  38. }
  39. }
  40. }
  41. /// <summary>
  42. /// 线条动画开始
  43. /// </summary>
  44. public void LineStart()
  45. {
  46. Line.gameObject.GetComponent<MeshRenderer>().enabled = true;//获取线条的组件
  47. Line.gameObject.GetComponent<Animator>().enabled = true;//获取线条动画的组件
  48. fanguang.gameObject.SetActive(true);
  49. Line.speed = 1;//播放动画
  50. }
  51. /// <summary>
  52. /// 线条动画暂停
  53. /// </summary>
  54. public void LineStop()
  55. {
  56. Line.gameObject.GetComponent<MeshRenderer>().enabled = false;
  57. Line.gameObject.GetComponent<Animator>().enabled = false;
  58. fanguang.gameObject.SetActive(false);
  59. Line.speed = 0;//暂停动画
  60. }
  61. /// <summary>
  62. /// 机械臂的动画开始
  63. /// </summary>
  64. public void AnimStart()
  65. {
  66. anim.speed = 1f;
  67. }
  68. /// <summary>
  69. /// 机械臂的动画停止
  70. /// </summary>
  71. public void AnimStop(int index)
  72. {
  73. ShowOrHeidGames(index);
  74. anim.speed = 0;
  75. isStart = true;
  76. }
  77. private void Update()
  78. {
  79. if (isStart)
  80. {
  81. startTimer -= Time.deltaTime;//开始时间倒计时
  82. if (startTimer <= 0)
  83. {
  84. AnimStart();
  85. startTimer = 4;
  86. ShowOrHeidGames(-1);//不播放文字动画
  87. isStart = false;
  88. }
  89. }
  90. }
  91. IEnumerator WaitForTiemrs(float timer, GameObject obj)
  92. {
  93. yield return new WaitForSeconds(timer);
  94. // obj.SetActive(false);
  95. }
  96. private void PlaySounds(int Soundindex)
  97. {
  98. string soundNames = "";
  99. switch (Soundindex)
  100. {
  101. case 0:
  102. soundNames = "GY_GKJ1";
  103. break;
  104. case 1:
  105. soundNames = "GY_GKJ2";
  106. break;
  107. case 2:
  108. soundNames = "GY_GKJ3";
  109. break;
  110. case 3:
  111. soundNames = "GY_GKJ4";
  112. break;
  113. case 4:
  114. soundNames = "GY_GKJ5";
  115. break;
  116. case 5:
  117. soundNames = "GY_GKJ6";
  118. break;
  119. }
  120. AudioManager.Instance.AudioGongYe_GKJ_LanguageSounds(soundNames);
  121. }
  122. }