123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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>(gameObject);
- gameObject2.GetComponent<Renderer>().enabled = false;
- gameObject2.transform.parent = goRoot.transform;
- this.m_goCamera.transform.parent = gameObject2.transform;
- this.m_animationClip = gameObject2.GetComponent<Animation>();
- List<string> list = new List<string>();
- 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<string> 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/";
- }
|