最近项目里用到unity的 tilemap,因为用的比较浅,主要是为了获得格子的坐标,所以做了一些测试。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class tileMapTest : MonoBehaviour {
public Sprite s1;
public Tilemap map;
public Tile tile;
public Sprite s2;
public Grid grid ;
// Use this for initialization
void Start () {
tile = new Tile();
tile.sprite = s1;
grid.cellSize = new Vector3(10 , 10 , 0);
StartCoroutine(SetTile( ));
}
IEnumerator SetTile() {
Tile t = ScriptableObject.CreateInstance<Tile>();
t.sprite = s2;
for ( int x = 0 ; x < 10 ; x++ ) {
for ( int y = 0 ; y < 10 ; y++ ) {
Debug.Log(x+","+y);
if ( x == y ) {
map.SetTile(new Vector3Int(x , y , 0) , tile);
}
else {
t.color = Random.ColorHSV();
map.SetTile(new Vector3Int(x , y, 0) , t);
}