예제 #1
0
 public void StorePath(IPath path)
 {
     _isNonUniformPath = path is NonUniformPath;
     _nonUniformPath   = path as NonUniformPath;
     _isUniformPath    = path is UniformPath;
     _uniformPath      = path as UniformPath;
 }
예제 #2
0
        public override void CachePath()
        {
            if (LockedAxis != Axis.None)
            {
                LockAxis(LockedAxis);
            }
            if (_path == null)
            {
                _path = GetComponent <PathComponent>();
            }
            if (_cachedPositions == null)
            {
                _cachedPositions = new List <Vector3>();
            }
            else
            {
                _cachedPositions.Clear();
            }
            if (_uniformPoinsts == null)
            {
                _uniformPoinsts = new List <Vector3>();
            }
            else
            {
                _uniformPoinsts.Clear();
            }
            _cachedPositions.Add(GetPointPosition(0));
            for (int i = 0; i < Points.Length - 1; i++)
            {
                SegmentingSection(i, i + 1, SegmentsPerUnit, _cachedPositions);
            }
            if (IsCyclic)
            {
                SegmentingSection(Points.Length - 1, 0, SegmentsPerUnit, _cachedPositions);
            }
            var   distances     = DistanceCalculator.CalculateDistances(_cachedPositions);
            float totalDistance = 0;

            foreach (var distance in distances)
            {
                totalDistance += distance;
            }
            var pointsCount   = Mathf.CeilToInt(totalDistance * SegmentsPerUnit);
            var segmentLength = totalDistance / pointsCount;

            DistanceCalculator.ToUniformPath(_cachedPositions, distances, segmentLength, _uniformPoinsts);
            var uniform = new UniformPath
            {
                TotalLength   = totalDistance,
                SegmentLength = segmentLength,
                Points        = _uniformPoinsts.ToArray()
            };

            _path.StorePath(uniform);
        }