エディター拡張1(タイルマップ作製支援ツール)



タイルマップ作成支援ツール
// ★変更(必要なものだけ記述すること)
using UnityEngine;
using UnityEditor;
public class MapCreate : EditorWindow // ←変更すること!
{
static MapCreate window;
private int yokoSize;
private int tateSize;
private GameObject wrapper;
[MenuItem("TileMap/Create")]
static void Open()
{
window = CreateInstance<MapCreate>();
window.Show();
}
private void OnGUI()
{
yokoSize = EditorGUILayout.IntField("横の大きさ", yokoSize);
tateSize = EditorGUILayout.IntField("縦の大きさ", tateSize);
if(GUILayout.Button("MapCreate"))
{
wrapper = new GameObject("TileMaps");
for(int i = 0; i < yokoSize; i++)
{
for(int j = 0; j < tateSize; j++)
{
GameObject prefab = (GameObject)Resources.Load("Tile");
GameObject clone = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
clone.transform.localRotation = Quaternion.Euler(90, 0, 0);
clone.transform.position = new Vector3(i, 0, j);
// 自動的に親子関係を作る
clone.transform.SetParent(wrapper.transform);
}
}
}
if(GUILayout.Button("Close"))
{
Close();
}
}
}







【2019版】TowerD Ⅱ(基礎/全4回)
1 | エディター拡張1(タイルマップ作製支援ツール) |
2 | エディター拡張2(オブジェクト配置支援ツール) |
3 | エディター拡張3(オブジェクト配置支援ツールの改良) |
4 | エディター拡張4(Undo機能の実装) |



タイルマップ作成支援ツール
// ★変更(必要なものだけ記述すること)
using UnityEngine;
using UnityEditor;
public class MapCreate : EditorWindow // ←変更すること!
{
static MapCreate window;
private int yokoSize;
private int tateSize;
private GameObject wrapper;
[MenuItem("TileMap/Create")]
static void Open()
{
window = CreateInstance<MapCreate>();
window.Show();
}
private void OnGUI()
{
yokoSize = EditorGUILayout.IntField("横の大きさ", yokoSize);
tateSize = EditorGUILayout.IntField("縦の大きさ", tateSize);
if(GUILayout.Button("MapCreate"))
{
wrapper = new GameObject("TileMaps");
for(int i = 0; i < yokoSize; i++)
{
for(int j = 0; j < tateSize; j++)
{
GameObject prefab = (GameObject)Resources.Load("Tile");
GameObject clone = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
clone.transform.localRotation = Quaternion.Euler(90, 0, 0);
clone.transform.position = new Vector3(i, 0, j);
// 自動的に親子関係を作る
clone.transform.SetParent(wrapper.transform);
}
}
}
if(GUILayout.Button("Close"))
{
Close();
}
}
}







エディター拡張1(タイルマップ作製支援ツール)