コード例 #1
0
ファイル: GameMap.cs プロジェクト: AldeRoberge/UnityGameMap
        private void PlaceObjectOfTypeAt(string id, TileLoc loc)
        {
            ConnectedTileObject cto = connectedGenericTileMap.GetConnectedTileAt(loc);

            bool shouldPlace = true;

            if (cto != null)
            {
                Debug.Log("Removing underlying tile of type " + id + " at " + loc + ".");
                connectedGenericTileMap.RemoveConnectedTileAt(cto.tileLoc);

                if (cto.GetObjectType() == pathObjectTypeToBuild)
                {
                    // Do not place new path.
                    shouldPlace = false;
                }
            }

            if (shouldPlace)
            {
                Debug.Log("Placing a new tile of type " + id + " at " + loc + ".");
                connectedGenericTileMap.CreateConnectedTileObject(loc, pathObjectTypeToBuild);
            }

            // Update the surrounding tiles
            UpdateNeigboursOf(loc);
        }
コード例 #2
0
        public ConnectedTileObject CreateConnectedTileObject(TileLoc loc, int objectType = -1)
        {
            GameObject tile = GameMap.Instance.CreateTileAt(loc, transform);

            ConnectedTileObject cto = tile.AddComponent <ConnectedTileObject>();

            ConnectedTiles[loc] = cto;
            cto.objectType      = objectType;
            cto.tileLoc         = loc;
            cto.UpdateConnection();

            return(cto);
        }
コード例 #3
0
ファイル: GameMap.cs プロジェクト: AldeRoberge/UnityGameMap
        private void UpdateNeigboursOf(TileLoc tileLoc)
        {
            // Update neighbours
            foreach (TileLoc pos in ConnectedTileUtils.Cardinal)
            {
                ConnectedTileObject c =
                    GameMap.Instance.connectedGenericTileMap.GetConnectedTileAt(pos.RelativeTo(tileLoc));

                if (c != null)
                {
                    Debug.Log("Updating " + tileLoc + "...");
                    c.UpdateConnection();
                }
            }
        }