以下の内容はhttps://baba-s.hatenablog.com/entry/2022/05/30/110000より取得しました。


【Unity】Tilemap のすべての Position を取得する拡張メソッド

ソースコード

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public static class TilemapExtensions
{
    public static IEnumerable<Vector3Int> GetPositions( this Tilemap self )
    {
        var bound = self.cellBounds;

        for ( var x = bound.min.x; x < bound.max.x; ++x )
        {
            for ( var y = bound.min.y; y < bound.max.y; ++y )
            {
                yield return new Vector3Int( x, y, 0 );
            }
        }
    }
}

(Z 座標は未対応)

使用例

foreach ( var position in tilemap.GetPositions() )
{
    var tile = tilemap.GetTile<RuleTile>( position );

    Debug.Log( tile );
}



以上の内容はhttps://baba-s.hatenablog.com/entry/2022/05/30/110000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14