AnimationComponent.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. namespace WS
  4. {
  5. [ObjectSystem]
  6. public class AnimationComponentAwakeSystem : AwakeSystem<AnimationComponent, Animation>
  7. {
  8. public override void Awake(AnimationComponent self, Animation a)
  9. {
  10. self.Awake(a);
  11. }
  12. }
  13. [ObjectSystem]
  14. public class AnimationComponentUpdateSystem : UpdateSystem<AnimationComponent>
  15. {
  16. public override void Update(AnimationComponent self)
  17. {
  18. self.Update();
  19. }
  20. }
  21. ///<summary>判断动画播放完成</summary>
  22. public class AnimationComponent : WSComponent
  23. {
  24. ///<summary>动画组件</summary>
  25. private Animation Anim;
  26. ///<summary>回调</summary>
  27. private UnityAction OnCallback;
  28. ///<summary>播放</summary>
  29. private bool isplay;
  30. public void Awake(Animation anim)
  31. {
  32. Anim = anim;
  33. }
  34. /// <summary>播放动画</summary>
  35. /// <param name="name">名称</param>
  36. /// <param name="action">回调</param>
  37. public void PlayAnim(string name, UnityAction action)
  38. {
  39. Anim.Play(name);
  40. OnCallback = action;
  41. isplay = true;
  42. }
  43. public void Update()
  44. {
  45. if (Anim != null)
  46. {
  47. if (isplay)
  48. {
  49. if (!Anim.isPlaying)
  50. {
  51. OnCallback?.Invoke();
  52. isplay = false;
  53. }
  54. }
  55. }
  56. }
  57. public override void Dispose()
  58. {
  59. base.Dispose();
  60. Anim = null;
  61. OnCallback = null;
  62. }
  63. }
  64. }