Hi,
Thank you for the 2d preview builds. It’s really fascinating to work with the new tools.
Yesterday I created a custom terrain tile to determine edges and it worked very well.
Today I tried to create a new tile for placing gameObjects (like collectibles and traps) but it’s not working. Seems there is a difference when Sprite is null and GetPreview is linked to a sprite. Even Tile Palette doesn’t show the tile but when I change the Sprite from null to m_preview it works. How can I change it to support showing the GameObject and no Tile in level?
Best Regards
namespace Game.Tile
{
[Serializable]
public class GameObjectTile : TileBase
{
[SerializeField]
private GameObject m_gameObject;
[SerializeField]
private Sprite m_preview;
#if UNITY_EDITOR
[MenuItem (“Assets/Create/Game Object Tile”)]
public static void CreateTerrainTile ()
{
string path = EditorUtility.SaveFilePanelInProject (“Save Game Object Tile”, “New Game Object Tile”, “asset”, “Save Game Object Tile”, “Assets”);
if (path == “”)
return;
AssetDatabase.CreateAsset (ScriptableObject.CreateInstance (), path);
}
public override Sprite GetPreview ()
{
return m_preview;
}
#endif
public override bool GetTileData (Vector3Int position, ITilemap tileMap, ref TileData tileData)
{
UpdateTile (position, tileMap, ref tileData);
return true;
}
private void UpdateTile (Vector3Int position, ITilemap tileMap, ref TileData tileData)
{
tileData.sprite = null;
tileData.gameObject = m_gameObject;
}
}
}