using UnityEngine; using UnityEditor; using System.Collections.Generic; using System.Linq; public class TEst : MonoBehaviour { public CityExcelData manager = new CityExcelData(); public AggregateStation aggregateStation; public Transform p; public bool isDeleteStationInstructs; public float h = 2; public int level = 0; [ContextMenu("GetInfo")] public void CreateItemAsset() { manager.cityItems = null; manager.cityItems = ExcelTool.CreateItemArrayWithExcel(ExcelConfig.excelsFolderPath + "山东行政区划数据.xlsx"); for (int i = 0; i < p.childCount; i++) { Transform t = p.GetChild(i); if (t.childCount > 0) { for (int j = 0; j < t.childCount; j++) { CityInfo cc = t.GetChild(j).GetComponent(); cc.cityName = cc.gameObject.name; for (int l = 0; l < manager.cityItems.Length; l++) { if (cc.cityName == manager.cityItems[l].districtName) cc.distCode = manager.cityItems[l].divisionNumber; } } } else { CityInfo c = t.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 < p.childCount; i++) { Transform t = p.GetChild(i); if (level == 1) { if (t.childCount > 0) { for (int g = 0; g < t.childCount; g++) { Transform tt = t.GetChild(g); if (tt.childCount > 0) { DestroyImmediate(tt.GetChild(0).gameObject); } AggregateStation _aggregateStation = Instantiate(aggregateStation, tt); _aggregateStation.transform.localPosition = new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), h); _aggregateStation.transform.localEulerAngles = new Vector3(60, 0, 0); } } } if (level == 0) { if (t.childCount > 0) { for (int y = 0; y < p.childCount; y++) { DestroyImmediate(p.GetChild(y).GetChild(0).gameObject); } } AggregateStation _aggregateStation = Instantiate(aggregateStation, t); _aggregateStation.transform.localPosition = new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f), h); _aggregateStation.transform.localEulerAngles = new Vector3(60, 0, 0); //_aggregateStation.SetInfo(sprites[j], "0"); } } } }