Search Unity

Tile Map Get Tilemap array

Discussion in '2D Experimental Preview' started by JuncleGrow, Apr 2, 2019.

  1. JuncleGrow

    JuncleGrow

    Joined:
    Apr 19, 2018
    Posts:
    4
    I think it useful to be able to get array of Tilemap, like:

    - Whole Tilemap
    - All sides (4 or 8) of specific tile

    I'm tired of making maps with hard coding or soft coding. I want to make it with Tilemap.
    I think it would be better to get array of script attached to Tile Asset.
    cf. https://forum.unity.com/threads/feature-request-attach-script-to-tileasset.654559/

    I could get where characters can go, distance of path, and so on.
     
    Last edited: Apr 2, 2019
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    822
    Could you explain more about what you mean by this?

    Right now, to get tiles around a particular position, you could try this:

    Code (CSharp):
    1.  
    2. var tiles = tilemap.GetTilesBlock(new BoundsInt(new Vector3Int(x -1, y - 1, z), new Vector3Int(3, 3, 1));
    3.  
     
  3. JuncleGrow

    JuncleGrow

    Joined:
    Apr 19, 2018
    Posts:
    4
    I'm sorry in a confusing representation. I'll explain my problem frankly.
    I have a huge array of numbers so I can store data of map.
    When I modified the map, I have to modify the array too. That's frustrating for me.
    What should I do for this problem?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    822
    I am not certain of what you mean by this. Could you explain more?

    I assume that when you modify the Tilemap, you need to modify an array of external data somewhere else? If so, is there a relation between this data and the Tilemap or the Tiles?
     
  5. JuncleGrow

    JuncleGrow

    Joined:
    Apr 19, 2018
    Posts:
    4
    I mean, I wanna tell AI a map.

    Here is a map, for example.
    image.png

    This is an array storing data of the map(0 is ground, and 1 is wall).

    Code (CSharp):
    1. int[,] map =
    2. {
    3.     { 1,1,1,1,1 },
    4.     { 1,0,0,1,1 },
    5.     { 1,1,0,0,1 },
    6.     { 1,0,0,0,1 },
    7.     { 1,1,1,1,1 },
    8. };
    If we have the array, AI can figure out where they can go(In this case, left side and down side). スクリーンショット 2019-04-30 18.19.53.png
     
unityunity