AnimState.cs 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. namespace UnityCommon
  3. {
  4. public class AnimState : CameraState
  5. {
  6. public Transform tfCameraAnim;
  7. private Animation animation;
  8. public AnimState(Camera camera, AnimationClip animClip) : base(camera)
  9. {
  10. animation = m_camera.gameObject.AddComponentOnlyOne<Animation>();
  11. animation.clip = animClip;
  12. }
  13. public override void Enter()
  14. {
  15. base.Enter();
  16. animation.enabled = true;
  17. tfCameraAnim.SetParent(null);
  18. tfCameraAnim.gameObject.SetActive(true);
  19. PlayAnim();
  20. }
  21. public override void Exit()
  22. {
  23. base.Exit();
  24. StopAnim();
  25. animation.enabled = false;
  26. }
  27. public void PlayAnim()
  28. {
  29. animation.Play();
  30. }
  31. public void StopAnim()
  32. {
  33. animation.Stop();
  34. }
  35. }
  36. }