上海杨浦大连路地铁站单机版电子沙盘
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.
 
 
 
 

293 lines
12 KiB

using AX.InputSystem;
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class TruckMessages : MonoBehaviour
{
public CarAttributeBase CarAttribute;
public TruckSkillsEnum CurrentSkill;
public bool IsR;
public TruckSkillsEnum TruckSkills { get; private set; }
public TruckSkillsEnum EnabledSkills
{
get
{
return enabledSkills;
}
set
{
// if (!IsR)//防止加载数据被初始化数据覆盖
enabledSkills = value;
}
}
public TruckSkillsEnum enabledSkills;
void Awake()
{
Initialize();
MessageDispatcher.AddListener("WaterSourceChanged", WaterSourceChanged);
MessageDispatcher.AddListener("WaterSeparaterChange",WaterseparadChange);
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("WaterSourceChanged", WaterSourceChanged);
MessageDispatcher.RemoveListener("WaterSeparaterChange", WaterseparadChange);
}
private void WaterseparadChange(IMessage obj)
{
if (GetComponent<WaterReceiver>())
{
var Id = GetComponent<CloneGameObjInfo>().gameObjID;
Waterseparadata data = (Waterseparadata)obj.Data;
if (Id==data.receiveId)
{
if (data.watertype == WaterType.water || data.watertype == WaterType.both)//普通水
{
if (data.IsContent)
{
EnabledSkills |= TruckSkillsEnum.SprayWater;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayWater;
if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent);
CurrentSkill &= ~TruckSkillsEnum.SprayWater;
}
}
}
if (data.watertype == WaterType.foam || data.watertype == WaterType.both)//泡沫
{
if (data.IsContent)
{
EnabledSkills |= TruckSkillsEnum.SprayFoam;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayFoam;
if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent);
CurrentSkill &= ~TruckSkillsEnum.SprayFoam;
}
}
}
if (data.watertype == WaterType.none)//不供水
{
if (data.IsContent)
{
//EnabledSkills |= TruckSkillsEnum.SprayFoam;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayFoam;
if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent);
CurrentSkill &= ~TruckSkillsEnum.SprayFoam;
}
EnabledSkills &= ~TruckSkillsEnum.SprayWater;
if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent);
CurrentSkill &= ~TruckSkillsEnum.SprayWater;
}
}
}
if (TruckSkillSPanel.GetInstance.gameObject.activeSelf && SelectedObjs.selectedObj == gameObject)
MessageDispatcher.SendMessage("TruckSkillsPanelDraw", gameObject);
}
}
}
private void WaterSourceChanged(IMessage obj)
{
var data = (WaterConnectionData)obj.Data;
// var gameObjId = (long)obj.Sender;
var Id = GetComponent<BaseGameObjInfo>().GameObjID;
if (data.supplierID == Id)
{
if (data.connected)
GetComponent<AgentController>().pathFindEnable = false;
else
{
if (GetComponent<WaterSupplier>().waterLineInfos.Contains(data.waterLineID))
{
GetComponent<WaterSupplier>().waterLineInfos.Remove(data.waterLineID);
}
if (GetComponent<WaterSupplier>().waterLineInfos.Count <= 0)
GetComponent<AgentController>().pathFindEnable = true;
}
}
if (data.receiverID != Id)
return;
GetComponent<AgentController>().pathFindEnable = !data.connected;
if (data.type == WaterType.water|| data.type == WaterType.both)//普通水
{
if (data.connected)
{
EnabledSkills |= TruckSkillsEnum.SprayWater;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayWater;
if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected);
CurrentSkill &= ~TruckSkillsEnum.SprayWater;
}
}
}
if (data.type == WaterType.foam || data.type == WaterType.both)//泡沫
{
if (data.connected)
{
EnabledSkills |= TruckSkillsEnum.SprayFoam;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayFoam;
if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected);
CurrentSkill &= ~TruckSkillsEnum.SprayFoam;
}
}
}
if (data.type == WaterType.none)//不供水
{
if (data.connected)
{
//EnabledSkills |= TruckSkillsEnum.SprayFoam;
}
else
{
EnabledSkills &= ~TruckSkillsEnum.SprayFoam;
if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected);
CurrentSkill &= ~TruckSkillsEnum.SprayFoam;
}
EnabledSkills &= ~TruckSkillsEnum.SprayWater;
if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0)
{
MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected);
CurrentSkill &= ~TruckSkillsEnum.SprayWater;
}
}
}
if (TruckSkillSPanel.GetInstance.gameObject.activeSelf && SelectedObjs.selectedObj == gameObject)
MessageDispatcher.SendMessage("TruckSkillsPanelDraw", gameObject);
}
void Initialize()
{
CarAttribute = CarAttributeRecord.GetCarAttributeByType(GetComponent<CloneGameObjInfo>().gameObjType);
foreach (int v in Enum.GetValues(typeof(TruckSkillsEnum)))
{
string strName = Enum.GetName(typeof(TruckSkillsEnum), v);
var truckskills = (TruckSkillsEnum)v;
switch (truckskills)
{
case TruckSkillsEnum.Debarkation:
if (GetComponent<FireManDebarkation>())
{
TruckSkills |= truckskills;
EnabledSkills |= truckskills;
}
//TruckSkills &= truckskills;
//EnabledSkills &= ~truckskills;
//Skills |= ~truckskills;
break;
case TruckSkillsEnum.SprayWater:
if (GetComponent<ControlSprayHead>())
TruckSkills |= truckskills;
if (GetComponent<WaterSupplier>())
if (GetComponent<WaterSupplier>().WaterReceiverType == WaterType.water || GetComponent<WaterSupplier>().WaterReceiverType == WaterType.both)
EnabledSkills |= truckskills;
break;
case TruckSkillsEnum.SprayFoam:
if (GetComponent<ControlSprayHead>())
TruckSkills |= truckskills;
if (GetComponent<WaterSupplier>())
{
if (GetComponent<WaterSupplier>().WaterReceiverType == WaterType.both || GetComponent<WaterSupplier>().WaterReceiverType == WaterType.foam)
{ EnabledSkills |= truckskills; }
else
{
TruckSkills &= ~truckskills;
}
}
break;
case TruckSkillsEnum.FixedSupport:
if (GetComponent<ControlTruckArm>())
{
TruckSkills |= truckskills;
EnabledSkills |= truckskills;
GetComponent<ControlTruckArm>().ArmLength = CarAttribute.Height;
GetComponent<ControlTruckArm>().SetHeight(CarAttribute.Height);
}
break;
case TruckSkillsEnum.AutomaticLiftArm:
//if (GetComponent<ControlTruckArm>())
// TruckSkills |= truckskills;
break;
case TruckSkillsEnum.PackUpTheLiftArm:
if (GetComponent<ControlTruckArm>())
TruckSkills |= truckskills;
break;
case TruckSkillsEnum.ForcibleEntry:
//if (GetComponent<ControlTruckArm>())
// TruckSkills |= truckskills;
break;
case TruckSkillsEnum.Illumination:
//if (GetComponent<ControlTruckArm>())
// TruckSkills |= truckskills;
break;
case TruckSkillsEnum.DischargeSmoke:
//if (GetComponent<ControlTruckArm>())
// TruckSkills |= truckskills;
break;
case TruckSkillsEnum.SelectTarget:
if (GetComponent<SelectTarget>())
{
//该车辆包含此技能
TruckSkills |= truckskills;
//该车辆可激活此技能按钮
//EnabledSkills |= truckskills; //暂不实现此功能
}
break;
case TruckSkillsEnum.AutoSwing:
if (GetComponent<AutoSwing>())
{
//该车辆包含此技能
TruckSkills |= truckskills;
//该车辆可激活此技能按钮
//EnabledSkills |= truckskills; //暂不实现此功能
}
break;
case TruckSkillsEnum.SprayPowder:
if (GetComponent<SprayPowder>())
{
//该车辆包含此技能
TruckSkills |= truckskills;
//该车辆可激活此技能按钮
//EnabledSkills |= truckskills; //暂不实现此功能
}
break;
default:
break;
}
}
IsR = false;
}
}