Last active
June 4, 2018 07:16
-
-
Save allencoded/0f200a35501dbc169a0ac58f21ad8236 to your computer and use it in GitHub Desktop.
GameTile
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
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Tilemaps; | |
public class GameTiles : MonoBehaviour { | |
public static GameTiles instance; | |
public Tilemap Tilemap; | |
public Dictionary<Vector3, WorldTile> tiles; | |
private void Awake() | |
{ | |
if (instance == null) | |
{ | |
instance = this; | |
} | |
else if (instance != this) | |
{ | |
Destroy(gameObject); | |
} | |
GetWorldTiles(); | |
} | |
// Use this for initialization | |
private void GetWorldTiles () | |
{ | |
tiles = new Dictionary<Vector3, WorldTile>(); | |
foreach (Vector3Int pos in Tilemap.cellBounds.allPositionsWithin) | |
{ | |
var localPlace = new Vector3Int(pos.x, pos.y, pos.z); | |
if (!Tilemap.HasTile(localPlace)) continue; | |
var tile = new WorldTile | |
{ | |
LocalPlace = localPlace, | |
WorldLocation = Tilemap.CellToWorld(localPlace), | |
TileBase = Tilemap.GetTile(localPlace), | |
TilemapMember = Tilemap, | |
Name = localPlace.x + "," + localPlace.y, | |
Cost = 1 // TODO: Change this with the proper cost from ruletile | |
}; | |
tiles.Add(tile.WorldLocation, tile); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment