using UnityEngine;
using UnityEngine.Tilemaps;
///
/// Helper script to generate placeholder tile sprites and tiles
/// Use this if you don't have tile graphics yet
///
public class TileGenerator
{
///
/// Creates a simple colored sprite at runtime
///
public static Sprite CreateColoredSprite(Color color, string name = "Tile")
{
Texture2D texture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
texture.name = name;
Color[] pixels = new Color[16 * 16];
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = color;
}
texture.SetPixels(pixels);
texture.Apply();
return Sprite.Create(texture, new Rect(0, 0, 16, 16), new Vector2(0.5f, 0.5f), 16);
}
///
/// Creates a simple checkered pattern texture for visual variety
///
public static Sprite CreateCheckerSprite(Color color1, Color color2, string name = "Checker")
{
Texture2D texture = new Texture2D(16, 16, TextureFormat.RGBA32, false);
texture.name = name;
Color[] pixels = new Color[16 * 16];
for (int y = 0; y < 16; y++)
{
for (int x = 0; x < 16; x++)
{
bool isEven = (x / 8 + y / 8) % 2 == 0;
pixels[y * 16 + x] = isEven ? color1 : color2;
}
}
texture.SetPixels(pixels);
texture.Apply();
return Sprite.Create(texture, new Rect(0, 0, 16, 16), new Vector2(0.5f, 0.5f), 16);
}
///
/// Creates a Tile asset from a sprite
///
public static Tile CreateTile(Sprite sprite)
{
Tile tile = ScriptableObject.CreateInstance();
tile.sprite = sprite;
return tile;
}
}