private void UpdateCells() { //Update Visual Inputs / Outputs foreach (InputCell input in gridManager.GetInputs()) { if (!inputs.ContainsKey(input)) { //Generate Prefab at position GameObject prefab = Instantiate(inputCellPrefab, gridParent); prefab.GetComponent <RectTransform>().anchoredPosition = visualGridManager.GetScreenFromGrid(input.Coordinates[0]); prefab.GetComponent <RectTransform>().localScale = Vector3.one * (5.0f / (Mathf.Min(visualGridManager.gridWidth, visualGridManager.gridHeight))); prefab.GetComponentInChildren <Text>().text = input.InputValue.ToString(); inputs.Add(input, prefab); } } foreach (OutputCell output in gridManager.GetOutputs()) { if (!outputs.ContainsKey(output)) { //Generate Prefab at position GameObject prefab = Instantiate(outputCellPrefab, gridParent); prefab.GetComponent <RectTransform>().anchoredPosition = visualGridManager.GetScreenFromGrid(output.Coordinates[0]); prefab.GetComponent <RectTransform>().localScale = Vector3.one * (5.0f / (Mathf.Min(visualGridManager.gridWidth, visualGridManager.gridHeight))); prefab.GetComponentInChildren <Text>().text = output.OutputTarget.ToString(); outputs.Add(output, prefab); } } }
void GenerateWire(List <CellCoordinates> _wirePath) { ClearLocalPath(); bool newWire = true; CellCoordinates currentStart = new CellCoordinates(0, 0), currentEnd = new CellCoordinates(0, 0); Vector2Int direction = Vector2Int.zero; GameObject currentWire = null; for (int i = 0; i < _wirePath.Count; i++) { if (newWire) //If this is a new wire, set this as the start point { currentStart = _wirePath[i]; newWire = false; Log("Visual Wire Manager: Start line at " + currentStart); } else { //Have we picked a direction? if (direction == Vector2Int.zero) { currentEnd = _wirePath[i]; direction = new Vector2Int((int)currentEnd.X - (int)currentStart.X, (int)currentEnd.Y - (int)currentStart.Y); Log("Visual Wire Manager: Forming at direction " + direction + " at " + currentEnd); currentWire = CreateWire(currentStart, currentEnd, direction); } else { //Is this cell in the same direction Vector2Int testDirection = new Vector2Int((int)_wirePath[i].X - (int)currentEnd.X, (int)_wirePath[i].Y - (int)currentEnd.Y); if (testDirection == direction) { currentEnd = _wirePath[i]; currentWire.GetComponent <RectTransform>().sizeDelta = new Vector2((visualGridManager.GetScreenFromGrid(currentStart) - visualGridManager.GetScreenFromGrid(currentEnd)).magnitude + 5, 10.0f); Log("Visual Wire Manager: Direction continues at " + currentEnd); } else { Log("Visual Wire Manager: Direction changes at " + currentEnd); //This is where this wire ends localGameObjects.Add(currentWire); //Reset and Continue currentWire = null; currentStart = currentEnd; direction = Vector2Int.zero; i--; } } } } if (currentWire != null) { localGameObjects.Add(currentWire); } localWire = _wirePath; }