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 WaitingTrucksCount : MonoBehaviour { |
|
private List<TruckMessage> waitingTrucks = new List<TruckMessage>(); |
|
//public static event Func<IntData,List<TruckMessage>,IntData> getWaitingTrucks; |
|
public static event Func<List<TruckMessage>, List<TruckMessage>> getWaitingTrucks; |
|
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/WaitingTruckItem") as GameObject; |
|
} |
|
} |
|
private void OnEnable() |
|
{ |
|
//IntData data = new IntData(0); |
|
waitingTrucks.Clear(); |
|
if(getWaitingTrucks != null) |
|
{ |
|
waitingTrucks = getWaitingTrucks(waitingTrucks); |
|
} |
|
GetComponent<Text>().text = waitingTrucks.Count.ToString(); |
|
foreach(Transform trans in content) |
|
{ |
|
Destroy(trans.gameObject); |
|
} |
|
foreach(TruckMessage msg in waitingTrucks) |
|
{ |
|
GameObject item = Instantiate(itemPre, content); |
|
item.GetComponent<WaitingTruckItem>().Set(msg); |
|
} |
|
} |
|
}
|
|
|