BesselPathMono.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. public bool isRun;
  13. private void OnDrawGizmos()
  14. {
  15. if (BesselPath == null)
  16. {
  17. BesselPath = new BesselPath();
  18. }
  19. if (!isRun)
  20. {
  21. if (Transforms == null || Transforms.Length < 2)
  22. {
  23. return;
  24. }
  25. List<Vector3> pos = new List<Vector3>();
  26. for (int i = 0; i < Transforms.Length; i++)
  27. {
  28. pos.Add(Transforms[i].position);
  29. }
  30. BesselPath.controlPoints = (pos);
  31. }
  32. Gizmos.color = Color.blue;
  33. // 绘制控制点
  34. for (int i = 0; i < BesselPath.controlPoints.Count; i++)
  35. {
  36. Gizmos.DrawSphere( BesselPath.controlPoints[i], 0.1f);
  37. }
  38. // 绘制曲线
  39. Vector3 previousPoint = BesselPath.CalculatePoint(0);
  40. int segments = 50;
  41. for (int i = 1; i <= segments; i++)
  42. {
  43. float t = i / (float)segments;
  44. Vector3 currentPoint = BesselPath.CalculatePoint(t);
  45. // Gizmos.DrawSphere(currentPoint, 0.03f);
  46. Gizmos.DrawLine(previousPoint, currentPoint);
  47. previousPoint = currentPoint;
  48. }
  49. }
  50. }
  51. }