ModelAniTool.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using DG.Tweening;
  6. using UnityEngine.Serialization;
  7. public enum AniType
  8. {
  9. move,
  10. rota
  11. }
  12. public class ModelAniTool : MonoBehaviour
  13. {
  14. public string moveModelName;
  15. [FormerlySerializedAs("oriPos")] public Vector3 oriV3;
  16. [FormerlySerializedAs("targetPos")] public Vector3 targetV3;
  17. public float speed=2.0f;
  18. private GameObject targetObj;
  19. public AniType aniType;
  20. public void FindObje()
  21. {
  22. targetObj = this.transform.Find(moveModelName+"(Clone)").gameObject;
  23. ActionInstance._Instance.ModelAni_On += Ani_On;
  24. ActionInstance._Instance.ModelAni_Off += Ani_Off;
  25. }
  26. public void Ani_On()
  27. {
  28. switch (aniType)
  29. {
  30. case AniType.move:
  31. targetObj.transform.localPosition = oriV3;
  32. targetObj.transform.DOLocalMove(targetV3, speed);
  33. break;
  34. case AniType.rota:
  35. targetObj.transform.localEulerAngles = oriV3;
  36. targetObj.transform.DOLocalRotate(targetV3, speed);
  37. break;
  38. }
  39. }
  40. public void Ani_Off()
  41. {
  42. switch (aniType)
  43. {
  44. case AniType.move:
  45. targetObj.transform.localPosition = targetV3;
  46. targetObj.transform.DOLocalMove(oriV3, speed);
  47. break;
  48. case AniType.rota:
  49. targetObj.transform.localEulerAngles = targetV3;
  50. targetObj.transform.DOLocalRotate(oriV3, speed);
  51. break;
  52. }
  53. }
  54. }