BesselPathMono.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using CombatLibrary.CombatLibrary.CombatCore.Utility;
  4. using UnityEngine;
  5. namespace Core.Utility
  6. {
  7. public class BesselPathMono : MonoBehaviour
  8. {
  9. public Transform[] Transforms;
  10. public BesselPath BesselPath;
  11. public ACurve ACurve;
  12. private void OnDrawGizmos()
  13. {
  14. if (BesselPath == null)
  15. {
  16. BesselPath = new BesselPath();
  17. }
  18. if (Transforms == null || Transforms.Length < 2)
  19. {
  20. return;
  21. }
  22. BetterList<Vector3> pos = new BetterList<Vector3>();
  23. for (int i = 0; i < Transforms.Length; i++)
  24. {
  25. pos.Add(Transforms[i].position);
  26. }
  27. BesselPath.controlPoints = (pos);
  28. Gizmos.color = Color.blue;
  29. // 绘制控制点
  30. for (int i = 0; i < pos.Count; i++)
  31. {
  32. Gizmos.DrawSphere(pos[i], 0.1f);
  33. }
  34. // 绘制曲线
  35. Vector3 previousPoint = BesselPath.CalculatePoint(0);
  36. int segments = 50;
  37. for (int i = 1; i <= segments; i++)
  38. {
  39. float t = i / (float)segments;
  40. Vector3 currentPoint = BesselPath.CalculatePoint(t);
  41. Gizmos.DrawLine(previousPoint, currentPoint);
  42. previousPoint = currentPoint;
  43. }
  44. }
  45. }
  46. }