Example #1
0
        public Vector3 GetPoint(WaypointsMover mover, float time)
        {
            if (IsCurved)
            {
                float fullLength     = BezierApproximation.GetLength(_moversParts[mover]);
                float remainedLength = fullLength * (time - 0.001f);
                for (int i = 0; i < _moversParts[mover].Count - 1; i++)
                {
                    Vector3 point1     = _moversParts[mover][i];
                    Vector3 point2     = _moversParts[mover][i + 1];
                    float   lineLength = Vector3.Distance(point1, point2);
                    if (lineLength < remainedLength)
                    {
                        remainedLength -= lineLength;
                    }
                    else
                    {
                        return(point1 + (point2 - point1).normalized * remainedLength);
                    }
                }

                throw new Exception("Get point error for time:" + time + ", remainedLength: " + remainedLength);
            }
            else
            {
                Vector3 point1         = _moversParts[mover][0];
                Vector3 point2         = _moversParts[mover][1];
                float   fullLength     = Vector3.Distance(point1, point2);
                float   remainedLength = fullLength * time;
                return(point1 + (point2 - point1).normalized * remainedLength);
            }
        }
Example #2
0
        public float GetLength(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
        {
            if (IsCurved)
            {
                Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
                Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
                return(BezierApproximation.GetLength(_capturedPositions[mover][fromInd], handle1,
                                                     _capturedPositions[mover][toInd], handle2, LinesCount));
            }

            return(Vector3.Distance(_capturedPositions[mover][fromInd], _capturedPositions[mover][toInd]));
        }
Example #3
0
        public void StartNextPart(WaypointsMover mover, int fromInd, int toInd, bool isForwardDirection)
        {
            Vector3 toPosition = CapturePosition(mover, toInd);

            if (IsCurved)
            {
                Vector3 handle1 = isForwardDirection ? GetHandle1(mover, fromInd) : GetHandle2(mover, fromInd);
                Vector3 handle2 = isForwardDirection ? GetHandle2(mover, toInd) : GetHandle1(mover, toInd);
                _moversParts[mover] = BezierApproximation.GetLines(_capturedPositions[mover][fromInd], handle1,
                                                                   toPosition, handle2, LinesCount);
            }
            else
            {
                _moversParts[mover] = new List <Vector3> {
                    _capturedPositions[mover][fromInd], toPosition
                };
            }

            ClearDestroyedMovers();
        }
Example #4
0
        public List <Vector3> GetPoints()
        {
            List <Vector3> points = new List <Vector3>();

            if (IsCurved)
            {
                for (int ind = 0; ind < Waypoints.Count; ind++)
                {
                    if (!IsClosed && ind == Waypoints.Count - 1)
                    {
                        continue;
                    }

                    int nextInd = (ind + 1) % Waypoints.Count;

                    List <Vector3> lines = BezierApproximation.GetLines(
                        Waypoints[ind].position, GetHandle1(ind),
                        Waypoints[nextInd].position, GetHandle2(nextInd), LinesCount);

                    if (points.Any())
                    {
                        points.RemoveAt(points.Count - 1);
                    }

                    points.AddRange(lines);
                }
            }
            else
            {
                points.AddRange(Waypoints.Select(_ => _.position));
                if (IsClosed)
                {
                    points.Add(Waypoints[0].position);
                }
            }

            return(points);
        }