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(); }
void DrawRightConnectionLines(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 = RightRaycastLineRenderers[indexA].GetPosition(1); Vector3 vertexB = RightRaycastLineRenderers[indexB].GetPosition(1); Vector3 vertexC = RightRaycastLineRenderers[indexC].GetPosition(1); Vector3 vertexD = RightRaycastLineRenderers[indexD].GetPosition(1); // find out if the line is clipping its bounds if (Mathf.Abs(vertexA.x) == 0 || Mathf.Abs(vertexA.x) < -Width / 2 || Mathf.Abs(vertexB.x) == 0 || Mathf.Abs(vertexB.x) < -Width / 2 || Mathf.Abs(vertexC.x) == 0 || Mathf.Abs(vertexC.x) < -Width / 2 || Mathf.Abs(vertexD.x) == 0 || Mathf.Abs(vertexD.x) < -Width / 2) { interrupted = false; } GameObject lineObject; LineRenderer lineRenderer; if (RightConnectingQuadObjects.Count <= quadNumber) { CreateLineRenderer(out lineObject, out lineRenderer); RightConnectingQuadObjects.Add(lineObject); RightConnectingQuadLineRenderers.Add(lineRenderer); // uncomment to show line in inspector // lineObject.hideFlags = HideFlags.None; } else { lineObject = RightConnectingQuadObjects[quadNumber]; lineRenderer = RightConnectingQuadLineRenderers[quadNumber]; } // unhide the line from the inspector // lineObject.hideFlags = HideFlags.None; // check for non initialised previous vertices if (vertexA.x == 0 || vertexB.x == 0 || vertexC.x == 0 || vertexD.x == 0) { // if this is true, it means at least one vertex // spans the width of the stage, which mean's it's not // fully interrupted, so don't draw interrupted = false; } // if it's not interrupted, don't render any lines if (!interrupted) { lineRenderer.enabled = false; } // if it is interrupted, draw away else { lineRenderer.enabled = true; lineRenderer.positionCount = 7; lineRenderer.SetPositions(new Vector3[] { vertexA, vertexB, vertexC, vertexD, vertexB, vertexC, vertexA }); } bool render = interrupted; if (!IsVisualisingRightConnectors) { render = false; } lineRenderer.enabled = render; }