using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class BlizzardCannonAttribute : ToolAttribute { public GameObject water;//需要控制的物体 public WaterReceiver receiver; protected override void Awake() { water = transform.Find("paokou/tai/Hose/WaterStraight").gameObject; water.SetActive(false); receiver = GetComponent(); gameObjType = CloneObjType.BlizzardCannon; typeName = "暴风雪炮"; MessageDispatcher.AddListener("WaterSourceChanged", WaterSourceChanged); MessageDispatcher.AddListener("WaterSeparaterChange", WaterseparadChange); base.Awake(); } protected override void OnDestroy() { base.OnDestroy(); MessageDispatcher.RemoveListener("WaterSourceChanged", WaterSourceChanged); MessageDispatcher.RemoveListener("WaterSeparaterChange", WaterseparadChange); } private void WaterseparadChange(IMessage obj) { var data = (Waterseparadata)obj.Data; var msg = GetComponent(); if (msg.gameObjID == data.receiveId) { receiver.hasSupplier = data.IsContent; if (msg.gameObjID == data.receiveId && data.IsContent == false && task == "灭火") { task = "待命"; Execute(task); } } } /// /// 执行任务 /// /// protected override void Execute(string TaskName) { task = TaskName; if (TaskName.Contains("灭火")) { //if (receiver.hasSupplier == true) //{ // water.SetActive(true); //} //else //{ // ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接水源", 2); // task = "待命"; //} if (receiver.hasSupplier == true) { //WaterType type = GetSupplerWaterType(receiver); //if (type == WaterType.foam || type == WaterType.both) { water.SetActive(true); } //else //{ // ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接泡沫源", 2); //} } else { ResourceLoadWindow.Instance.LoadTextHintWindow("请先连接水源", 2); } } else { water.SetActive(false); } } private WaterType GetSupplerWaterType(WaterReceiver receiver) { WaterType type = WaterType.none; GameObject waterline = EntitiesManager.Instance.GetEntityByID(receiver.waterlinelist[0]); GameObject suppler = EntitiesManager.Instance.GetEntityByID(waterline.GetComponent().SupplierID); type = suppler.GetComponent().WaterReceiverType; return type; } private void WaterSourceChanged(IMessage obj) { var data = (WaterConnectionData)obj.Data; var msg = GetComponent(); if (msg.gameObjID == data.receiverID && data.connected == false && task == "灭火") { task = "待命"; Execute(task); } } }