using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraAnimationCtrl : MonoBehaviour { public void Play(GameObject goRoot, string animationName) { this.PlayByPath(goRoot, "Debug/CameraAnimation/Prefab/AnimationObject/" + animationName); } public void PlayByPath(GameObject goRoot, string animePrefabPath) { this.m_goRoot = goRoot; this.ClearExistAnimationObject(goRoot); this.m_goCamera = goRoot.transform.Find("Camera").gameObject; GameObject gameObject = Resources.Load(animePrefabPath) as GameObject; NDebug.Assert(gameObject != null, string.Format("アニメーションを保持する指定のプレハブがみつかりませんでした。パス={0}", animePrefabPath)); GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject); gameObject2.GetComponent().enabled = false; gameObject2.transform.parent = goRoot.transform; this.m_goCamera.transform.parent = gameObject2.transform; this.m_animationClip = gameObject2.GetComponent(); List list = new List(); IEnumerator enumerator = this.m_animationClip.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; AnimationState animationState = (AnimationState)obj; list.Add(animationState.name); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } if (list.Count > 0) { base.StartCoroutine(this.Play(list)); } else { Debug.LogError(string.Format("再生するアニメーションが存在しません。パス={0}", animePrefabPath)); } } private IEnumerator Play(List listClip) { this.m_pressStop = false; this.m_pressPause = false; this.m_pressResume = false; bool isPausing = false; int clipNum = 0; string playingAnimationClipName = listClip[0]; this.m_goCamera.SetActive(true); for (;;) { while (this.m_animationClip.isPlaying && !isPausing) { if (this.m_pressStop) { goto Block_1; } if (this.m_pressPause) { this.m_animationClip[playingAnimationClipName].speed = 0f; isPausing = true; } yield return null; } while (this.m_pressPause) { if (this.m_pressResume) { this.m_animationClip[playingAnimationClipName].speed = 1f; isPausing = false; this.m_pressPause = false; } if (this.m_pressStop) { goto Block_5; } yield return null; } if (this.m_pressResume) { this.m_pressResume = false; } else { if (listClip.Count <= clipNum) { goto Block_8; } playingAnimationClipName = listClip[clipNum]; this.m_animationClip.Play(playingAnimationClipName); clipNum++; } } Block_1: this.m_animationClip.Stop(); UnityEngine.Object.Destroy(this.m_goRoot); yield break; Block_5: this.m_animationClip.Stop(); UnityEngine.Object.Destroy(this.m_goRoot); yield break; Block_8: UnityEngine.Object.Destroy(this.m_goRoot); yield break; yield break; } private void ClearExistAnimationObject(GameObject go) { IEnumerator enumerator = go.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; if (transform.name != "Camera") { UnityEngine.Object.Destroy(transform.gameObject); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } } public void Pause() { this.m_pressPause = true; } public void Resume() { if (this.m_pressPause) { this.m_pressResume = true; } } public void Stop() { this.m_pressStop = true; } private GameObject m_goRoot; private GameObject m_goCamera; private Animation m_animationClip; private bool m_pressStop; private bool m_pressPause; private bool m_pressResume; private const string ANIMATION_PREFAB_ROOT_PATH = "Debug/CameraAnimation/Prefab/AnimationObject/"; }