Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        //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);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 public bool ClearTile(NavNode node)
 {
     return(map.RemoveValue(node));
 }
Exemplo n.º 5
0
 public void UnpaintTile(NavNode node)
 {
     node.painted = false;
     tilemap.SetColor(node.cellPos, defaultTileColor.Value);
 }
Exemplo n.º 6
0
 public void PaintTile(NavNode node, Color col)
 {
     node.painted = true;
     tilemap.SetColor(node.cellPos, col);
 }
Exemplo n.º 7
0
 public int Cost(NavNode current, NavNode next)
 {
     return(current.pathCost + next.pathCost);
 }
Exemplo n.º 8
0
 public virtual void SnapTo(NavNode newNode)
 {
     transform.position = newNode.worldPos;
 }