/// <summary> /// Get a navNode from the map. /// </summary> /// <param name="worldPos">input in world space.</param> /// <param name="node">The node at the asked for position</param> /// <returns>True if node was found.</returns> public bool GetNode(Vector3 worldPos, out NavNode node) { Assert.IsTrue(initiated); Vector3Int cell = WorldToCell(worldPos); if (map.ContainsKey(cell)) { node = map.KeyMap[cell]; return(true); } node = null; return(false); }
public List <NavNode> GetConnectionsTo(NavNode node) { Assert.IsTrue(initiated); List <NavNode> connections = new List <NavNode>(); foreach (var dir in node.connections.AsV3IArray()) { if (map.ContainsKey((node.cellPos + dir))) { connections.Add(map.KeyMap[(node.cellPos + dir)]); } } return(connections); }
//INitiate tiles could be called bu the puzzle manager. private void InitiateTiles() { initiated = true; //if we do this at runtime, not for initialization, theres probably gonna need to be event unregistering and memory management issues. I dont have events yet soooo map.Clear(); //reset min and max to improbable states. _max = new Vector3Int(Int32.MinValue, Int32.MinValue, 0); _min = new Vector3Int(Int32.MaxValue, Int32.MaxValue, 0); BoundsInt bounds = tilemap.cellBounds; for (int x = bounds.xMin; x <= bounds.xMax; x++) { for (int y = bounds.yMin; y <= bounds.yMax; y++) { for (int z = bounds.zMin; z <= bounds.zMax; z++) //not officially supporting layered grids but might as well try. //Probably better to use multiple tilemaps. { Vector3Int position = new Vector3Int(x, y, z); NavTile nt = tilemap.GetTile(position) as NavTile; //todo z values? if (nt != null) { //Create NavNode NavNode node = new NavNode(position, this, nt.walkableDirections, nt.walkable); RegisterTile(position, node); if (defaultTileColor != null) { tilemap.SetColor(position, defaultTileColor.Value); } //Adjust Min and Max _min = new Vector3Int(Mathf.Min(_min.x, position.x), Mathf.Min(_min.y, position.y), 0); _max = new Vector3Int(Mathf.Max(_max.x, position.x), Mathf.Max(_max.y, position.y), 0); } } } } }
public bool ClearTile(NavNode node) { return(map.RemoveValue(node)); }
public void UnpaintTile(NavNode node) { node.painted = false; tilemap.SetColor(node.cellPos, defaultTileColor.Value); }
public void PaintTile(NavNode node, Color col) { node.painted = true; tilemap.SetColor(node.cellPos, col); }
public int Cost(NavNode current, NavNode next) { return(current.pathCost + next.pathCost); }
public virtual void SnapTo(NavNode newNode) { transform.position = newNode.worldPos; }