ShanDongVirtualPowerPlant/u3d-ShanDongVirtualPowerPlant/Assets/Adam/Scripts/TEst.cs

94 lines
3.4 KiB
C#

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<Sprite> sprites = new List<Sprite>();
public List<GameObject> gameObjects = new List<GameObject>();
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<CityInfo>();
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<CityInfo>();
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);
}
}
}
}
}