using System; using System.Collections; using System.Collections.Generic; using AX.MessageSystem; using UnityEngine; public class HookPipeAttribute : ToolAttribute { public GameObject water; public WaterReceiver receiver; protected override void Awake() { water = transform.Find("WaterStraight").gameObject; water.SetActive(false); receiver = GetComponent(); Tasklist = new string[] { "待命", "灭火" }; gameObjType = CloneObjType.FoamHookPipe; 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); } } } 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; } /// /// 执行任务 /// /// protected override void Execute(string TaskName) { task = TaskName; if (TaskName.Contains("灭火")) { 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 void WaterSourceChanged(IMessage obj) { var data = (WaterConnectionData)obj.Data; var msg = GetComponent(); if (msg.gameObjID == data.receiverID && data.connected == false && task == "灭火") { task = "待命"; Execute(task); } } }