Пример #1
0
        public Vector3 GetPosition(float param)
        {
            Vector3  position     = Vector3.zero;
            PathEdge currentEdge  = null;
            float    pathDistance = 0;

            foreach (PathEdge edge in edges)
            {
                pathDistance += Vector3.Distance(edge.point1, edge.point2);
                if (param <= pathDistance)
                {
                    currentEdge = edge;
                    break;
                }
            }
            if (currentEdge == null)
            {
                return(position);
            }
            Vector3 edgeDirection = (currentEdge.point2 - currentEdge.point1).normalized;

            pathDistance -= Vector3.Distance(currentEdge.point1, currentEdge.point2);
            pathDistance  = param - pathDistance;
            position      = currentEdge.point1 + edgeDirection * pathDistance;
            return(position);
        }
Пример #2
0
        public float GetParam(Vector3 position, float lastParam)
        {
            float    param        = 0;
            float    pathDistance = 0;
            PathEdge currentEdge  = null;

            foreach (PathEdge edge in edges)
            {
                pathDistance += Vector3.Distance(edge.point1, edge.point2);
                if (lastParam <= pathDistance)
                {
                    currentEdge = edge;
                    break;
                }
            }
            if (currentEdge == null)
            {
                return(param);
            }
            Vector3 currentPosition = position - currentEdge.point1;
            Vector3 edgeDirection   = (currentEdge.point2 - currentEdge.point1).normalized;
            Vector3 pointInEdge     = Vector3.Project(currentPosition, edgeDirection);

            param  = pathDistance - Vector3.Distance(currentEdge.point1, currentEdge.point2);
            param += pointInEdge.magnitude;
            return(param);
        }
Пример #3
0
 public void AddEdge(PathEdge edge)
 {
     if (edges == null)
     {
         edges = new List <PathEdge>();
     }
     edges.Add(edge);
 }