Пример #1
0
        private void OnDrawGizmos()
        {
            Gizmos.color  = _renderColor;
            Gizmos.matrix = transform.localToWorldMatrix;

            int segmentCount = SegmentCount;

            if (_data.Count > 1 && segmentCount > 0)
            {
                for (int segmentIndex = 0; segmentIndex < segmentCount; ++segmentIndex)
                {
                    ItemData segment = _data[segmentIndex];
                    if (segment.EnsureRenderPointsValidity())
                    {
                        segment.UpdateRenderPoints();
                    }

                    Vector3[] renderPoints = segment.RenderPoints;
                    Vector3   prev         = renderPoints[0];
                    Vector3   curr;
                    for (int renderPointIndex = 1, len = renderPoints.Length; renderPointIndex < len; ++renderPointIndex)
                    {
                        curr = renderPoints[renderPointIndex];
                        Gizmos.DrawLine(curr, prev);
                        prev = curr;
                    }
                }
            }

            for (int vertexIndex = 0; vertexIndex < _data.Count; ++vertexIndex)
            {
                Vector3 position = _data[vertexIndex].Position;
                Gizmos.DrawCube(position, RenderPointSize * HandleUtility.GetHandleSize(position));
            }

            Gizmos.matrix = Matrix4x4.identity;
        }
Пример #2
0
        private void UpdateSegment(int index)
        {
            int segmentCount = SegmentCount;
            int lastSegment  = segmentCount - 1;
            int vertexCount  = _data.Count;

            Vector3 p1 = _data[index].Position;
            Vector3 p0, p2, p3;

            if (_type == SplineTypes.Open)
            {
                p2 = _data[index + 1].Position;
                p0 = index == 0           ? p1 : _data[index - 1].Position;
                p3 = index == lastSegment ? p2 : _data[index + 2].Position;
                //p0 = index == 0           ? (2f * p1 - p2) : _data[index - 1].Position;
                //p3 = index == lastSegment ? (2f * p2 - p1) : _data[index + 2].Position;
            }
            else
            {
                p0 = index == 0 ? _data[lastSegment].Position : _data[index - 1].Position;
                p2 = _data[(index + 1) % vertexCount].Position;
                p3 = _data[(index + 2) % vertexCount].Position;
            }

            ItemData segment = _data[index];

            segment.A = p1;
            segment.B = 0.5f * (-p0 + p2);
            segment.C = p0 - 2.5f * p1 + 2f * p2 - 0.5f * p3;
            segment.D = 0.5f * (-p0 + 3f * p1 - 3f * p2 + p3);

#if UNITY_EDITOR
            segment.EnsureRenderPointsValidity();
            segment.UpdateRenderPoints();
#endif
        }