-
-
Save todorok1/a91fdf05887217092d5ee4a0b4a9a587 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第8回 Tilemapに関する機能を提供する管理クラス 変換用メソッドの説明
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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