C# Rookiss Part7 MMORPG : MapTool
๐โโ๏ธ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();
}
}
}
}