BesselPathGroup.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace Core.Utility
  4. {
  5. public class BesselPathGroup
  6. {
  7. public float lane;
  8. public List<BesselPath> allBesselPath = new List<BesselPath>();
  9. public void AddBesselPath(BesselPath besselPath)
  10. {
  11. allBesselPath.Add(besselPath);
  12. }
  13. public void Start()
  14. {
  15. lane = 0;
  16. for (int i = 0; i < allBesselPath.Count; i++)
  17. {
  18. BesselPath besselPath = allBesselPath[i];
  19. besselPath.SetLengthAtT();
  20. lane += besselPath.allDis;
  21. }
  22. }
  23. public Vector3 CalculatePoint(float t)
  24. {
  25. // BesselPath currBeselPath = null;
  26. float currLane = 0;
  27. Vector3 endPos=Vector3.zero;
  28. for (int i = 0; i < allBesselPath.Count; i++)
  29. {
  30. BesselPath besselPath = allBesselPath[i];
  31. endPos=besselPath.controlPoints[^1];
  32. float allLane = currLane;
  33. allLane += besselPath.allDis;
  34. float b = allLane / lane;
  35. if (t <= b)
  36. {
  37. float lasetB = currLane / lane;
  38. b -= lasetB;
  39. t -= lasetB;
  40. float currB = t / b;
  41. return besselPath.CalculatePoint(currB);
  42. }
  43. currLane = allLane;
  44. }
  45. return endPos;
  46. }
  47. }
  48. }