【问题标题】:Is there a way to bulk create tile assets from a collection of tile images?有没有办法从一组平铺图像中批量创建平铺资产?
【发布时间】:2020-06-19 02:55:31
【问题描述】:

有没有办法批量创建这种类型的磁贴资产https://docs.unity3d.com/Manual/Tilemap-TileAsset.html

来自运行前的 2D 精灵集合?我怀疑可能有一种方法可以使用这样的编辑器脚本来做到这一点: https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html

这将节省大量时间,而不必在项目文件夹中单独复制图块并为新图块一一选择默认图像。

在这种情况下,我宁愿避免通常的拖放到瓷砖调色板,因为除非我实例化一个瓷砖地图预制件,否则该过程生成的瓷砖不能真正通过代码单独访问,我不想这样做.

【问题讨论】:

  • 你的意思是像this
  • @derHugo,不,这是一个使用瓷砖调色板的瓷砖地图,我特别说过我要避免。

标签: c# unity3d


【解决方案1】:

这就是我一直在寻找的答案。

using UnityEngine;
using UnityEditor;
using UnityEngine.Tilemaps;

public class TileParser : MonoBehaviour
{
    private const string inputPath = "Tilesets";
    private const string outputPath = "Assets/Tiles/";
    [MenuItem("Pre Production/Parse Tiles")]
    public static void ParseTiles()
    {
        var sprites = Resources.LoadAll<Sprite>(inputPath);

        foreach(var sprite in sprites)
        {
            Tile t = ScriptableObject.CreateInstance<Tile>();
            t.name = sprite.name;
            t.sprite = sprite;
            AssetDatabase.CreateAsset(t, string.Format("{0}{1}.asset", outputPath, t.name));
        }
        Debug.Log(sprites.Length + " tiles created at " + outputPath);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    相关资源
    最近更新 更多