Example #1
0
        void UpdateLineCounts()
        {
            // force even numbers so that we can draw triangles correctly
            if (_LineCountY % 2 != 0)
            {
                _LineCountY += 1;
            }
            if (_LineCountZ % 2 != 0)
            {
                _LineCountZ += 1;
            }

            LineCountY = _LineCountY;
            LineCountZ = _LineCountZ;

            // wipe lines for recalculation
            LeftInterruptLineObjects.ForEach(g => GameObject.Destroy(g));
            LeftInterruptLineObjects.Clear();

            RightRaycastLineObjects.ForEach(g => GameObject.Destroy(g));
            RightRaycastLineObjects.Clear();

            LeftConnectingQuadObjects.ForEach(g => GameObject.Destroy(g));
            LeftConnectingQuadObjects.Clear();

            RightConnectingQuadObjects.ForEach(g => GameObject.Destroy(g));
            RightConnectingQuadObjects.Clear();

            LeftInterruptLineRenderers.Clear();

            RightRaycastLineRenderers.Clear();

            LeftConnectingQuadLineRenderers.Clear();

            RightConnectingQuadLineRenderers.Clear();

            // recalculate spacing offsets
            CalculateSpacing();
        }
Example #2
0
        void DrawLeftConnectionLines(int y, int z, bool interrupted)
        {
            // can't draw from 0 index because there is no points to draw
            // the quad BACK onto
            if (z == 0 || y == 0)
            {
                return;
            }

            // the index of the quad we are drawing:
            int quadNumber = (y - 1) + ((z - 1) * (LineCountY - 1));

            // line indices we will draw the quad with:
            int lineNumber = y + (LineCountY * z);

            int indexA = lineNumber;
            int indexB = lineNumber - 1;
            int indexC = lineNumber - LineCountY;
            int indexD = lineNumber - 1 - LineCountY;

            // grab the position vectors for each index based on the end point (1)
            // of the corresponding line
            Vector3 vertexA = LeftInterruptLineRenderers[indexA].GetPosition(1);
            Vector3 vertexB = LeftInterruptLineRenderers[indexB].GetPosition(1);
            Vector3 vertexC = LeftInterruptLineRenderers[indexC].GetPosition(1);
            Vector3 vertexD = LeftInterruptLineRenderers[indexD].GetPosition(1);

            // find out if the line is clipping its bounds
            if (Mathf.Abs(vertexA.x) == Width / 2 ||
                Mathf.Abs(vertexA.x) < 0 ||
                Mathf.Abs(vertexB.x) == Width / 2 ||
                Mathf.Abs(vertexB.x) < 0 ||
                Mathf.Abs(vertexC.x) == Width / 2 ||
                Mathf.Abs(vertexC.x) < 0 ||
                Mathf.Abs(vertexD.x) == Width / 2 ||
                Mathf.Abs(vertexD.x) < 0)
            {
                interrupted = false;
            }

            GameObject   lineObject;
            LineRenderer lineRenderer;

            if (LeftConnectingQuadObjects.Count <= quadNumber)
            {
                CreateLineRenderer(out lineObject, out lineRenderer);
                LeftConnectingQuadObjects.Add(lineObject);
                LeftConnectingQuadLineRenderers.Add(lineRenderer);

                // uncomment to show line in inspector
                // lineObject.hideFlags = HideFlags.None;
            }
            else
            {
                lineObject   = LeftConnectingQuadObjects[quadNumber];
                lineRenderer = LeftConnectingQuadLineRenderers[quadNumber];
            }

            // unhide the line from the inspector
            // lineObject.hideFlags = HideFlags.None;

            // if it's not interrupted, don't render any lines
            bool render = interrupted;

            if (!IsVisualisingLeftConnectors)
            {
                render = false;
            }
            lineRenderer.enabled = render;

            lineRenderer.positionCount = 7;
            lineRenderer.SetPositions(new Vector3[] {
                vertexA,
                vertexB,
                vertexC,
                vertexD,
                vertexB,
                vertexC,
                vertexA
            });

            if (HighlightBody)
            {
                Color lineColor = lineRenderer.material.color;
                lineColor.a = LineOpacity + HighlightGain;
                lineRenderer.material.color = lineColor;
            }
        }