Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 8, 2025 04:15
Show Gist options
  • Save todorok1/a91fdf05887217092d5ee4a0b4a9a587 to your computer and use it in GitHub Desktop.
Save todorok1/a91fdf05887217092d5ee4a0b4a9a587 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第8回 Tilemapに関する機能を提供する管理クラス 変換用メソッドの説明
/// <summary>
/// ワールド座標からTilemap上の論理的な座標を取得します。
/// </summary>
/// <param name="worldPos">変換元のワールド座標</param>
public Vector3Int GetPositionOnTilemap(Vector3 worldPos)
{
var posOnTile = Vector3Int.zero;
if (_tilemapBase != null)
{
posOnTile =_tilemapBase.WorldToCell(worldPos);
}
return posOnTile;
}
/// <summary>
/// Tilemap上の座標からワールド座標を取得します。
/// </summary>
/// <param name="worldPos">変換元のTilemap上の座標</param>
public Vector3 GetWorldPosition(Vector3Int posOnTile)
{
var worldPos = Vector3.zero;
if (_tilemapBase != null)
{
worldPos = _tilemapBase.CellToWorld(posOnTile);
worldPos += _tilemapBase.tileAnchor;
}
return worldPos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment