AniDriver_UnityAnimation.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using ChivaXR;
  5. using System;
  6. using Sirenix.OdinInspector;
  7. /// <summary>
  8. /// 动画驱动器--- UnityAnimation
  9. /// </summary>
  10. public class AniDriver_UnityAnimation : AnimationDriverBase
  11. {
  12. public Animation animation;
  13. [ValueDropdown("GetAllAnimationNames")]
  14. public string aniName;
  15. public float speed = 1;
  16. public override void FinishedState()
  17. {
  18. AnimationToolkit.SetAnimationNormalizedToPose(animation, aniName, 1);
  19. }
  20. public override void InitState()
  21. {
  22. AnimationToolkit.SetAnimationNormalizedToPose(animation, aniName, 0);
  23. }
  24. public override void StartPlay(Action finishedCallBack = null)
  25. {
  26. AnimationToolkit.SetAnimationNormalizedToPlay(animation, aniName, 0, speed, finishedCallBack);
  27. }
  28. private IEnumerable GetAllAnimationNames()
  29. {
  30. List<ValueDropdownItem> item = new List<ValueDropdownItem>();
  31. if (animation != null)
  32. {
  33. foreach (AnimationState state in animation)
  34. {
  35. item.Add(new ValueDropdownItem(state.name, state.name));
  36. }
  37. }
  38. return item;
  39. }
  40. }