-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileGeneratorEditor.cs
More file actions
50 lines (42 loc) · 1.28 KB
/
TileGeneratorEditor.cs
File metadata and controls
50 lines (42 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor (typeof (TileGenerator))]
public class TileGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if(GUILayout.Button("Generate Board"))
{
GenerateBoard();
}
if (GUILayout.Button("Clear Board"))
{
ClearBoard((TileGenerator)target);
}
}
void GenerateBoard()
{
TileGenerator tg = (TileGenerator)target;
ClearBoard(tg);
for (int i = 0; i < tg.size.x; i++)
{
for (int j = 0; j < tg.size.y; j++)
{
var newTile = PrefabUtility.InstantiatePrefab(tg.tile) as GameObject;
newTile.transform.SetParent(tg.transform);
newTile.transform.localPosition = new Vector3((i-j)*tg.offset.x, -(i+j)*tg.offset.y, 1-(i+j)/(tg.size.x+tg.size.y));
newTile.name += " " + i + "-" + j;
}
}
}
void ClearBoard(TileGenerator tg)
{
for (int i = tg.transform.childCount-1; i >= 0; i--)
{
DestroyImmediate(tg.transform.GetChild(i).gameObject);
}
}
}