-
-
Save todorok1/07b033e385600a62bf9fb33e8cab1d99 to your computer and use it in GitHub Desktop.
シンプルRPGチュートリアル第120回 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> | |
| /// 対象の座標に移動できるかどうかを確認します。 | |
| /// </summary> | |
| /// <param name="targetPos">移動先のTilemap上の座標</param> | |
| public bool CanEntryTile(Vector3Int targetPos) | |
| { | |
| bool canEntry = true; | |
| if (_noEntryTileData == null) | |
| { | |
| SimpleLogger.Instance.LogWarning("侵入できないタイル一覧の定義ファイルがnullです。[NoEntryTileData]のフィールドに定義ファイルをアサインしてください。"); | |
| return canEntry; | |
| } | |
| // 移動先の座標にキャラクターがいるか確認します。 | |
| if (IsPositionUsed(targetPos)) | |
| { | |
| canEntry = false; | |
| return canEntry; | |
| } | |
| // 各レイヤーのタイルを確認します。 | |
| List<TileBase> targetTiles = GetTilesOnPosition(targetPos); | |
| // 定義ファイルのタイルと照合します。 | |
| foreach (var tile in targetTiles) | |
| { | |
| if (tile == null) | |
| { | |
| break; | |
| } | |
| if (_noEntryTileData.noEntryTiles == null) | |
| { | |
| break; | |
| } | |
| var noEntryTile = _noEntryTileData.noEntryTiles.Find(t => t.name == tile.name); | |
| if (noEntryTile != null) | |
| { | |
| canEntry = false; | |
| break; | |
| } | |
| } | |
| return canEntry; | |
| } | |
| /// <summary> | |
| /// 対象の座標が、イベントの実行時にひとつ先まで確認する対象のタイルか確認します。 | |
| /// </summary> | |
| /// <param name="targetPos">移動先のTilemap上の座標</param> | |
| public bool IsThroughTile(Vector3Int targetPos) | |
| { | |
| bool isThroughTile = false; | |
| if (_throughTileData == null) | |
| { | |
| SimpleLogger.Instance.LogWarning("ひとつ先まで確認するタイル一覧の定義ファイルがnullです。[ThroughTileData]のフィールドに定義ファイルをアサインしてください。"); | |
| return isThroughTile; | |
| } | |
| // 各レイヤーのタイルを確認します。 | |
| List<TileBase> targetTiles = GetTilesOnPosition(targetPos); | |
| // 定義ファイルのタイルと照合します。 | |
| foreach (var tile in targetTiles) | |
| { | |
| if (tile == null) | |
| { | |
| break; | |
| } | |
| if (_throughTileData.throughTiles == null) | |
| { | |
| break; | |
| } | |
| var throughTile = _throughTileData.throughTiles.Find(t => t.name == tile.name); | |
| if (throughTile != null) | |
| { | |
| isThroughTile = true; | |
| break; | |
| } | |
| } | |
| return isThroughTile; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment