BesselPathMono.cs 1.9 KB

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