35 lines
936 B
C#
35 lines
936 B
C#
|
|
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class BoxBroadEditor : MonoBehaviour
|
|
{
|
|
#if UNITY_EDITOR
|
|
public int width = 10; // 棋盘宽度
|
|
public int height = 5; // 棋盘高度
|
|
public float scale = 1;
|
|
|
|
public void GenerateBoard()
|
|
{
|
|
// 清除现有的子对象
|
|
foreach (Transform child in transform)
|
|
{
|
|
DestroyImmediate(child.gameObject);
|
|
}
|
|
|
|
// 生成新的棋盘
|
|
for (int x = 0; x < width; x++)
|
|
{
|
|
for (int y = 0; y < height; y++)
|
|
{
|
|
Vector3 position = new Vector3(x * scale, y * scale ,0 );
|
|
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
|
cube.transform.SetParent(this.transform);
|
|
cube.transform.localPosition = position;
|
|
cube.transform.localScale = new Vector3(scale, scale, scale);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|