备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
#endif
using UnityEngine;
[ExecuteInEditMode]
public class BackBroadEditor : MonoBehaviour
{
#if UNITY_EDITOR
public List<GameObject> prefabs; // 棋盘格子Prefab
public int width = 10; // 棋盘宽度
public int height = 5; // 棋盘高度
public float spacing = 1f; // 格子之间的间距
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 * spacing, y * spacing,0 );
GameObject obj = GetRandomSelection(prefabs);
GameObject broad = PrefabUtility.InstantiatePrefab(obj) as GameObject;
broad.transform.SetParent(this.transform);
broad.transform.localPosition = position;
}
}
}
private GameObject GetRandomSelection(List<GameObject> list)
{
System.Random random = new System.Random();
int n = list.Count;
int randomNumber = random.Next(0, n);
return list[randomNumber];
}
#endif
}