海淀天下城电子沙盘单机版
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.

378 lines
12 KiB

4 years ago
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FireManSkillsPanel : ResourceLoadPanel<FireManSkillsPanel>
{
public GameObject chooseObj;
private Transform panel;
private Toggle layerwaterHose;
private Toggle layliftSavingFlarePath;
private Toggle forcibleEntry;
private Toggle dischargeSmoke;
private Toggle lighting;
private Toggle sprayWater;
private Toggle sprayFoam;
private Toggle decontamination;
public bool IsChange = false;//该变量用来判断是不是换选.是的话,换选的时候不执行子物体toggle中的ison事件
void Awake()
{
MessageDispatcher.AddListener("CANCEL_SELECTED_COMMAND", EscCancelSelected);
MessageDispatcher.AddListener("SelectChange", SelectChange);
MessageDispatcher.AddListener("FiremanSkillsPanelDraw", setData);
MessageDispatcher.AddListener("DeleteObj", DeleteObj);
//MessageDispatcher.AddListener("LayWaterHoseToggle", LayWaterHose);
//MessageDispatcher.AddListener("LayLifeSavingFlarePathToggle", LayLifeSavingFlarePath);
//MessageDispatcher.AddListener("SprayWaterToggle", SprayWater);
//MessageDispatcher.AddListener("SprayFoamToggle", SprayFoam);
//MessageDispatcher.AddListener("DecontaminationToggle", Decontamination);
//MessageDispatcher.AddListener("ForcibleEntryToggle", ForcibleEntry);
//MessageDispatcher.AddListener("DischargeSmokeToggle", DischargeSmoke);
//MessageDispatcher.AddListener("LightingToggle", Lightingfunc);
//MessageDispatcher.AddListener("SaveToggle", Save);
//MessageDispatcher.AddListener("AskPeopleToggle", AskPeople);
//MessageDispatcher.AddListener("ClearDangerousToggle", ClearDangerous);
//MessageDispatcher.AddListener("ClearSundriesToggle", ClearSundries);
//MessageDispatcher.AddListener("PackUpLine", PackUpLine);
//MessageDispatcher.AddListener("TagSearchRoom",TagSearchRoom);
//MessageDispatcher.AddListener("EquipSelect", EquipSelectfunc);
//equipSelect = GameObject.Find("Canvas").transform.Find("EquipSelect");
//bag = GameObject.Find("Canvas").transform.Find("Bag");
//equipSelect.GetComponent<EquipSelect>().Init();
panel = transform.Find("Scroll View/Viewport/Content/Panel");
forcibleEntry = panel.Find("ForcibleEntry").GetComponent<Toggle>();
dischargeSmoke = panel.Find("DischargeSmoke").GetComponent<Toggle>();
lighting = panel.Find("Lighting").GetComponent<Toggle>();
sprayWater = panel.Find("SprayWater").GetComponent<Toggle>();
sprayFoam = panel.Find("SprayFoam").GetComponent<Toggle>();
decontamination = panel.Find("Decontamination").GetComponent<Toggle>();
layerwaterHose = panel.Find("LayWaterHose").GetComponent<Toggle>();
layliftSavingFlarePath = panel.Find("LayLifeSavingFlarePath").GetComponent<Toggle>();
}
public void CloseSprayToggle()
{
//if (!chooseObj.GetComponentInChildren<ParticleControlOfType>())
//{
// if (chooseObj.GetComponent<FireManMessage>().workType == FireManSkills.SprayWater)
// {
// chooseObj.GetComponent<FireManMessage>().workType = FireManSkills.None;
// }
//}
sprayWater.isOn = false;
}
public bool GetSprayOn()
{
return sprayWater.isOn;
}
public void CloselayhoseToggle()
{
layerwaterHose.isOn = false;
}
public void CloseLayLiftToggle()
{
layliftSavingFlarePath.isOn = false;
}
private void OnEnable()
{
IsChange = true;
if (SelectedObjs.selectedCharacters.Count < 0)
{
gameObject.SetActive(false);
}
}
void OnDisable()
{
chooseObj = null;
IsChange = false;
if (BagPanel.GetInstance.gameObject.activeInHierarchy)
{
BagPanel.GetInstance.gameObject.SetActive(false);
}
}
private void EquipSelectfunc(IMessage obj)
{
EquipSelect.GetInstance.gameObject.SetActive(true);
BagPanel.GetInstance.gameObject.SetActive(true);
//bag.gameObject.SetActive(true);
//equipSelect.gameObject.SetActive(true);
}
private void TagSearchRoom(IMessage obj)
{
Debug.Log("搜查房间");
}
private void PackUpLine(IMessage obj)
{
Debug.Log("收起水带");
}
private void ClearSundries(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("清理杂物堆" + value);
}
private void ClearDangerous(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("清理危险品" + value);
}
private void AskPeople(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("询问知情人" + value);
}
private void Save(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("疏散救生" + value);
}
private void Lightingfunc(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("照明" + value);
}
private void DischargeSmoke(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("排烟" + value);
}
private void ForcibleEntry(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("破拆" + value);
}
private void SprayFoam(IMessage obj)
{
bool value = (bool)obj.Data;
if (value)
MessageDispatcher.SendMessage(chooseObj.GetComponent<CloneGameObjInfo>().GameObjID, "SprayFoam", value);
// else
// chooseObj.GetComponent<FiremanControlSprayHead>().SetAnimAndHose(value);
}
private void Decontamination(IMessage obj)
{
bool value = (bool)obj.Data;
if (value)
MessageDispatcher.SendMessage(chooseObj.GetComponent<CloneGameObjInfo>().GameObjID, "Decontamination", value);
//else
//chooseObj.GetComponent<FiremanControlSprayHead>().SetAnimAndHose(value);
}
private void SprayWater(IMessage obj)
{
bool value = (bool)obj.Data;
if (value)
MessageDispatcher.SendMessage(chooseObj.GetComponent<CloneGameObjInfo>().GameObjID, "SprayWater", value);
// else
//chooseObj.GetComponent<FiremanControlSprayHead>().SetAnimAndHose(value);
}
private void LayLifeSavingFlarePath(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("铺设救生照明线" + value);
}
private void LayWaterHose(IMessage obj)
{
bool value = (bool)obj.Data;
Debug.Log("铺设管线" + value);
}
private void DeleteObj(IMessage message)
{
if (!gameObject.activeSelf)
return;
var obj = message.Data as GameObject;
if (obj == chooseObj)
gameObject.SetActive(false);
}
/// <summary>
/// 单选换选
/// </summary>
/// <param name="obj"></param>
private void SelectChange(IMessage obj)
{
GameObject select = (GameObject)obj.Data;
if (select.GetComponent<FireManMessage>())
{
if (select != chooseObj)
{
IsChange = true;
chooseObj = select;
FireManSkillsPanel.GetInstance.gameObject.SetActive(true);
Bag bag = select.GetComponent<Bag>();
setUI(bag);
SetHasWater(chooseObj);
SetToggle();
IsChange = false;
}
else
{
if (!FireManSkillsPanel.GetInstance.gameObject.activeInHierarchy)
{
FireManSkillsPanel.GetInstance.gameObject.SetActive(true);
}
}
}
else
{
FireManSkillsPanel.GetInstance.gameObject.SetActive(false);
}
}
private void EscCancelSelected(IMessage obj)
{
gameObject.SetActive(false);
}
void Init()
{
//TruckArmPanel = transform.Find("TruckArmPanel").gameObject;
//cloneObjType = SelectedObjs.selectedObj.GetComponent<BaseGameObjInfo>().gameObjType;
}
private void setData(IMessage obj)
{
var newChoose = (GameObject)obj.Data;
gameObject.SetActive(true);
chooseObj = newChoose;
Bag bag = newChoose.GetComponent<Bag>();
setUI(bag);
SetHasWater(chooseObj);
SetToggle();
//IsChange = false;
//MessageDispatcher.SendMessage("SetFireManSkills", chooseObj);
}
/// <summary>
/// 控制消防员技能面板显示,特殊处理出水的消防员显示
/// </summary>
void SetToggle()
{
if (this == null)
{
return;
}
FireManSkills chooseskill = chooseObj.GetComponent<FireManMessage>().workType;
FireManSkillTogge[] all = GetComponentsInChildren<FireManSkillTogge>();
for (int i = 0; i < all.Length; i++)
{
all[i].GetComponent<Toggle>().isOn = false;
}
for (int i = 0; i < all.Length; i++)
{
if (FireManSkills.SprayWater == chooseskill)
{
if (all[i].fireManSkills == FireManSkills.SprayWater)
{
all[i].flag = true;
all[i].GetComponent<Toggle>().isOn = true;
}
}
else
{
if (all[i].fireManSkills == chooseskill)
{
all[i].GetComponent<Toggle>().isOn = true;
}
}
}
}
void SetHasWater(GameObject gameObject)
{
if (this==null)
{
return;
}
FireManMessage mess = gameObject.GetComponent<FireManMessage>();
if ((mess.EnabledSkills & FireManSkills.SprayWater) != 0)
{
sprayWater.interactable = true;
}
else
{
sprayWater.isOn = false;
sprayWater.interactable = false;
}
if ((mess.EnabledSkills & FireManSkills.Decontamination) != 0)
{
decontamination.interactable = true;
}
else
{
decontamination.isOn = false;
decontamination.interactable = false;
}
if ((mess.EnabledSkills & FireManSkills.SprayFoam) != 0)
{
sprayFoam.interactable = true;
}
else
{
sprayFoam.isOn = false;
sprayFoam.interactable = false;
}
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("CANCEL_SELECTED_COMMAND", EscCancelSelected);
MessageDispatcher.RemoveListener("SelectChange", EscCancelSelected);
MessageDispatcher.RemoveListener("FiremanSkillsPanelDraw", setData);
MessageDispatcher.RemoveListener("DeleteObj", DeleteObj);
MessageDispatcher.RemoveListener("LayWaterHose", LayWaterHose);
MessageDispatcher.RemoveListener("LayLifeSavingFlarePath", LayLifeSavingFlarePath);
MessageDispatcher.RemoveListener("SprayWater", SprayWater);
MessageDispatcher.RemoveListener("SprayFoam", SprayFoam);
MessageDispatcher.RemoveListener("DecontaminationToggle", Decontamination);
MessageDispatcher.RemoveListener("ForcibleEntry", ForcibleEntry);
MessageDispatcher.RemoveListener("DischargeSmoke", DischargeSmoke);
MessageDispatcher.RemoveListener("Lighting", Lightingfunc);
MessageDispatcher.RemoveListener("Save", Save);
//MessageDispatcher.RemoveListener("AskPeople", AskPeople);
//MessageDispatcher.RemoveListener("ClearDangerous", ClearDangerous);
//MessageDispatcher.RemoveListener("ClearSundries", ClearSundries);
MessageDispatcher.RemoveListener("PackUpLine", PackUpLine);
MessageDispatcher.RemoveListener("TagSearchRoom", TagSearchRoom);
MessageDispatcher.RemoveListener("EquipSelect", EquipSelectfunc);
}
public void setUI(Bag bag)
{
CheckBag(bag, "无齿锯", forcibleEntry);
CheckBag(bag, "手提式防爆强光照明灯", lighting);
CheckBag(bag, "移动式排烟机", dischargeSmoke);
}
void CheckBag(Bag bag, string equipName, Toggle toggle)
{
Equip EQ = bag.GetEquipFromBag(equipName);
if (EQ != null)
{
toggle.interactable = true;
}
else
{
toggle.interactable = false;
}
}
}