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.
45 lines
1.4 KiB
45 lines
1.4 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
/// <summary> |
|
/// 获取所有参战车辆数 |
|
/// </summary> |
|
public class InBattleTrucksCount : MonoBehaviour { |
|
private List<TruckMessage> inBattleTrucks = new List<TruckMessage>(); |
|
//public static event Func<IntData,IntData> getInBattleTrucks; |
|
public static event Func<List<TruckMessage>,List<TruckMessage>> 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>().text = inBattleTrucks.Count.ToString(); |
|
foreach (Transform trans in content) |
|
{ |
|
Destroy(trans.gameObject); |
|
} |
|
foreach (TruckMessage msg in inBattleTrucks) |
|
{ |
|
GameObject item = Instantiate(itemPre, content); |
|
item.GetComponent<InBattleTruckItem>().Set(msg); |
|
} |
|
} |
|
}
|
|
|