网上演练贵港万达广场(人员密集)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.4 KiB

4 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class OilTanksManager : MonoBehaviour
{
//public Transform AllGuanQu;
public List<Transform> AllGuanQu = new List<Transform>();
public GameObject OilTankPrefab;
public Transform OilTankParent;
private ToggleGroup FatherGroup;
private List<OilTankMessage> AllList = new List<OilTankMessage>();
4 years ago
private void Awake()
{
if (GameSettings.othersSettings.SceneType != SceneType.)
{
gameObject.SetActive(false);
return;
}
}
4 years ago
void Start()
{
4 years ago
4 years ago
//AllGuanQu = GameObject.Find("GuanQu_normal").transform;
//for (int i = 0; i < AllGuanQu.childCount; i++)
//{
// if (AllGuanQu.GetChild(i).GetComponent<OilTankMessage>())
// {
// AllList.Add(AllGuanQu.GetChild(i).GetComponent<OilTankMessage>());
// }
//}
//FatherGroup = gameObject.AddComponent<ToggleGroup>();
//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<OilTankMessage>();
// foreach (var tank in tanks)
// {
// AllList.Add(tank);
// }
// }
//}
AllList = GameObject.Find("SceneAll/GuanQu").GetComponentsInChildren<OilTankMessage>().ToList();
FatherGroup = OilTankParent.gameObject.AddComponent<ToggleGroup>();
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<OilTankMessage> 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<OilTankController>().ChildList = new List<GameObject>();
c.GetComponent<OilTankController>().HasChild.gameObject.SetActive(true);
c.GetComponent<OilTankController>().MyManager = this;
c.GetComponent<Toggle>().group = FatherGroup;
c.name = item.ToList()[0].MyBaseMessage.TankFieldName.Split('#')[0];//ShowText + item.Key;
c.GetComponent<OilTankController>().DataBind();
ToggleGroup group = c.gameObject.AddComponent<ToggleGroup>();
group.allowSwitchOff = true;
foreach (var o in item.ToList())
{
GameObject cc = Instantiate(OilTankPrefab, OilTankParent);
cc.GetComponent<OilTankController>().MyManager = this;
cc.GetComponent<OilTankController>().HasChild.gameObject.SetActive(false);
cc.GetComponent<OilTankController>().MyMsg = o;
cc.name = o.MyBaseMessage.GuanQuName;//TankFieldNum + "_" + o.MyBaseMessage.TankFieldInnerNum;
cc.GetComponent<Toggle>().group = group;
cc.GetComponent<OilTankController>().DataBind();
cc.gameObject.SetActive(false);
c.GetComponent<OilTankController>().ChildList.Add(cc);
}
}
}
}
// Update is called once per frame
void Update()
{
}
}