using UnityEngine; using UnityEditor; using System.Collections.Generic; using System.Linq; public class TEst : MonoBehaviour { public CityExcelData manager = new CityExcelData(); public AggregateStation aggregateStation; public List sprites = new List(); public List gameObjects = new List(); [ContextMenu("GetInfo")] public void CreateItemAsset() { manager.cityItems = null; manager.cityItems = ExcelTool.CreateItemArrayWithExcel(ExcelConfig.excelsFolderPath + "山东行政区划数据.xlsx"); for (int i = 0; i < transform.childCount; i++) { CityInfo c = transform.GetChild(i).GetComponent(); c.cityName = c.gameObject.name; for (int l = 0; l < manager.cityItems.Length; l++) { if (c.cityName == manager.cityItems[l].districtName) c.distCode = manager.cityItems[l].divisionNumber; } } } [ContextMenu("CreateStation")] public void CreateStation() { for (int i = 0; i < gameObjects.Count; i++) { DestroyImmediate(gameObjects[i]); } gameObjects.Clear(); for (int i = 0; i < transform.childCount; i++) { Transform t = transform.GetChild(i); for (int j = 0; j < sprites.Count; j++) { AggregateStation _aggregateStation = Instantiate(aggregateStation, t); _aggregateStation.transform.localPosition = new Vector3( Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), 2f); _aggregateStation.transform.localEulerAngles = new Vector3(90, 0, 0); _aggregateStation.SetInfo(sprites[j], "0"); gameObjects.Add(_aggregateStation.gameObject); } } } }