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(); public Transform p; public bool isDeleteStationInstructs; public float h = 2; [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 < gameObjects.Count; i++) { DestroyImmediate(gameObjects[i]); } gameObjects.Clear(); if (isDeleteStationInstructs) return; for (int i = 0; i < p.childCount; i++) { Transform t = p.GetChild(i); if (t.childCount > 0) { for (int g = 0; g < t.childCount; g++) { Transform tt = t.GetChild(g); for (int j = 0; j < sprites.Count; j++) { 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(90, 0, 0); _aggregateStation.SetInfo(sprites[j], "0"); gameObjects.Add(_aggregateStation.gameObject); } } } else { 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), h); _aggregateStation.transform.localEulerAngles = new Vector3(90, 0, 0); _aggregateStation.SetInfo(sprites[j], "0"); gameObjects.Add(_aggregateStation.gameObject); } } } } }