private void SetPointsToLine()
        {
            //create old positions if they dont match
            if (linePositionsOld.Length != linePositions.Length)
            {
                linePositionsOld = new Vector3[linePositions.Length];
            }

            //check if line points have moved
            bool moved = false;

            for (int i = 0; i < linePositions.Length; i++)
            {
                //compare
                if (linePositions[i] != linePositionsOld[i])
                {
                    moved = true;
                }
            }

            //update if moved
            if (moved == true)
            {
                LineRenderer line = this.GetComponent <LineRenderer>();

                //get smoothed values
                Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, lineSegmentSize);

                //set line settings
                line.positionCount = smoothedPoints.Length;
                line.SetPositions(smoothedPoints);
                line.startWidth = lineWidth;
                line.endWidth   = useCustomEndWidth ? endWidth : lineWidth;
            }
        }
        private void SetPointsToLine()
        {
            bool rebuild = false;

            // create old positions if they don't match
            if (linePositionsOld.Length != linePositions.Length)
            {
                linePositionsOld = new Vector3[linePositions.Length];
                rebuild          = true;
            }
            else
            {
                // check if line points have moved
                for (int i = 0; i < linePositions.Length; i++)
                {
                    //compare
                    if (linePositions[i] != linePositionsOld[i])
                    {
                        rebuild = true;
                        break;
                    }
                }
            }

            // update if line points were modified
            if (rebuild)
            {
                linePositions.CopyTo(linePositionsOld, 0);
                if (lineRenderer == null)
                {
                    lineRenderer = GetComponent <LineRenderer>();
                }
                // get smoothed values
                Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, lineSegmentSize);

                // set line settings
                lineRenderer.positionCount = smoothedPoints.Length;
                lineRenderer.SetPositions(smoothedPoints);
                lineRenderer.startWidth = lineWidth;
                lineRenderer.endWidth   = useCustomEndWidth ? endWidth : lineWidth;
            }
        }
Beispiel #3
0
        private void SetPointsToLine()
        {
            if (allowWidthEditOnCurveGraph)
            {
                // if the start width was edited directly on the curve
                if (oldLineWidth == lineWidth && oldLineRendererStartWidth != lineRenderer.startWidth)
                {
                    lineWidth = lineRenderer.startWidth;
                }

                // if the end width was edited directly on the curve
                if (oldEndWidth == endWidth && oldLineRendererEndWidth != lineRenderer.endWidth)
                {
                    endWidth = lineRenderer.endWidth;
                    if (endWidth != lineWidth)
                    {
                        useCustomEndWidth = true;
                    }
                }
            }

            float actualEndWidth = useCustomEndWidth ? endWidth : lineWidth;

            // rebuild the line if any parameter was changed
            bool rebuild = (lineRenderer.startWidth != lineWidth || lineRenderer.endWidth != actualEndWidth);

            if (!rebuild)
            {
                // create old positions if they don't match
                if (linePositionsOld.Length != linePositions.Length)
                {
                    linePositionsOld = new Vector3[linePositions.Length];
                    rebuild          = true;
                }
                else
                {
                    // check if line points have moved
                    for (int i = 0; i < linePositions.Length; i++)
                    {
                        //compare
                        if (linePositions[i] != linePositionsOld[i])
                        {
                            rebuild = true;
                            break;
                        }
                    }
                }
            }

            // update if line points were modified
            if (rebuild)
            {
                linePositions.CopyTo(linePositionsOld, 0);
                if (lineRenderer == null)
                {
                    lineRenderer = GetComponent <LineRenderer>();
                }

                // get smoothed values
                Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, lineSegmentSize);

                // set line settings
                lineRenderer.positionCount = smoothedPoints.Length;
                lineRenderer.SetPositions(smoothedPoints);
                lineRenderer.startWidth = lineWidth;
                lineRenderer.endWidth   = useCustomEndWidth ? endWidth : lineWidth;

                oldLineWidth = lineWidth;
                oldEndWidth  = endWidth;
                oldLineRendererStartWidth = lineRenderer.startWidth;
                oldLineRendererEndWidth   = lineRenderer.endWidth;
            }
        }