using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ArrivedPowerTotal : MonoBehaviour { public GameObject content; //private PowerPair arrivedPowers = new PowerPair(); public static event Func getArrivedPower; /// /// 记录所有已经到场的车辆 /// public static Dictionary>> arrivedCars = new Dictionary>>(); private int trucksCount = 0; private int firemenCount = 0; private void Awake() { if (content == null) { content = transform.parent.Find("Scroll View/Viewport/Content").gameObject; } } public static void ResertArrivePowerTotal() { arrivedCars.Clear(); } void OnEnable() { trucksCount = 0; firemenCount = 0; foreach (List> carlist in arrivedCars.Values) { foreach (KeyValuePair pair in carlist) { trucksCount += pair.Value; firemenCount += (int)pair.Key.PassengerCapacity * pair.Value; } } if (GameSettings.othersSettings.mode == Mode.manoeuvre) { firemenCount = 0; foreach (var item in GameSettings.othersSettings.DisplayName_Num_Dic.Keys) { if (GameSettings.othersSettings.DisPlay_Arrive_Dic[item]) { firemenCount += GameSettings.othersSettings.DisplayName_Num_Dic[item]; } } } GetComponent().text = "到场力量共" + arrivedCars.Count + "个中队" + trucksCount + "辆车," + firemenCount + "名消防员。"; content.GetComponent().CreateItems(arrivedCars); } /// /// 有新的中队车辆到场 /// /// /// public static void addArrivedCar(string team, List> cars) { List> arrivedList = new List>(); //之前已经有这个中队,将该中队已有的在途车辆提取出到typeCars if (arrivedCars.TryGetValue(team, out arrivedList)) { foreach (KeyValuePair item in cars) { //更新 AddCar(arrivedList, item); } } //之前没有这个中队 else { arrivedCars.Add(team, cars); } } private static void AddCar(List> typeCars, KeyValuePair item) { //之前保存过这种车型 for (int i = 0; i < typeCars.Count; i++) { if (typeCars[i].Key.TypeName == item.Key.TypeName) { typeCars[i] = new KeyValuePair(typeCars[i].Key, typeCars[i].Value + item.Value); return; } } //之前没保存过这种车型 typeCars.Add(item); } } /// /// 参战力量、到场力量使用 /// public class PowerPair { public PowerPair() { truckMsgs = new List(); teams = new List(); trucks = 0; firemen = 0; } /// /// 所有车辆信息 /// public List truckMsgs; /// /// 所有中队 /// public List teams; /// /// 参战、到场车辆计数 /// public int trucks; /// /// 参战、到场消防员计数 /// public int firemen; public void Clear() { trucks = 0; firemen = 0; truckMsgs.Clear(); } }