๐Ÿ™‡โ€โ™€๏ธMapTool

๐ŸชMapTool

๋งต ํˆด์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„  Editor ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ทธ ์‚ฐํ•˜์— ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค (Resources์™€ ๊ฐ™์€ ๊ฐœ๋…)

Editor ์‚ฐํ•˜์— MapEditor๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ ์ด ๋–„ ์ด๊ฒƒ์€ ์‹ค์ œ ๋ผ์ด๋ธŒ์—์„œ ๋‚˜๊ฐ€๋ฉด ์•ˆ๋˜๊ธฐ ๋–„๋ฌธ์—

#if UNITY_EDITOR
#endif

๋กœ ๊ฐ์‹ธ์„œ ์šฐ๋ฆฌ๋งŒ ์“ธ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์•ผํ•œ๋‹ค

ํˆด ์ƒ์„ฑ ์˜ˆ์‹œ

// % (Ctrl), # (Shift), & (Alt)
[MenuItem("Tools/GenerateMap %#g+m")
private static void HelloWorld()
{
 if (EditorUtility.DisplayDialog("Hello World", "Create?", "Create", "Cancel"))
{ new GameObject("Hello World"); }
}

๐Ÿช๋งต ์ƒ์„ฑ ํˆด

// % (Ctrl), # (Shift), & (Alt)
    [MenuItem("Tools/GenerateMap %#gm")]
    private static void GenerateMap()
    {
        GameObject[] gameObjects = Resources.LoadAll<GameObject>("Prefabs/Map");

        foreach (GameObject go in gameObjects)
        {
            Tilemap tm = Util.FindChild<Tilemap>(go, "Tilemap_Collision", true);

            // 000010110110
            using (StreamWriter writer = File.CreateText($"Assets/Resources/Map/{go.name}.txt"))
            {
                writer.WriteLine(tm.cellBounds.xMin);
                writer.WriteLine(tm.cellBounds.xMax);
                writer.WriteLine(tm.cellBounds.yMin);
                writer.WriteLine(tm.cellBounds.yMax);

                for (int y = tm.cellBounds.yMax; y >= tm.cellBounds.yMin; y--)
                {
                    for (int x = tm.cellBounds.xMin; x <= tm.cellBounds.xMax; x++)
                    {
                        TileBase tile = tm.GetTile(new Vector3Int(x, y, 0));
                        if (tile != null)
                            writer.Write("1");
                        else
                            writer.Write("0");
                    }
                    writer.WriteLine();
                }
            }
        }
    }

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: