using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 获取所有参战车辆数 /// public class InBattleTrucksCount : MonoBehaviour { private List inBattleTrucks = new List(); //public static event Func getInBattleTrucks; public static event Func,List> getInBattleTrucks; public Transform content; public GameObject itemPre; private void Awake() { if (content == null) { content = transform.Find("Scroll View/Viewport/Content"); } if (itemPre == null) { itemPre = Resources.Load("ExternalForce/InBattleTruckItem") as GameObject; } } private void OnEnable() { //IntData data = new IntData(0); inBattleTrucks.Clear(); if(getInBattleTrucks != null) { inBattleTrucks = getInBattleTrucks(inBattleTrucks); } GetComponent().text = inBattleTrucks.Count.ToString(); foreach (Transform trans in content) { Destroy(trans.gameObject); } foreach (TruckMessage msg in inBattleTrucks) { GameObject item = Instantiate(itemPre, content); item.GetComponent().Set(msg); } } }