void OnState() { if (state == UIState.CREATE) { int buildingWidth = 5; int buildingHeight = 5; Vector2Int mouseCoord = World.nodeCoordFromWorldPos((Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition) - new Vector2((buildingWidth - 1) / 2f * 1.044f, 0)); PlaceableReturn placeableReturn = Placeable(mouseCoord.x, mouseCoord.y, buildingWidth, buildingHeight); RemoveMarkers(); if (Input.GetMouseButtonDown(0) && placeableReturn.placeable) { Building building = new Building(Tower); List <BuildingNode> newNodes = new List <BuildingNode>(); foreach (PlanetNode n in placeableReturn.placeableNodes) { BuildingNode newNode = new BuildingNode(n.Q, n.R, n.worldPos, building); newNodes.Add(newNode); World.nodes[new Vector2Int(n.Q, n.R)] = newNode; World.planetNodes.TryRemove(new Vector2Int(n.Q, n.R), out _); } building.buildingNodes = newNodes; HashSet <PlanetNode> workerNodes = new HashSet <PlanetNode>(); foreach (PlanetNode n in placeableReturn.placeableNodes) { foreach (PlanetNode neighbour in n.getNeighbours()) { if (!workerNodes.Contains(neighbour)) { workerNodes.Add(neighbour); } } } building.workerNodes = workerNodes; InstantiateJob j = new InstantiateJob(building); JobManager.instance.QueueJob(j); _workerNodes = workerNodes; ExitState(UIState.CREATE); state = UIState.IDLE; EnterState(state); } else { SetMarkers(placeableReturn); } } }
void SetMarkers(PlaceableReturn placeableReturn) { b = placeableReturn.placeableNodes; foreach (PlanetNode n in placeableReturn.placeableNodes) { GameObject gameObject = ObjectPool.Instance.pools["BlueTransparentHexagon"].get(n.worldPos, Quaternion.identity); blueTransparentHexagon.Add(gameObject); gameObject.SetActive(true); } foreach (Node n in placeableReturn.nonPlaceableNodes) { GameObject gameObject = ObjectPool.Instance.pools["RedTransparentHexagon"].get(n.worldPos, Quaternion.identity); redTransparentHexagon.Add(gameObject); gameObject.SetActive(true); } }