using UnityEngine;
using UnityEngine.Tilemaps;
namespace UnityEditor.Tilemaps
{
///
/// Utility class for creating Tiles
///
public class TileUtility
{
internal static void CreateNewTile()
{
string message = string.Format("Save tile'{0}':", "tile");
string newAssetPath = EditorUtility.SaveFilePanelInProject("Save tile", "New Tile", "asset", message, ProjectWindowUtil.GetActiveFolderPath());
// If user canceled or save path is invalid, we can't create the tile
if (string.IsNullOrEmpty(newAssetPath))
return;
AssetDatabase.CreateAsset(CreateDefaultTile(), newAssetPath);
}
/// Creates a Tile with defaults based on the Tile preset
/// A Tile with defaults based on the Tile preset
public static Tile CreateDefaultTile()
{
return ObjectFactory.CreateInstance();
}
/// Creates a Tile with defaults based on the Tile preset and a Sprite set
/// A Sprite to set the Tile with
/// A Tile with defaults based on the Tile preset and a Sprite set
[CreateTileFromPalette]
public static TileBase DefaultTile(Sprite sprite)
{
Tile tile = CreateDefaultTile();
tile.name = sprite.name;
tile.sprite = sprite;
tile.color = Color.white;
return tile;
}
}
}