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.
461 lines
14 KiB
461 lines
14 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using AX.MessageSystem; |
|
using System; |
|
using UnityEngine.AI; |
|
|
|
public enum Cloth |
|
{ |
|
战斗服黄, |
|
避火服, |
|
防化服, |
|
隔热服 |
|
} |
|
public class Bag : MonoBehaviour |
|
{ |
|
|
|
public List<Equip> EquipList = new List<Equip>(); |
|
private Transform zhandoufu_yellow; |
|
private Transform BHF; |
|
private Transform FHF; |
|
private Transform GRF; |
|
private XiaoFangYuanDrawLine drawLine; |
|
// private Transform BagUI; |
|
private void Awake() |
|
{ |
|
zhandoufu_yellow = transform.Find("zhandoufu_yellow"); |
|
BHF = transform.Find("BHF_Body"); |
|
FHF = transform.Find("FHF_Body"); |
|
GRF = transform.Find("GHF_Body"); |
|
//BagUI = GameObject.Find("Canvas").transform.Find("Bag"); |
|
// MessageDispatcher.AddListener("ReplayFrame", ReplayFrameSelectEquip); |
|
MessageDispatcher.AddListener("ReplayEvent", ReplayEventEquipChange); |
|
MessageDispatcher.AddListener("DelectEquip", DelectEquip); |
|
} |
|
|
|
|
|
|
|
private void ReplayEventEquipChange(IMessage obj) |
|
{ |
|
var eventData = (EventData)obj.Data; |
|
if (eventData.eventType == RecordEventType.SelectEquip) |
|
{ |
|
FiremanEquipRecordData data = JsonUtility.FromJson<FiremanEquipRecordData>(eventData.json); |
|
if (gameObject.name == data.objectName) |
|
{ |
|
EquipList = data.equips; |
|
ChangeCloth(); |
|
var work = GetComponent<FireManMessage>().workType; |
|
|
|
if (work == FireManSkills.LayWaterHose || work == FireManSkills.SprayFoam || |
|
work == FireManSkills.SprayWater || work == FireManSkills.Decontamination) |
|
{ |
|
for (int i = 0; i < data.equips.Count; i++) |
|
{ |
|
if (data.equips[i].Name == "消防高压水带") |
|
{ |
|
drawLine.BeginLineNum += data.equips[i].Number; |
|
if (!GetComponent<NavMeshAgent>().enabled) |
|
{ |
|
GetComponent<NavMeshAgent>().enabled = true; |
|
GetComponent<AgentController>().enabled = true; |
|
} |
|
if (GetComponent<XiaoFangYuanDrawLine>()) |
|
{ |
|
// if (GetComponent<XiaoFangYuanDrawLine>() == null) |
|
GetComponent<XiaoFangYuanDrawLine>().setLine(); |
|
} |
|
} |
|
} |
|
|
|
} |
|
else if (work == FireManSkills.LayLifeSavingFlarePath) |
|
{ |
|
for (int i = 0; i < data.equips.Count; i++) |
|
{ |
|
if (data.equips[i].Name == "救生照明线") |
|
{ |
|
drawLine.BeginLiftLineNum += data.equips[i].Number; |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
|
|
private void OnEnable() |
|
{ |
|
MessageDispatcher.AddListener("EquipSureSubmit", AddEquipFromEquip); |
|
} |
|
private void OnDisable() |
|
{ |
|
MessageDispatcher.RemoveListener("EquipSureSubmit", AddEquipFromEquip); |
|
} |
|
private void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("EquipSureSubmit", AddEquipFromEquip); |
|
//MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameSelectEquip); |
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventEquipChange); |
|
MessageDispatcher.RemoveListener("DelectEquip", DelectEquip); |
|
|
|
} |
|
private void Start() |
|
{ |
|
drawLine = GetComponent<XiaoFangYuanDrawLine>(); |
|
} |
|
private void DelectEquip(IMessage obj) |
|
{ |
|
if (gameObject == SelectedObjs.selectedCharacters[0]) |
|
{ |
|
List<string> list = (List<string>)obj.Data; |
|
for (int i = 0; i < list.Count; i++) |
|
{ |
|
delectEquip(list[i], false); |
|
} |
|
bagChange(false); |
|
//ChangeCloth(); |
|
} |
|
|
|
} |
|
|
|
private void AddEquipFromEquip(IMessage obj) |
|
{ |
|
FiremanEquipRecordData data = (FiremanEquipRecordData)obj.Data; |
|
if (gameObject.name == data.objectName) |
|
{ |
|
EquipAdd(data.equips); |
|
// ChangeCloth(); |
|
|
|
//GetComponent<FireManMessage>().BagChange(true); |
|
//在铺设状态下选择管线/照明线 |
|
var work = GetComponent<FireManMessage>().workType; |
|
|
|
if (work == FireManSkills.LayWaterHose || work == FireManSkills.SprayFoam || |
|
work == FireManSkills.SprayWater || work == FireManSkills.Decontamination) |
|
{ |
|
for (int i = 0; i < data.equips.Count; i++) |
|
{ |
|
if (data.equips[i].Name == "消防高压水带") |
|
{ |
|
drawLine.BeginLineNum += data.equips[i].Number; |
|
if (!GetComponent<NavMeshAgent>().enabled) |
|
{ |
|
GetComponent<NavMeshAgent>().enabled = true; |
|
GetComponent<AgentController>().enabled = true; |
|
} |
|
if (GetComponent<XiaoFangYuanDrawLine>()) |
|
{ |
|
// if (GetComponent<XiaoFangYuanDrawLine>() == null) |
|
GetComponent<XiaoFangYuanDrawLine>().setLine(); |
|
} |
|
} |
|
} |
|
|
|
} |
|
else if (work == FireManSkills.LayLifeSavingFlarePath) |
|
{ |
|
for (int i = 0; i < data.equips.Count; i++) |
|
{ |
|
if (data.equips[i].Name == "救生照明线") |
|
{ |
|
drawLine.BeginLiftLineNum += data.equips[i].Number; |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 消耗装备 |
|
/// </summary> |
|
/// <param name="equipname">装备名称</param> |
|
/// <param name="usenum">消耗数量,默认为1</param> |
|
private void EquipExped(string equipname, int usenum = 1) |
|
{ |
|
Equip eq = null; |
|
for (int i = 0; i < EquipList.Count; i++) |
|
{ |
|
if (EquipList[i].Name == equipname) |
|
{ |
|
eq = EquipList[i]; |
|
break; |
|
} |
|
} |
|
if (eq == null) |
|
{ |
|
ResourceLoadWindow.Instance.LoadTextHintWindow("背包中没有该装备", 0.5f); |
|
return; |
|
} |
|
if (eq.IsSelectMore) |
|
{ |
|
if (eq.Number < usenum) |
|
{ |
|
ResourceLoadWindow.Instance.LoadTextHintWindow("背包没有足够的装备", 0.5f); |
|
return; |
|
} |
|
eq.Number -= usenum; |
|
if (eq.Number <= 0) |
|
{ |
|
EquipList.Remove(eq); |
|
} |
|
} |
|
else |
|
{ |
|
eq.Number = 0; |
|
} |
|
bagChange(false); |
|
} |
|
public void SetEquipNum(string equipname,int num) |
|
{ |
|
Equip eq = GetEquipFromBag(equipname); |
|
if (eq!=null) |
|
{ |
|
if (eq.IsSelectMore) |
|
{ |
|
eq.Number = num; |
|
} |
|
} |
|
bagChange(false); |
|
} |
|
/// <summary> |
|
/// 删除装备 |
|
/// </summary> |
|
/// <param name="equipname"></param> |
|
/// <param name="send"></param> |
|
private void delectEquip(string equipname, bool send = true) |
|
{ |
|
for (int i = 0; i < EquipList.Count; i++) |
|
{ |
|
if (EquipList[i].Name == equipname) |
|
{ |
|
//在铺设过程中更改管线,修改铺设的初始管线数量 |
|
if (equipname == "消防高压水带") |
|
{ |
|
//在铺设状态下选择管线/照明线 |
|
var work = GetComponent<FireManMessage>().workType; |
|
|
|
if (work == FireManSkills.LayWaterHose || work == FireManSkills.SprayFoam || |
|
work == FireManSkills.SprayWater || work == FireManSkills.Decontamination) |
|
{ |
|
drawLine.BeginLineNum -= EquipList[i].Number; |
|
} |
|
} |
|
else if (equipname=="救生照明线") |
|
{ |
|
var work = GetComponent<FireManMessage>().workType; |
|
|
|
if (work == FireManSkills.LayLifeSavingFlarePath) |
|
{ |
|
drawLine.BeginLiftLineNum -= EquipList[i].Number; |
|
} |
|
} |
|
EquipList.Remove(EquipList[i]); |
|
} |
|
} |
|
if (send) |
|
{ |
|
bagChange(false); |
|
} |
|
} |
|
/// <summary> |
|
/// 批量添加装备 |
|
/// </summary> |
|
/// <param name="equipname"></param> |
|
/// <param name="addnum"></param> |
|
public void EquipAdd(List<Equip> qlist) |
|
{ |
|
for (int i = 0; i < qlist.Count; i++) |
|
{ |
|
EquipAdd(qlist[i].Name, qlist[i].Number, false); |
|
} |
|
bagChange(true); |
|
} |
|
/// <summary> |
|
/// 添加一种装备,默认发送UI更改信息 |
|
/// </summary> |
|
/// <param name="Equipname"></param> |
|
/// <param name="num"></param> |
|
/// <param name="send"></param> |
|
public void EquipAdd(string Equipname, int num = 1, bool send = true) |
|
{ |
|
Equip eq = GetEquipFromBag(Equipname); |
|
if (eq == null) |
|
{ |
|
eq = EquipSelect.GetInstance.GetInitEquipByName(Equipname); |
|
if (eq.IsSelectMore) |
|
{ |
|
eq.Number = num; |
|
} |
|
EquipList.Add(eq); |
|
} |
|
else |
|
{ |
|
//可多选装备,背包已有 |
|
if (eq.IsSelectMore) |
|
{ |
|
eq.Number += num; |
|
} |
|
} |
|
if (send) |
|
{ |
|
bagChange(true); |
|
} |
|
|
|
} |
|
/// <summary> |
|
/// 从背包获取装备,没有返回null |
|
/// </summary> |
|
/// <param name="name"></param> |
|
/// <returns></returns> |
|
public Equip GetEquipFromBag(string name) |
|
{ |
|
Equip eq = null; |
|
|
|
for (int i = 0; i < EquipList.Count; i++) |
|
{ |
|
if (EquipList[i].Name == name) |
|
{ |
|
eq = EquipList[i]; |
|
break; |
|
} |
|
} |
|
return eq; |
|
} |
|
|
|
/// <summary> |
|
/// 背包装备更改 |
|
/// </summary> |
|
/// <param name="add">是否是添加</param> |
|
private void bagChange(bool add) |
|
{ |
|
if (BagPanel.GetInstance.gameObject.activeInHierarchy) |
|
{ |
|
MessageDispatcher.SendMessage("BagChaneg", gameObject); |
|
} |
|
if (FireManSkillsPanel.GetInstance.gameObject.activeInHierarchy) |
|
{ |
|
if (SelectedObjs.selectedCharacters[0] == gameObject) |
|
{ |
|
FireManSkillsPanel.GetInstance.setUI(this); |
|
} |
|
} |
|
GetComponent<FireManMessage>().SetEnableSkill(add); |
|
FiremanEquipRecordData data = new FiremanEquipRecordData |
|
{ |
|
equips = EquipList, |
|
objectName = gameObject.name |
|
}; |
|
AddRecordEquipChange(data); |
|
ChangeCloth(); |
|
} |
|
/// <summary> |
|
/// 换装 |
|
/// </summary> |
|
public void ChangeCloth() |
|
{ |
|
Cloth cl = CheckClosthInBag(); |
|
ChanageCloth(cl); |
|
|
|
} |
|
private void ChanageCloth(Cloth cloth) |
|
{ |
|
switch (cloth) |
|
{ |
|
case Cloth.战斗服黄: |
|
zhandoufu_yellow.gameObject.SetActive(true); |
|
BHF.gameObject.SetActive(false); |
|
FHF.gameObject.SetActive(false); |
|
GRF.gameObject.SetActive(false); |
|
break; |
|
case Cloth.避火服: |
|
zhandoufu_yellow.gameObject.SetActive(false); |
|
BHF.gameObject.SetActive(true); |
|
FHF.gameObject.SetActive(false); |
|
GRF.gameObject.SetActive(false); |
|
break; |
|
case Cloth.防化服: |
|
zhandoufu_yellow.gameObject.SetActive(false); |
|
BHF.gameObject.SetActive(false); |
|
FHF.gameObject.SetActive(true); |
|
GRF.gameObject.SetActive(false); |
|
break; |
|
case Cloth.隔热服: |
|
zhandoufu_yellow.gameObject.SetActive(false); |
|
BHF.gameObject.SetActive(false); |
|
FHF.gameObject.SetActive(false); |
|
GRF.gameObject.SetActive(true); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
/// <summary> |
|
/// 检查服装 |
|
/// </summary> |
|
/// <returns></returns> |
|
private Cloth CheckClosthInBag() |
|
{ |
|
Cloth c = Cloth.战斗服黄; |
|
for (int i = 0; i < EquipList.Count; i++) |
|
{ |
|
if (EquipList[i].Name == "隔热防护服") |
|
{ |
|
c = Cloth.隔热服; |
|
} |
|
else if (EquipList[i].Name == "消防避火服") |
|
{ |
|
c = Cloth.避火服; |
|
} |
|
else if (EquipList[i].Name == "消防防化服") |
|
{ |
|
c = Cloth.防化服; |
|
} |
|
} |
|
return c; |
|
} |
|
/// <summary> |
|
/// 添加事件记录 |
|
/// </summary> |
|
/// <param name="args"></param> |
|
public void AddRecordEquipChange(FiremanEquipRecordData args) |
|
{ |
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) |
|
{ |
|
var eventData = new EventData(); |
|
eventData.time = RecordManager.Instance.RecordTimer; |
|
eventData.cloneObjType = CloneObjType.None; |
|
eventData.eventType = RecordEventType.SelectEquip; |
|
string json = JsonUtility.ToJson(args); |
|
eventData.json = json; |
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
/// <summary> |
|
/// 获取某装备的数量,返回-2为没有装备.-1为不课多选装备 |
|
/// </summary> |
|
/// <returns></returns> |
|
public int GetEquipNum(string equipname) |
|
{ |
|
int num = 0; |
|
Equip sd = GetEquipFromBag(equipname); |
|
if (sd == null) |
|
{ |
|
num = -2; |
|
} |
|
else |
|
{ |
|
if (sd.IsSelectMore) |
|
{ |
|
num = sd.Number; |
|
} |
|
else |
|
{ |
|
num = -1; |
|
} |
|
} |
|
return num; |
|
} |
|
}
|
|
|