/// <summary> /// Decides which color to use for drawing the nodes. /// </summary> private Color GetColor(V2Node.NodeMode mode) { Color col = Color.white; switch (mode) { case V2Node.NodeMode.obstacle: col = obstacleColor != null ? obstacleColor : Color.black; break; case V2Node.NodeMode.startPoint: col = startPointColor != null ? startPointColor : Color.red; break; case V2Node.NodeMode.endPoint: col = endPointColor != null ? endPointColor : Color.green; break; case V2Node.NodeMode.path: col = pathColor != null ? pathColor : Color.yellow; break; } return(col); }
/// <summary> /// Creates a new grid. /// </summary> private void CreateGrid() { grid = new V2Node[gridSizeX, gridSizeY]; for (int x = 0; x < gridSizeX; x++) { for (int y = 0; y < gridSizeY; y++) { Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius); int i = Random.Range(0, 3); V2Node.NodeMode mod = i == 0 ? V2Node.NodeMode.obstacle : V2Node.NodeMode.normal; grid[x, y] = new V2Node(mod, worldPoint, x, y); } } }
/// <summary> /// Updates the editing mode depending on which key is pressed. /// </summary> private void UpdateEditMode() { editMode = V2Node.NodeMode.normal; if (Input.GetKey("q")) { editMode = V2Node.NodeMode.startPoint; } if (Input.GetKey("w")) { editMode = V2Node.NodeMode.endPoint; } if (Input.GetKey("a")) { editMode = V2Node.NodeMode.obstacle; } }