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.
386 lines
15 KiB
386 lines
15 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine.UI;
|
||
|
using System;
|
||
|
using UnityEngine.Events;
|
||
|
using AX.TrackRecord;
|
||
|
|
||
|
public class EquipSubmit : MonoBehaviour {
|
||
|
|
||
|
public static List<GameObject> selectEquipPlayers = new List<GameObject>();//所选装备的人
|
||
|
|
||
|
public static Dictionary<string, CostEquip> costSelectedEquips = new Dictionary<string, CostEquip>();//选择的有消耗的装备
|
||
|
public static Dictionary<string, UnCostEquip> unCostSelectedEquips = new Dictionary<string, UnCostEquip>();//选择的无消耗的装备
|
||
|
private bool flag;
|
||
|
|
||
|
GameObject canvas;
|
||
|
GameObject BagEquipImg;
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
this.GetComponent<Button>().onClick.AddListener(SubmitSelectedEquips);
|
||
|
|
||
|
canvas = GameObject.Find("Canvas");
|
||
|
BagEquipImg = Resources.Load<GameObject>("UIPrefab/Equipment/BagEquipImg");
|
||
|
}
|
||
|
|
||
|
private void SubmitSelectedEquips()
|
||
|
{
|
||
|
flag = false;
|
||
|
|
||
|
bool tipFlag = GetLastUnCostSelectedEquips(unCostSelectedEquips);
|
||
|
|
||
|
if (!flag)
|
||
|
{
|
||
|
GetLastCostSelectedEquips(costSelectedEquips);
|
||
|
|
||
|
DrawEquipsInBag();
|
||
|
}
|
||
|
for (int i = 0; i < selectEquipPlayers.Count; i++)
|
||
|
{
|
||
|
selectEquipPlayers[i].GetComponent<Bag>().ChangeEquip();
|
||
|
}
|
||
|
|
||
|
if (RecordManager.Instance.IsRecording && !tipFlag)
|
||
|
{
|
||
|
TrackRecordHelpClass.RecordSubmitEquipEvent(selectEquipPlayers);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
this.GetComponent<Button>().onClick.RemoveListener(SubmitSelectedEquips);
|
||
|
}
|
||
|
|
||
|
private bool GetLastUnCostSelectedEquips(Dictionary<string, UnCostEquip> unCostSelectedEqp)
|
||
|
{
|
||
|
bool flag1 = false;
|
||
|
bool flag2 = false;
|
||
|
bool tipFlag = false;
|
||
|
foreach (var item in unCostSelectedEqp)
|
||
|
{
|
||
|
if (item.Key.Contains("消防避火服") || item.Key.Contains("隔热防护服") || item.Key.Contains("抢险救援服")
|
||
|
|| item.Key.Contains("消防防化服")|| item.Key.Contains("灭火防护服") || item.Key.Contains("指挥员") || item.Key.Contains("义务消防员"))
|
||
|
{
|
||
|
flag1 = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach (GameObject obj in selectEquipPlayers)
|
||
|
{
|
||
|
bool flag = false;
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquips = obj.GetComponent<Bag>().unCostSelectedEquips;
|
||
|
foreach (var item in unCostSelectedEquips)
|
||
|
{
|
||
|
if (item.Key.Contains("消防避火服") || item.Key.Contains("隔热防护服") || item.Key.Contains("抢险救援服")
|
||
|
|| item.Key.Contains("消防防化服") || item.Key.Contains("灭火防护服") || item.Key.Contains("指挥员") || item.Key.Contains("义务消防员"))
|
||
|
{
|
||
|
flag2 = true;
|
||
|
flag = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (flag) break;
|
||
|
}
|
||
|
|
||
|
if (flag1)
|
||
|
{
|
||
|
int count = 0;
|
||
|
foreach (var item in unCostSelectedEqp)
|
||
|
{
|
||
|
if (item.Key.Contains("消防避火服") || item.Key.Contains("隔热防护服") || item.Key.Contains("抢险救援服")
|
||
|
|| item.Key.Contains("消防防化服") || item.Key.Contains("灭火防护服") || item.Key.Contains("指挥员") || item.Key.Contains("义务消防员"))
|
||
|
{
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (count != 0)
|
||
|
{
|
||
|
if (count > 1)
|
||
|
{
|
||
|
GameObject TipWin = Instantiate(Resources.Load<GameObject>("UIPrefab/TipWindow")) as GameObject;
|
||
|
string tips = "每次只能选择一套套装!";
|
||
|
TipWin.GetComponent<TipWindowManager>().SetWindow(tips, null, null);
|
||
|
flag = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (!flag2)
|
||
|
{
|
||
|
foreach (GameObject obj in selectEquipPlayers)
|
||
|
{
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquips = obj.GetComponent<Bag>().unCostSelectedEquips;
|
||
|
foreach (var item in unCostSelectedEqp)
|
||
|
{
|
||
|
string[] str = item.Key.Split('/');
|
||
|
bool flag = false;
|
||
|
|
||
|
foreach (string key in unCostSelectedEquips.Keys)
|
||
|
{
|
||
|
if (key.IndexOf(str[2]) > -1)
|
||
|
{
|
||
|
flag = true;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!flag)
|
||
|
{
|
||
|
unCostSelectedEquips.Add(item.Key, item.Value);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GameObject TipWin = Instantiate(Resources.Load<GameObject>("UIPrefab/TipWindow")) as GameObject;
|
||
|
string tips = "是否确定换装?";
|
||
|
TipWin.GetComponent<TipWindowManager>().SetWindow(tips, new UnityAction(SureChangeEquip), null);
|
||
|
flag = true;
|
||
|
tipFlag = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
foreach (GameObject obj in selectEquipPlayers)
|
||
|
{
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquips = obj.GetComponent<Bag>().unCostSelectedEquips;
|
||
|
foreach (var item in unCostSelectedEqp)
|
||
|
{
|
||
|
string[] str = item.Key.Split('/');
|
||
|
bool flag = false;
|
||
|
|
||
|
foreach (string key in unCostSelectedEquips.Keys)
|
||
|
{
|
||
|
if (key.IndexOf(str[2]) > -1)
|
||
|
{
|
||
|
flag = true;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!flag)
|
||
|
{
|
||
|
unCostSelectedEquips.Add(item.Key, item.Value);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return tipFlag;
|
||
|
}
|
||
|
|
||
|
private void GetLastCostSelectedEquips(Dictionary<string, CostEquip> costSelectedEqp)
|
||
|
{
|
||
|
foreach (GameObject obj in selectEquipPlayers)
|
||
|
{
|
||
|
Dictionary<string, CostEquip> costSelectedEquips = obj.GetComponent<Bag>().costSelectedEquips;
|
||
|
foreach (var item in costSelectedEqp)
|
||
|
{
|
||
|
string[] str = item.Key.Split('/');
|
||
|
bool flag = false;
|
||
|
|
||
|
foreach (string key in costSelectedEquips.Keys)
|
||
|
{
|
||
|
if (key.IndexOf(str[2]) > -1)
|
||
|
{
|
||
|
costSelectedEquips[key].selectedEquipNum += item.Value.selectedEquipNum;
|
||
|
flag = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!flag)
|
||
|
{//所选的消耗装备,给多少个人选装就要实例化对应消防员的所选装备实例(防止所有消防员的所选装备实例指向同一个内存地址)
|
||
|
string key = item.Key;
|
||
|
|
||
|
CostEquip eqp = null;
|
||
|
if (str[2] == "消防高压水带")
|
||
|
{
|
||
|
//eqp = new pipeLine(item.Value.unit);
|
||
|
eqp = new CostEquip(item.Value.unit);
|
||
|
}
|
||
|
|
||
|
if (str[2] == "救生照明线")
|
||
|
{
|
||
|
//eqp = new lifeSaveLightLine(item.Value.unit);
|
||
|
eqp = new CostEquip(item.Value.unit);
|
||
|
}
|
||
|
|
||
|
eqp.selectedEquipName = item.Value.selectedEquipName;
|
||
|
eqp.selectedEquipNum = item.Value.selectedEquipNum;
|
||
|
eqp.useNum = item.Value.useNum;
|
||
|
|
||
|
costSelectedEquips.Add(key, eqp);
|
||
|
obj.GetComponent<AgentRecord>().SetList();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void SureChangeEquip()
|
||
|
{
|
||
|
foreach (var obj in selectEquipPlayers)
|
||
|
{
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquip = obj.GetComponent<Bag>().unCostSelectedEquips;
|
||
|
foreach (var item in unCostSelectedEquip)
|
||
|
{
|
||
|
if (item.Key.Contains("消防避火服") || item.Key.Contains("隔热防护服") || item.Key.Contains("抢险救援服")
|
||
|
|| item.Key.Contains("消防防化服") || item.Key.Contains("灭火防护服") || item.Key.Contains("指挥员") || item.Key.Contains("义务消防员"))
|
||
|
{
|
||
|
unCostSelectedEquip.Remove(item.Key);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
GetLastCostSelectedEquips(costSelectedEquips, selectEquipPlayers);
|
||
|
|
||
|
GetLastUnCostSelectedEquips(unCostSelectedEquips, selectEquipPlayers);
|
||
|
|
||
|
DrawEquipsInBag();
|
||
|
selectEquipPlayers[0].GetComponent<Bag>().ChangeEquip();//更换装备后,触发换装逻辑
|
||
|
|
||
|
if (RecordManager.Instance.IsRecording)
|
||
|
{
|
||
|
TrackRecordHelpClass.RecordSubmitEquipEvent(selectEquipPlayers);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void GetLastCostSelectedEquips(Dictionary<string, CostEquip> costSelectedEqp, List<GameObject> changeEqpPlayers)
|
||
|
{
|
||
|
foreach (GameObject obj in changeEqpPlayers)
|
||
|
{
|
||
|
Dictionary<string, CostEquip> costSelectedEquips = obj.GetComponent<Bag>().costSelectedEquips;
|
||
|
foreach (var item in costSelectedEqp)
|
||
|
{
|
||
|
string[] str = item.Key.Split('/');
|
||
|
bool flag = false;
|
||
|
|
||
|
foreach (string key in costSelectedEquips.Keys)
|
||
|
{
|
||
|
if (key.IndexOf(str[2]) > -1)
|
||
|
{
|
||
|
costSelectedEquips[key].selectedEquipNum += item.Value.selectedEquipNum;
|
||
|
flag = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!flag)
|
||
|
{//所选的消耗装备,给多少个人选装就要实例化对应消防员的所选装备实例(防止所有消防员的所选装备实例指向同一个内存地址)
|
||
|
string key = item.Key;
|
||
|
|
||
|
CostEquip eqp = null;
|
||
|
if (str[2] == "消防高压水带")
|
||
|
{
|
||
|
//eqp = new pipeLine(item.Value.unit);
|
||
|
eqp = new CostEquip(item.Value.unit);
|
||
|
}
|
||
|
|
||
|
if (str[2] == "救生照明线")
|
||
|
{
|
||
|
//eqp = new lifeSaveLightLine(item.Value.unit);
|
||
|
eqp = new CostEquip(item.Value.unit);
|
||
|
}
|
||
|
|
||
|
eqp.selectedEquipName = item.Value.selectedEquipName;
|
||
|
eqp.selectedEquipNum = item.Value.selectedEquipNum;
|
||
|
eqp.useNum = item.Value.useNum;
|
||
|
|
||
|
costSelectedEquips.Add(key, eqp);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void GetLastUnCostSelectedEquips(Dictionary<string, UnCostEquip> unCostSelectedEqp, List<GameObject> changeEqpPlayers)
|
||
|
{
|
||
|
foreach (GameObject obj in changeEqpPlayers)
|
||
|
{
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquips = obj.GetComponent<Bag>().unCostSelectedEquips;
|
||
|
foreach (var item in unCostSelectedEqp)
|
||
|
{
|
||
|
string[] str = item.Key.Split('/');
|
||
|
bool flag = false;
|
||
|
|
||
|
foreach (string key in unCostSelectedEquips.Keys)
|
||
|
{
|
||
|
if (key.IndexOf(str[2]) > -1)
|
||
|
{
|
||
|
flag = true;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!flag)
|
||
|
{
|
||
|
unCostSelectedEquips.Add(item.Key, item.Value);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void DrawEquipsInBag()
|
||
|
{
|
||
|
RemoveAllChild(canvas.transform.Find("BagWin").Find("BagImage"));
|
||
|
|
||
|
Dictionary<string, CostEquip> costSelectedEquips = selectEquipPlayers[0].GetComponent<Bag>().costSelectedEquips;
|
||
|
Dictionary<string, UnCostEquip> unCostSelectedEquips = selectEquipPlayers[0].GetComponent<Bag>().unCostSelectedEquips;
|
||
|
|
||
|
//存在消耗的装备
|
||
|
foreach (string key in costSelectedEquips.Keys)
|
||
|
{
|
||
|
string[] str = key.Split('/');
|
||
|
string equipSpriteNameX = str[2] + "X";
|
||
|
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
|
||
|
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
|
||
|
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
|
||
|
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
|
||
|
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
|
||
|
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
|
||
|
equipmentSelectedImg.transform.Find("Text").GetComponent<Text>().text = (costSelectedEquips[key].selectedEquipNum - costSelectedEquips[key].useNum).ToString();
|
||
|
equipmentSelectedImg.AddComponent<ViewBagEquip>();
|
||
|
}
|
||
|
|
||
|
//不存在消耗的装备
|
||
|
foreach (string key in unCostSelectedEquips.Keys)
|
||
|
{
|
||
|
string[] str = key.Split('/');
|
||
|
string equipSpriteNameX = str[2] + "X";
|
||
|
var equipSpriteX = Resources.Load<GameObject>("UIPrefab/Equipment/" + equipSpriteNameX);
|
||
|
var equipmentSelectedImg = Instantiate(BagEquipImg) as GameObject;
|
||
|
equipmentSelectedImg.name = equipSpriteNameX.Substring(0, equipSpriteNameX.Length - 1);
|
||
|
equipmentSelectedImg.transform.parent = canvas.transform.Find("BagWin").Find("BagImage");
|
||
|
equipmentSelectedImg.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 1f);
|
||
|
equipmentSelectedImg.GetComponent<Image>().sprite = equipSpriteX.GetComponent<SpriteRenderer>().sprite;
|
||
|
equipmentSelectedImg.AddComponent<ViewBagEquip>();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void RemoveAllChild(Transform tsf)
|
||
|
{
|
||
|
foreach (Transform t in tsf)
|
||
|
{
|
||
|
Destroy(t.gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|