SceneEventParabolic.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. using DG;
  7. using DG.Tweening;
  8. /// <summary>
  9. /// 场景组件 抛物线
  10. /// </summary>
  11. public class SceneEventParabolic : MonoBehaviour
  12. {
  13. Sequence seq;
  14. bool isComplate = false;
  15. private void Awake()
  16. {
  17. seq = DOTween.Sequence();
  18. }
  19. // Start is called before the first frame update
  20. void Start()
  21. {
  22. }
  23. public void OnTriggerEnter(Collider collider)
  24. {
  25. Role r = collider.GetComponent<Role>();
  26. if(r && !seq.IsPlaying())
  27. {
  28. TestDoTween(collider.transform);
  29. }
  30. }
  31. public void OnTriggerExit(Collider collider)
  32. {
  33. }
  34. public void TestDoTween(Transform target)
  35. {
  36. var ParabolicDis = Vector3.Distance(target.transform.position, this.transform.position);
  37. var ParabolicDown = target.transform.position.y;
  38. var speed = 3.0f;
  39. var time = ParabolicDis / speed;
  40. seq.Append(this.transform.DOMoveX(target.position.x, time / 2).SetEase(Ease.Linear));
  41. seq.Append(this.transform.DOMoveZ(target.position.z, time / 2).SetEase(Ease.Linear));
  42. seq.Insert(0, this.transform.DOMoveY(target.transform.position.y + ParabolicDis, time / 2).SetEase(Ease.OutQuart));
  43. seq.Insert(0.5f , this.transform.DOMoveY(ParabolicDown, time * 0.5f).SetEase(Ease.InCirc));
  44. seq.OnComplete<Sequence>(() => { OnDoTweenComplete(); });
  45. }
  46. public void OnDoTweenComplete()
  47. {
  48. Debug.Log("抛物线完成!");
  49. }
  50. }