void ClearDrawPath() { while (drawPathStack.Count > 0) { Node popped = drawPathStack.Pop(); ClickableTile tile = map.tiles[popped.pos.x, popped.pos.y]; if (!tile.IsAvailable()) { tile.Highlight(false); } tile.SetValueText(tile.GetValue()); } }
void DrawPath() { if (Input.GetButtonUp("Fire1")) { //We have let go, return to idle state state = ControllerState.idle; //All moves used? if (drawPathStack.Count - 1 == selectedUnit.GetMoveSpeed()) { //Is this a valid path that leads to a destination tile? Node finalNode = drawPathStack.Peek(); if (map.tiles[finalNode.pos.x, finalNode.pos.y].IsAvailable()) { //Feed our unit this path Debug.Log("sending drawn path to unit"); List <Node> path = new List <Node>(drawPathStack); path.Reverse(); selectedUnit.SetPath(path); } } else { map.ResetTileDrawPath(); } ClearDrawPath(); return; } Node currentNode = drawPathStack.Peek(); RaycastHit hit; //Check if we are hovering over tile if (MouseCast(out hit)) { if (hit.transform.tag == "Tile") { ClickableTile tempTile = hit.transform.GetComponent <ClickableTile>(); Node tempNode = map.nodes[tempTile.pos.x, tempTile.pos.y]; //Is the tile a walkable neighbor tile? if (NodeIsNeighbour(currentNode, tempNode) && map.UnitCanEnterTile(tempNode.pos, selectedUnit)) { //Is it the previous path node? if (drawPathStack.Contains(tempNode)) { //pop current position Node popped = drawPathStack.Pop(); ClickableTile tile = map.tiles[popped.pos.x, popped.pos.y].GetComponent <ClickableTile>(); Debug.Log(tile.GetValue()); tile.DrawHighlight(false, .01f); tile.SetValueText(tile.GetValue()); audioSource.volume = .4f; audioSource.pitch = 1.9f; audioSource.clip = sndClickUp; audioSource.Play(); //adjust available tiles var coordOptions = selectedUnit.GetAvailableTileOptions(tempNode, selectedUnit.GetMoveSpeed() - drawPathStack.Count + 1); map.ResetTileAvailability(); List <Map.Coord> coordList = new List <Map.Coord>(); for (int i = 0; i < selectedUnit.coordOptions.Length; i++) { if (coordOptions.Contains(selectedUnit.coordOptions[i])) { coordList.Add(selectedUnit.coordOptions[i]); } } map.MakeTilesAvailable(coordList.ToArray()); } //If not, we can push this neighbor is we have remianing moves, one step closer to destination else if (drawPathStack.Count - 1 < selectedUnit.GetMoveSpeed()) { { //adjust available tiles var coordOptions = selectedUnit.GetAvailableTileOptions(tempNode, selectedUnit.GetMoveSpeed() - drawPathStack.Count); map.ResetTileAvailability(); List <Map.Coord> coordList = new List <Map.Coord>(); for (int i = 0; i < selectedUnit.coordOptions.Length; i++) { if (coordOptions.Contains(selectedUnit.coordOptions[i])) { coordList.Add(selectedUnit.coordOptions[i]); } } map.MakeTilesAvailable(coordList.ToArray()); drawPathStack.Push(tempNode); //highlight tempTile? show its part of path tempTile.DrawHighlight(true, .02f); tempTile.SetValueText(tempTile.GetValue() + drawPathStack.Count - 1); audioSource.volume = .95f; audioSource.pitch = (((float)drawPathStack.Count - 1f) / (float)selectedUnit.GetMoveSpeed()) * .1f + .9f; audioSource.clip = sndClickDown; audioSource.Play(); } } } } //end MouseCast } }