using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Linq; public class OilTanksManager : MonoBehaviour { //public Transform AllGuanQu; public List AllGuanQu = new List(); public GameObject OilTankPrefab; public Transform OilTankParent; private ToggleGroup FatherGroup; private List AllList = new List(); private void Awake() { if (GameSettings.othersSettings.SceneType != SceneType.化工建筑) { gameObject.SetActive(false); return; } } void Start() { //AllGuanQu = GameObject.Find("GuanQu_normal").transform; //for (int i = 0; i < AllGuanQu.childCount; i++) //{ // if (AllGuanQu.GetChild(i).GetComponent()) // { // AllList.Add(AllGuanQu.GetChild(i).GetComponent()); // } //} //FatherGroup = gameObject.AddComponent(); //FatherGroup.allowSwitchOff = true; Init(); } private void Init() { //AllGuanQu.Add(GameObject.Find("3#GuanQu").transform); //AllGuanQu.Add(GameObject.Find("4#GuanQu").transform); //foreach (Transform item in AllGuanQu) //{ // if (item != null) // { // var tanks = item.GetComponentsInChildren(); // foreach (var tank in tanks) // { // AllList.Add(tank); // } // } //} AllList = GameObject.Find("SceneAll/GuanQu").GetComponentsInChildren().ToList(); FatherGroup = OilTankParent.gameObject.AddComponent(); FatherGroup.allowSwitchOff = true; //从Start移过来,避免编辑灾情库时加载灾情库也在Start里,加载普通火蔓延范围管线与这里生成的对象ID重复 DataBind(); } private void DataBind() { //{ var DataList = from OilFlowManage in AllList where OilFlowManage.MyBaseMessage.TankFieldName.Contains("GuanQu") select OilFlowManage; //Debug.Log(DataList.Count()); BindMethord(DataList, "罐区"); //} //{ // var DataList = from OilFlowManage in AllList where OilFlowManage.MyBaseMessage.TankFieldName.Contains("QiuGuan") select OilFlowManage; // //Debug.Log(DataList.Count()); // BindMethord(DataList, "球罐区"); //} } private void BindMethord(IEnumerable DataList, string ShowText) { var GroupResult = from OilTankMessage in DataList group OilTankMessage by OilTankMessage.MyBaseMessage.TankFieldName; foreach (var item in GroupResult) { if (item.ToList().Count > 0) { GameObject c = Instantiate(OilTankPrefab, OilTankParent); c.GetComponent().ChildList = new List(); c.GetComponent().HasChild.gameObject.SetActive(true); c.GetComponent().MyManager = this; c.GetComponent().group = FatherGroup; c.name = item.ToList()[0].MyBaseMessage.TankFieldName.Split('#')[0];//ShowText + item.Key; c.GetComponent().DataBind(); ToggleGroup group = c.gameObject.AddComponent(); group.allowSwitchOff = true; foreach (var o in item.ToList()) { GameObject cc = Instantiate(OilTankPrefab, OilTankParent); cc.GetComponent().MyManager = this; cc.GetComponent().HasChild.gameObject.SetActive(false); cc.GetComponent().MyMsg = o; cc.name = o.MyBaseMessage.GuanQuName;//TankFieldNum + "_" + o.MyBaseMessage.TankFieldInnerNum; cc.GetComponent().group = group; cc.GetComponent().DataBind(); cc.gameObject.SetActive(false); c.GetComponent().ChildList.Add(cc); } } } } // Update is called once per frame void Update() { } }