Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Quaky · Oct 21, 2019 at 08:13 AM · scripting problemunity 2dtilemap

Tilemap - How to merge more tilemaps into one array

I'm making a 2D RPG game in Unity. I need a room detection... so I would like to get all tiles from more tilemaps and merge them into one array in the script. I have a problem, because not all tiles are imported. For example it imports 11 door instead of 30.

My C# code:

 public class RoomController : MonoBehaviour{
 public Tilemap floor;
 public Tilemap walls;
 public Tilemap doors;
 public WorldGraph worldGraph;
 public List<Room> rooms;
 Queue<ClonedTile> queue;
 // Start is called before the first frame update
 void Start()
 {
     rooms = new List<Room>();
     rooms.Add( new Room() );
     UnityEngine.Debug.Log( "Rooms: " + rooms.Count );
     worldGraph = new WorldGraph(walls.cellBounds.size.x, walls.cellBounds.size.y, walls, floor, doors, this);
 }

This is my worldGraph class:

 public class WorldGraph {
 public ClonedTile[,] tiles;
 Tilemap walls;
 Tilemap floor;
 Tilemap door;
 Dictionary<ClonedTile, TileBase> originalTiles;
 public int width;
 public int height;
 RoomController roomController;

 public WorldGraph(int width, int height, Tilemap walls, Tilemap floor, Tilemap door, RoomController roomController ) {
     tiles = new ClonedTile[width, height];
     this.walls = walls;
     this.floor = floor;
     this.door = door;
     this.width = width;
     this.height = height;
     this.roomController = roomController;

     Debug.Log( width + " " + height );
     originalTiles = new Dictionary<ClonedTile, TileBase>();

     ImportTiles();
 // This is the place, where I import all tiles.

 public void ImportTiles() {
     for(int y = 0; y<height; y++ ) {
         for(int x = 0; x<width; x++ ) {
             Vector3Int pos = new Vector3Int( x, y, 0 );

             TileBase tile = floor.GetTile(pos);

             if(tile!= null ) {
                 tiles[x, y] = new ClonedTile( x, y, TileType.Floor, false );
             }

             if(tile == null ) {
                 tiles[x, y] = new ClonedTile( x, y, TileType.Empty, false );
             }

             tile = walls.GetTile( pos );
             if (tile != null ) { 
                 tiles[x, y] = new ClonedTile( x, y, TileType.Wall, true );
             }

             tile = door.GetTile( pos );
             if(tile!= null ) {
                 tiles[x, y] = new ClonedTile( x, y, TileType.Door, true );
             }
         }
     }

     int wallnumber = 0;
     int floornumber = 0;
     int doornumber = 0;
     int emptynumber = 0;
     foreach (ClonedTile t in tiles ) {

         t.roomController = roomController;
         roomController.GetOutsideRoom().Tiles.Add( t );
         t.hasRoom = false;



         switch ( t.type ) {
             case TileType.Wall:
                 wallnumber++;
                 break;
             case TileType.Door:
                 doornumber++;
                 break;
             case TileType.Floor:
                 floornumber++;
                 break;
             default:
                 emptynumber++;
                 break;
         }
     }
     Debug.Log( "Walls: " + wallnumber + " Floor: " + floornumber + " Doors: " + doornumber + " Empty: " + emptynumber );
 }

}

I would be glad for any suggestions.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ShadyProductions · Oct 21, 2019 at 08:24 AM

This is probably because you're going over the following grid size of walls.cellBounds.size.x, walls.cellBounds.size.y

But it could be that some of your doors are not contained within this grid? Perhaps you should loop over each map's cellbounds seperately?

This is just an idea, as I will need more information to help further.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

202 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D tilemaps - separation of view and data, prototyping doubts 0 Answers

Replicating MC Redstone Wiring 3 Answers

[Solved] Isometric Rule Tiles not Following Guidelines. 0 Answers

Raycast Not Working properly 1 Answer

Remove a single tile from a tilemap 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges