1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Unity 6.4でTilemap関連の構造体とそれらを使ったメソッドが増えそう

Posted at

Unity 6.4で、Tilemap関連の構造体、そしてそれらを使ったメソッドが増えそうです。

前提

本記事は、まだベータ段階のUnityの情報を元にしています。
対象バージョンは、Unity 6000.4.0b4です。

追加される構造体

Unity 6.4でTilemapクラスの「入れ子になった構造体」として、次の3個の構造体が追加されそうです。

  • TileArray
  • PositionArray
  • SpriteArray

それぞれIEnumerable<T>インターフェースを実装しています。また、Lengthプロパティーとインデクサーを持っています。

追加されるメソッド

本記事で紹介するメソッドはどのメソッドも、Unity.Collections.Allocator型を引数にとるオーバーロードと、Unity.Collections.MemoryLabel型を引数に取るオーバーロードが追加されています。なお、前者のAllocator型を引数に取るオーバーロードは、省略可能な引数としてAllocator.Tempが設定されています。


TileArray型を使うメソッドとして、TilemapクラスにGetUsedTilesメソッドが追加されました。

  • public Tilemap.TileArray GetUsedTiles(Allocator allocator = Allocator.Temp);
  • public Tilemap.TileArray GetUsedTiles(MemoryLabel memoryLabel);

対象のTilemapが利用している「TileBase」を、TileArrayを通して列挙・取得できるメソッドです。


同じくTileArray型を使うメソッドとして、TilemapクラスにGetTilesメソッドが追加されました。

  • public Tilemap.TileArray GetTiles(BoundsInt bounds, Allocator allocator = Allocator.Temp);
  • public Tilemap.TileArray GetTiles(BoundsInt bounds, MemoryLabel memoryLabel);

対象のTilemapにおいて、boundsにあるTileBaseを、TileArrayを通して列挙・取得できるメソッドです。

また、GetTilesメソッドには、out引数としてTileArray型とPositionArray型を使うオーバーロードも存在します。

  • public int GetTiles(BoundsInt bounds, out Tilemap.PositionArrray positions, out Tilemap.TileArray tiles, Allocator allocator = Allocator.Temp, bool withinBounds = true);
  • public int GetTiles(BoundsInt bounds, out Tilemap.PositionArrray positions, out Tilemap.TileArray tiles, MemoryLabel memoryLabel, bool withinBounds = true);


SpriteArray型を使うメソッドとして、TilemapクラスにGetUsedSpritesメソッドが追加されました。

  • public Tilemap.SpriteArray GetUsedSprites(Allocator allocator = Allocator.Temp);
  • public Tilemap.SpriteArray GetUsedSprites(MemoryLabel memoryLabel);

対象のTilemapが利用している「Sprite」を、SpriteArrayを通して列挙・取得できるメソッドです。

以前から存在した類似メソッド

かなり前からTilemapクラスには次のようなメソッドがありました。

  • GetUsedTilesNonAlloc
  • GetTilesBlockNonAlloc
  • GetTilesRangeNonAlloc
  • GetUsedSpritesNonAlloc

これらの既存メソッドは、配列を引数として渡し、その配列の中身として結果を受け取るメソッドです。「引数として渡した配列の長さが結果のデータ長より短いと、求めたいデータが一部受け取れない」という点が使いにくそうでした。

Unity 6.4で新たにTilemapに追加されるメソッドは、どれも上記のメソッドと同じようなことができるメソッドです。同じようなメソッドですが、TileArrayなどを引数として返したり、out引数として返したりすることで、使いやすさが向上していそうです。

感想

Unity 6.4において、Tilemapには「GetTileEntityId」が追加されています。こちらも気になりますね。

Tilemapが進化・パワーアップして、嬉しい!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?