123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace Core.Utility
- {
- /// <summary>
- /// 贝塞尔曲线
- /// </summary>
- public class BesselPath
- {
- public List<Vector3> PosList;
- public void SetPos(List<Vector3> PosList)
- {
- this.PosList = PosList;
- }
- public float GetPathCount(int count)
- {
- float step = 1f / count;
- Vector3 startPos = GetValue(0);
- float d = 0;
- for (int i = 1; i < count; i++)
- {
- Vector3 currPos = GetValue(step * i);
- d += Vector3.Distance(startPos, currPos);
- }
- return d;
- }
- public Vector3 GetValue(float t)
- {
- Vector3 a = PosList[0];
- for (int i = 1; i < PosList.Count; i++)
- {
- Vector3 b = PosList[i];
- Vector3 c = Vector3.Lerp(a, b, t);
- a = c;
- }
- return a;
- }
- }
- }
|