using UnityEngine;
using System.Collections;

public class Tile {
	const float TEXTURE_TILE_SIZE = 1f * 16f / 512f;
	const float CORRECTION = 1f / (512f * 64f);
	public const float TILE_SIZE = 1.6f;
	
	static Sprite CreateSprite (Transform transform, Coordinate tileUV, Vector3 position, Material material){
		Sprite tile = Sprite.Create(
		                            transform, position, 
		                            new Vector2(TILE_SIZE, TILE_SIZE), 
		                            material);
		tile.SetUV(
				new Rect(
				         tileUV.x * TEXTURE_TILE_SIZE + CORRECTION, 
				         tileUV.y * TEXTURE_TILE_SIZE + CORRECTION, 
				         TEXTURE_TILE_SIZE - CORRECTION * 2f, TEXTURE_TILE_SIZE - CORRECTION * 2f));
		return tile;
	}
	
	public static Sprite CreateChar(Transform transform, Coordinate tileUV, Vector3 position){		
		return CreateSprite(transform, tileUV, position, Resources.Load("Material/Characters") as Material);
	}
	
	public static Sprite CreateTile(Transform transform, Coordinate tileUV, Vector3 position){		
		return CreateSprite(transform, tileUV, position, Resources.Load("Material/Main") as Material);
	}
}
