AniDriver_ToolAnimationItem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using ChivaXR;
  2. using Sirenix.OdinInspector;
  3. using System;
  4. using System.Collections;
  5. using System.Linq.Expressions;
  6. #if UNITY_EDITOR
  7. using UnityEditor;
  8. #endif
  9. using UnityEngine;
  10. public class AniDriver_ToolAnimationItem : AnimationDriverBase
  11. {
  12. [HorizontalGroup("AniGroup")]
  13. public ToolAnimationItem mToolAnimationItem;
  14. #if UNITY_EDITOR
  15. [HorizontalGroup("AniGroup")]
  16. [Button("选中ToolAnimationItem")]
  17. public void SelectMovePathItem()
  18. {
  19. if (mToolAnimationItem != null)
  20. {
  21. Selection.activeObject = mToolAnimationItem.gameObject;
  22. }
  23. }
  24. #endif
  25. #if UNITY_EDITOR
  26. [Header("反向播放")]
  27. #endif
  28. public bool reverse = false;
  29. public override void FinishedState()
  30. {
  31. mToolAnimationItem.SetFinishedState(reverse);
  32. }
  33. public override void InitState()
  34. {
  35. mToolAnimationItem.SetInitState(reverse);
  36. }
  37. public override void StartPlay(Action finishedCallBack = null)
  38. {
  39. StartAniCoroutine(PlayToolAnimation(mToolAnimationItem, reverse, finishedCallBack));
  40. }
  41. IEnumerator PlayToolAnimation(ToolAnimationItem toolAnimationItem, bool isReverse, Action finishedCallBack = null)
  42. {
  43. toolAnimationItem.Play();
  44. int i = 0;
  45. while (toolAnimationItem.PlayToolAnimation(isReverse))
  46. {
  47. i++;
  48. yield return new WaitForEndOfFrame();
  49. Debug.Log("PlayToolAnimation" + i);
  50. }
  51. finishedCallBack?.Invoke();
  52. }
  53. }