public void WireCircuit() { string[] wire_list = GetWireList(); if (wire_list.Length < 4) { return; } // Debug.Log("in wire circuit, length = " + wire_list.Length); // Debug.Log("in wire circuit, _wire_list = '" + _wire_list + "'"); // Debug.Log("in wire circuit, wire_list[] = '" + wire_list[0] + "', '" + // wire_list[1] + "', '" + // wire_list[2] + "', '" + // wire_list[3] + "'"); for (int i = 0; i < wire_list.Length; i += 4) { // Debug.Log("in wire circuit source = " + wire_list[i] + " dest = " + wire_list[i+2]); GameObject mysource = GameObject.Find(wire_list[i]); GameObject mydestination = GameObject.Find(wire_list[i + 2]); BasicGate mysource_gate = mysource.GetComponent(typeof(BasicGate)) as BasicGate; BasicGate mydestination_gate = mydestination.GetComponent(typeof(BasicGate)) as BasicGate; // Debug.Log("in wire circuit mysoure_gate = " + mysource_gate.name); // Debug.Log(" dest = " + mydestination.name); // Debug.Log(" dest gate = " + mydestination_gate.name); float startx_adjust = mysource_gate.output_x_adjust(); float starty_adjust = mysource_gate.output_y_adjust(); float startx = mysource.transform.position.x + startx_adjust; float starty = mysource.transform.position.y + starty_adjust; float endx_adjust = -1; float endy_adjust = 0; switch (wire_list[i + 3]) { case "a": endx_adjust = mydestination_gate.inputa_x_adjust(); endy_adjust = mydestination_gate.inputa_y_adjust(); //Debug.Log("Destination " + wire_list[i + 2] + "/" + wire_list[i + 3] // + " endx adjust = " + endx_adjust // + " endy adjust = " + endy_adjust); break; case "b": endx_adjust = mydestination_gate.inputb_x_adjust(); endy_adjust = mydestination_gate.inputb_y_adjust(); break; case "d": endx_adjust = mydestination_gate.inputd_x_adjust(); endy_adjust = mydestination_gate.inputd_y_adjust(); break; case "ck": endx_adjust = mydestination_gate.inputck_x_adjust(); endy_adjust = mydestination_gate.inputck_y_adjust(); break; } float endx = mydestination.transform.position.x + endx_adjust; float endy = mydestination.transform.position.y + endy_adjust; float middlex = (float)(startx + endx) / 2.0f; Vector3[] positions; LineRenderer mylr = mysource.GetComponent <LineRenderer>(); if (!mylr || mylr.positionCount < 2) { // Create a new route from the source to the destination // Debug.Log(" First segment destination = " + mydestination_gate.name); if (!mylr) { mysource.AddComponent <LineRenderer>(); } mylr = mysource.GetComponent <LineRenderer>(); positions = new Vector3[4]; positions[0] = new Vector3(startx, starty, 0); positions[1] = new Vector3(middlex, starty, 0); positions[2] = new Vector3(middlex, endy, 0); positions[3] = new Vector3(endx, endy, 0); mylr.positionCount = 4; } else { // Adding onto an existing route by backtracing one segment, then adding two more // segments to the line // Debug.Log(" Next segment destination = " + mydestination_gate.name); // Debug.Log(" old_position_count = " + mylr.positionCount); int old_position_count = mylr.positionCount; positions = new Vector3[old_position_count + 3]; mylr.GetPositions(positions); positions[old_position_count] = positions[old_position_count - 2]; positions[old_position_count + 1] = new Vector3(positions[old_position_count - 2].x, endy, 0); positions[old_position_count + 2] = new Vector3(endx, endy, 0); mylr.positionCount = old_position_count + 3; } mylr.SetPositions(positions); // mylr.material = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Line.mat"); } }