CameraAnimationCtrl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class CameraAnimationCtrl : MonoBehaviour
  6. {
  7. public void Play(GameObject goRoot, string animationName)
  8. {
  9. this.PlayByPath(goRoot, "Debug/CameraAnimation/Prefab/AnimationObject/" + animationName);
  10. }
  11. public void PlayByPath(GameObject goRoot, string animePrefabPath)
  12. {
  13. this.m_goRoot = goRoot;
  14. this.ClearExistAnimationObject(goRoot);
  15. this.m_goCamera = goRoot.transform.Find("Camera").gameObject;
  16. GameObject gameObject = Resources.Load(animePrefabPath) as GameObject;
  17. NDebug.Assert(gameObject != null, string.Format("アニメーションを保持する指定のプレハブがみつかりませんでした。パス={0}", animePrefabPath));
  18. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  19. gameObject2.GetComponent<Renderer>().enabled = false;
  20. gameObject2.transform.parent = goRoot.transform;
  21. this.m_goCamera.transform.parent = gameObject2.transform;
  22. this.m_animationClip = gameObject2.GetComponent<Animation>();
  23. List<string> list = new List<string>();
  24. IEnumerator enumerator = this.m_animationClip.GetEnumerator();
  25. try
  26. {
  27. while (enumerator.MoveNext())
  28. {
  29. object obj = enumerator.Current;
  30. AnimationState animationState = (AnimationState)obj;
  31. list.Add(animationState.name);
  32. }
  33. }
  34. finally
  35. {
  36. IDisposable disposable;
  37. if ((disposable = (enumerator as IDisposable)) != null)
  38. {
  39. disposable.Dispose();
  40. }
  41. }
  42. if (list.Count > 0)
  43. {
  44. base.StartCoroutine(this.Play(list));
  45. }
  46. else
  47. {
  48. Debug.LogError(string.Format("再生するアニメーションが存在しません。パス={0}", animePrefabPath));
  49. }
  50. }
  51. private IEnumerator Play(List<string> listClip)
  52. {
  53. this.m_pressStop = false;
  54. this.m_pressPause = false;
  55. this.m_pressResume = false;
  56. bool isPausing = false;
  57. int clipNum = 0;
  58. string playingAnimationClipName = listClip[0];
  59. this.m_goCamera.SetActive(true);
  60. for (;;)
  61. {
  62. while (this.m_animationClip.isPlaying && !isPausing)
  63. {
  64. if (this.m_pressStop)
  65. {
  66. goto Block_1;
  67. }
  68. if (this.m_pressPause)
  69. {
  70. this.m_animationClip[playingAnimationClipName].speed = 0f;
  71. isPausing = true;
  72. }
  73. yield return null;
  74. }
  75. while (this.m_pressPause)
  76. {
  77. if (this.m_pressResume)
  78. {
  79. this.m_animationClip[playingAnimationClipName].speed = 1f;
  80. isPausing = false;
  81. this.m_pressPause = false;
  82. }
  83. if (this.m_pressStop)
  84. {
  85. goto Block_5;
  86. }
  87. yield return null;
  88. }
  89. if (this.m_pressResume)
  90. {
  91. this.m_pressResume = false;
  92. }
  93. else
  94. {
  95. if (listClip.Count <= clipNum)
  96. {
  97. goto Block_8;
  98. }
  99. playingAnimationClipName = listClip[clipNum];
  100. this.m_animationClip.Play(playingAnimationClipName);
  101. clipNum++;
  102. }
  103. }
  104. Block_1:
  105. this.m_animationClip.Stop();
  106. UnityEngine.Object.Destroy(this.m_goRoot);
  107. yield break;
  108. Block_5:
  109. this.m_animationClip.Stop();
  110. UnityEngine.Object.Destroy(this.m_goRoot);
  111. yield break;
  112. Block_8:
  113. UnityEngine.Object.Destroy(this.m_goRoot);
  114. yield break;
  115. yield break;
  116. }
  117. private void ClearExistAnimationObject(GameObject go)
  118. {
  119. IEnumerator enumerator = go.transform.GetEnumerator();
  120. try
  121. {
  122. while (enumerator.MoveNext())
  123. {
  124. object obj = enumerator.Current;
  125. Transform transform = (Transform)obj;
  126. if (transform.name != "Camera")
  127. {
  128. UnityEngine.Object.Destroy(transform.gameObject);
  129. }
  130. }
  131. }
  132. finally
  133. {
  134. IDisposable disposable;
  135. if ((disposable = (enumerator as IDisposable)) != null)
  136. {
  137. disposable.Dispose();
  138. }
  139. }
  140. }
  141. public void Pause()
  142. {
  143. this.m_pressPause = true;
  144. }
  145. public void Resume()
  146. {
  147. if (this.m_pressPause)
  148. {
  149. this.m_pressResume = true;
  150. }
  151. }
  152. public void Stop()
  153. {
  154. this.m_pressStop = true;
  155. }
  156. private GameObject m_goRoot;
  157. private GameObject m_goCamera;
  158. private Animation m_animationClip;
  159. private bool m_pressStop;
  160. private bool m_pressPause;
  161. private bool m_pressResume;
  162. private const string ANIMATION_PREFAB_ROOT_PATH = "Debug/CameraAnimation/Prefab/AnimationObject/";
  163. }