private void CheckNeighbours() { for (int x = -1; x <= 1; x++) { Vector3 pos = new Vector3(transform.position.x + x, transform.position.y, transform.position.z); if (transform.position != pos) { if (Gridsystem.getGridTile(pos)) { neighbours.Add(Gridsystem.getGridTile(pos)); } } } for (int z = -1; z <= 1; z++) { Vector3 pos = new Vector3(transform.position.x, transform.position.y, transform.position.z + z); if (transform.position != pos) { if (Gridsystem.getGridTile(pos)) { neighbours.Add(Gridsystem.getGridTile(pos)); } } } }
void Start() { _startLocation = transform.position; _startRotation = transform.rotation; grid = GameObject.Find("System").GetComponent <Gridsystem>(); }
void Start() { _startLocation = transform.position; _startRotation = transform.rotation; _grid = GameObject.FindObjectOfType <Gridsystem>(); }
void Start () { obj_GridSystem = GameObject.FindGameObjectWithTag ("Grid").transform; gridSystem = obj_GridSystem.GetComponent<Gridsystem> (); sRender = gameObject.GetComponent<SpriteRenderer> (); playerPosition = gameObject.transform.position; blockSize = sprite.rect.x + 0.016f; }
void Start() { obj_GridSystem = GameObject.FindGameObjectWithTag("Grid").transform; gridSystem = obj_GridSystem.GetComponent <Gridsystem> (); sRender = gameObject.GetComponent <SpriteRenderer> (); playerPosition = gameObject.transform.position; blockSize = sprite.rect.x + 0.016f; }
void UpdateEvents() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction * 100, Color.red); if (Physics.Raycast(ray, out hit)) { if (Input.GetMouseButtonDown(0)) { if (_currentEvents == Events.SELECTED) { if (hit.transform.name == Constants.NAME_MOVE_BUTTON) { _currentEvents = Events.MOVING; _gSystem.ShowAllTiles(0); _gSystem.ShowAllTiles(1); UpdateTiles(); } else if (hit.transform.name == Constants.NAME_UPGRADE_BUTTON) { _currentEvents = Events.UPGRADE; UpgradeStructure(); } else { _currentEvents = Events.IDLE; } Destroy(GameObject.FindGameObjectWithTag(Constants.TAG_SELECTED_BUTTONS)); buttonsSpawned = false; _sController.EnableAllRays(); Gridsystem.EnableAllRays(); } else if (_currentEvents == Events.MOVING) { if (hit.transform.name == Constants.NAME_TILE) { if (openList.Contains(hit.transform.GetComponent <Gridtile>())) { Gridsystem.getGridTile(transform.position).occupied = false; transform.position = new Vector3(hit.transform.position.x, hit.transform.position.y + 0.4f, hit.transform.position.z); hit.transform.GetComponent <Gridtile>().occupied = true; Reset(); _gSystem.HideAllTiles(0); _gSystem.HideAllTiles(1); _sController.hasUpMoved = true; _currentEvents = Events.IDLE; } else { _currentEvents = Events.IDLE; Reset(); _gSystem.HideAllTiles(0); _gSystem.HideAllTiles(1); } } else { _currentEvents = Events.IDLE; Reset(); _gSystem.HideAllTiles(0); _gSystem.HideAllTiles(1); } } else if (_currentEvents == Events.IDLE) { if (hit.transform == _sController.hitPoint.transform) { _currentEvents = Events.SELECTED; ShowMiniMenu(); _sController.DisableAllRays(); Gridsystem.DisableAllRays(); } } } } }
void Start() { _gSystem = GameObject.FindObjectOfType <Gridsystem>(); _sController = gameObject.GetComponent <StructureController>(); }
private void UpdateTiles() { for (int i = 0; i < movementRange + 1; i++) { List <Gridtile> tiles = Gridsystem.GetGridTiles(); if (tiles.Count > 0) { Vector3 tilePosition = new Vector3(transform.position.x, tiles[0].transform.position.y, transform.position.z + i); Vector3 tileSidePositionX = new Vector3(transform.position.x + 1, tiles[0].transform.position.y, transform.position.z + 1); Vector3 tileSidePositionZ = new Vector3(transform.position.x - 1, tiles[0].transform.position.y, transform.position.z + 1); for (int j = 0; j < tiles.Count - 1; j++) { if (tiles[j].transform.position == tilePosition || tiles[j].transform.position == tileSidePositionX || tiles[j].transform.position == tileSidePositionZ) { if (tiles[j].type == Gridtile.TileType.FRIENDLY || tiles[j].type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(tiles[j]); } else { if (tiles[j].transform.position == tilePosition) { Vector3 addedTilePosition = new Vector3(tilePosition.x, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } else if (tiles[j].transform.position == tileSidePositionX) { Vector3 addedTilePosition = new Vector3(tilePosition.x + 1, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } else if (tiles[j].transform.position == tileSidePositionZ) { Vector3 addedTilePosition = new Vector3(tilePosition.x - 1, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } } } else if (tiles[j].type == Gridtile.TileType.PATH) { if (tiles[j].transform.position == tilePosition) { Vector3 addedTilePosition = new Vector3(tilePosition.x, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } if (addedSideExtra) { if (tiles[j].transform.position == tileSidePositionX) { Vector3 addedTilePosition = new Vector3(tilePosition.x + 1, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } else if (tiles[j].transform.position == tileSidePositionZ) { Vector3 addedTilePosition = new Vector3(tilePosition.x - 1, tilePosition.y, tilePosition.z + 1); if (Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.FRIENDLY || Gridsystem.getGridTile(addedTilePosition).type == Gridtile.TileType.ENEMY) { if (tiles[j].occupied == false) { openList.Add(Gridsystem.getGridTile(addedTilePosition)); } } } } } } } } } for (int k = 0; k < openList.Count; k++) { openList[k].GetComponent <Renderer>().material = openList[k].movementMaterial; openList[k].ChangeTransparency(0.50f); } }
public static List <Gridtile> Search(Gridtile start, Gridtile end) { if (start && end) { Gridsystem.ResetAllGridTiles(); List <Gridtile> openList = new List <Gridtile>(); List <Gridtile> closedList = new List <Gridtile>(); Gridtile currentTile; Gridtile neighbour; float gScore; bool gScoreIsBest; openList.Add(start); while (openList.Count > 0) { if (openList[0] != null) { openList.Sort(sortOnF); currentTile = openList[0]; if (currentTile == end) { return(getPathToTile(currentTile)); } openList.Remove(currentTile); closedList.Add(currentTile); currentTile.closed = true; currentTile.open = false; for (int tileCount = 0; tileCount < currentTile.neighbours.Count; tileCount++) { neighbour = currentTile.neighbours[tileCount]; if (neighbour.closed && neighbour.type == Gridtile.TileType.FRIENDLY || neighbour.closed && neighbour.type == Gridtile.TileType.ENEMY || neighbour.closed && neighbour.type == Gridtile.TileType.FORBIDDEN) { continue; } if (isDiagonal(currentTile, neighbour)) { gScore = currentTile.g + diagonalScore; } else { gScore = currentTile.g + horizontalScore; } gScoreIsBest = false; if (!neighbour.open && !neighbour.closed && neighbour.type == Gridtile.TileType.PATH || !neighbour.open && !neighbour.closed && neighbour.type == Gridtile.TileType.ENDPATH || !neighbour.open && !neighbour.closed && neighbour.type == Gridtile.TileType.STARTPATH) { gScoreIsBest = true; neighbour.h = heuristic(neighbour.transform.position, end.transform.position); openList.Add(neighbour); neighbour.open = true; } else if (gScore < neighbour.g) { gScoreIsBest = true; } if (gScoreIsBest) { neighbour.parent = currentTile; neighbour.g = gScore; neighbour.f = neighbour.g + neighbour.h; } } } else { openList.RemoveAt(0); } } } return(new List <Gridtile>()); }
void Start() { _gSystem = GameObject.FindGameObjectWithTag(Constants.TAG_VISUALSYSTEM).GetComponent<Gridsystem>(); }
public static List<Gridtile> Search(Gridsystem grid, Gridtile start, Gridtile end) { if (start && end && end.onPerspective) { Gridsystem.ResetAllGridTiles(); start.GetComponent<Renderer>().material.color = Color.yellow; end.GetComponent<Renderer>().material.color = Color.red; List<Gridtile> openList = new List<Gridtile>(); List<Gridtile> closedList = new List<Gridtile>(); Gridtile currentTile; Gridtile neighbour; float gScore; bool gScoreIsBest; openList.Add(start); while(openList.Count > 0) { if(openList[0] != null) { openList.Sort(sortOnF); currentTile = openList[0]; if(currentTile == end) { return getPathToTile(currentTile); } openList.Remove(currentTile); closedList.Add(currentTile); currentTile.closed = true; currentTile.open = false; for (int tileCount = 0; tileCount < currentTile.neighbours.Count; tileCount++) { neighbour = currentTile.neighbours[tileCount]; if (neighbour.closed && !neighbour.onPerspective) { continue; } if (isDiagonal(currentTile, neighbour)) { gScore = currentTile.g + diagonalScore; } else { gScore = currentTile.g + horizontalScore; } gScoreIsBest = false; if(!neighbour.open && !neighbour.closed) { gScoreIsBest = true; neighbour.h = heuristic(neighbour.transform.position, end.transform.position); openList.Add(neighbour); neighbour.open = true; if (neighbour != end) neighbour.GetComponent<Renderer>().material.color = Color.green; } else if (gScore < neighbour.g) { gScoreIsBest = true; } if(gScoreIsBest) { neighbour.parent = currentTile; neighbour.g = gScore; neighbour.f = neighbour.g + neighbour.h; } } } else { openList.RemoveAt(0); } } } return new List<Gridtile>(); }
void Start() { _startLocation = transform.position; _startRotation = transform.rotation; _grid = GameObject.FindObjectOfType<Gridsystem>(); }
void Start() { obj_gridSystem = GameObject.FindGameObjectWithTag("Grid").transform; gridSystem = obj_gridSystem.GetComponent <Gridsystem> (); }
void Start () { obj_gridSystem = GameObject.FindGameObjectWithTag ("Grid").transform; gridSystem = obj_gridSystem.GetComponent<Gridsystem> (); }
void Start() { _gSystem = GameObject.FindObjectOfType<Gridsystem>(); _sController = gameObject.GetComponent<StructureController>(); }