备份CatanBuilding瘦身独立工程
This commit is contained in:
34
Assets/Scripts/SandDigEditorScript/BoxBroadEditor.cs
Normal file
34
Assets/Scripts/SandDigEditorScript/BoxBroadEditor.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user