using System.Collections; using System.Collections.Generic; using UnityEngine; using AX.MessageSystem; using System; using AX.NetworkSystem; public class ObjDelete : MonoBehaviour { // Use this for initialization void Start() { } // Update is called once per frame void Update() { } void OnEnable() { MessageDispatcher.AddListener("DELETE_COMMAND", ObjDeleted); //MessageDispatcher.AddListener("DELETE_ALL_COMMAND", DeletedAllObj); } void OnDisable() { MessageDispatcher.RemoveListener("DELETE_COMMAND", ObjDeleted); //MessageDispatcher.RemoveListener("DELETE_ALL_COMMAND", DeletedAllObj); } void OnDestroy() { MessageDispatcher.RemoveListener("DELETE_COMMAND", ObjDeleted); //MessageDispatcher.RemoveListener("DELETE_ALL_COMMAND", DeletedAllObj); } private void ObjDeleted(IMessage obj) { if (SelectedObjs.selectedObj == gameObject) { if (GetComponent().gameObjType == CloneObjType.fireNormal) { if (gameObject.GetComponent()) { if (gameObject.GetComponent().fireAttribute.spreadWay != SpreadWay.None) { LoadPromptWin.Instance.LoadTextPromptWindow("开始蔓延的火不能删除!", 1f); return; } } //if (GameSettings.othersSettings.isStartDrill) //{ // LoadPromptWin.Instance.LoadTextPromptWindow("开始演练后不能删除!", 1f); // return; //} //如果演练开始手动删除灾情,通知修改火堆信息 if (GameSettings.othersSettings.IsStartDrill) { if (gameObject.GetComponent()) { MessageDispatcher.SendMessage("FireNormalNumChasnge", false); } } DeleteObj(); } else if (GetComponent().gameObjType == CloneObjType.OrdinaryHose) { GameObject start = gameObject.GetComponent().StartHitGameObj; GameObject end = gameObject.GetComponent().EndHitGameObj; if(end!=null) {//可能先把连接物体删除然后导致结尾物体为空 if (CheckWorkType(end, start) == false) { LoadPromptWin.Instance.LoadTextPromptWindow("不能删除该管线", 1f); return; } } //MessageDispatcher.SendMessage("DelectWaterHose"); var arg = new HoseConnectOrDelectData(); arg.StartId = start.GetComponent().gameObjID; if(end!=null) { arg.EndId = end.GetComponent().gameObjID; } arg.HoseId = gameObject.GetComponent().gameObjID; arg.Isconnect = false; MessageDispatcher.SendMessage("HOSE_CONNECT_OR_DELECT", arg); DeleteObj(); } else if (GetComponent().gameObjType == CloneObjType.WaterCannon) { if (gameObject.GetComponent().Skill != WaterCannonSkill.None) { LoadPromptWin.Instance.LoadTextPromptWindow("不能删除该水炮", 1f); return; } //删除可回收工具,当前UI隐藏以及工具回收 MessageDispatcher.SendMessage("DelectExpendTool", gameObject); DeleteObj(); } else if (GetComponent().gameObjType == CloneObjType.SnowCannon) { if (gameObject.GetComponent().Skill != SnowCannonSkill.None) { LoadPromptWin.Instance.LoadTextPromptWindow("不能删除该暴风雪炮", 1f); return; } //删除可回收工具,当前UI隐藏以及工具回收 MessageDispatcher.SendMessage("DelectExpendTool", gameObject); DeleteObj(); } else if (GetComponent().gameObjType == CloneObjType.FirefightingRobot) { if (gameObject.GetComponent().WorkType == FireRobotSkill.出水 || gameObject.GetComponent().WorkType == FireRobotSkill.出泡沫 || gameObject.GetComponent().WorkType == FireRobotSkill.铺设水带) { LoadPromptWin.Instance.LoadTextPromptWindow("不能删除该灭火机器人", 1f); return; } if(gameObject.GetComponent().GetSelfConsumedLength()>0) { LoadPromptWin.Instance.LoadTextPromptWindow("请先收起管线", 1f); return; } //删除可回收工具,当前UI隐藏以及工具回收 MessageDispatcher.SendMessage("DelectExpendTool", gameObject); DeleteObj(); } else if (GetComponent().gameObjType == CloneObjType.WaterCurtainHose) { //删除可回收工具,当前UI隐藏以及工具回收 MessageDispatcher.SendMessage("DelectExpendTool", gameObject); //删除绑定的水源车上的水幕水带 WaterCarBindCurtainHose waterCarBindCurtainHose = new WaterCarBindCurtainHose(); waterCarBindCurtainHose.WaterSourceObjId = GetComponent().waterSourceGameObjId; waterCarBindCurtainHose.WaterCurtainHose = gameObject; waterCarBindCurtainHose.isConnect = false; MessageDispatcher.SendMessage("WATERCAR_DESTORY_CURTAINHOSE", waterCarBindCurtainHose); DeleteObj(); } else { DeleteObj(); } } //选中消防人员删除处理 if (SelectedObjs.selectedCharacters.Contains(gameObject)) { //var msg = GetComponent(); //if (msg && msg.group != null) //{ // ResourceLoadWindow.Instance.LoadTextHintWindow("已经编组,不能删除", 1f); //} //else //{ // if (msg) //如果是消防人员,就删除铺设的管线 // { // gameObject.GetComponent().Pack(); // gameObject.GetComponent().DeleteParent(); // gameObject.GetComponent().Pack(); // gameObject.GetComponent().DeleteParent(); // } // DeleteObj(); //} } } //接收到删除所有物体命令时的处理脚本 private void DeletedAllObj(IMessage msg) { DeleteObj(); } private void DeleteObj() { //删除同步命令 if (GameSettings.othersSettings.mode != Mode.DisasterManagement) { BaseNetworkSyncDate arg = new BaseNetworkSyncDate(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = gameObject.GetComponent().gameObjID; NetworkManager.Default.SendAsync("OBJ_DELECT_SYNC", arg); } EntitiesManager.Instance.DeleteObj(gameObject); //MessageDispatcher.SendMessage("DELE_HEAD_NAME", (object)gameObject.name);//删除对应的UI名称显示 } private bool CheckWorkType(GameObject endobj, GameObject startobj) { bool can = true; //如果是消防员,并且在出水 if (endobj.GetComponent() && endobj.GetComponent().workType == FireManSkills.SprayWater) { can = false; } else if (endobj.GetComponent() && endobj.GetComponent().workType == FireManSkills.LayWaterHose) { can = false; } ///车在喷水 else if (endobj.GetComponent()) { if ((endobj.GetComponent().NowSkill == TruckSkills.喷水 || endobj.GetComponent().NowSkill == TruckSkills.喷泡沫) || (endobj.GetComponent() && endobj.GetComponent().TotalFlow > 0/*&&startobj.GetComponent().HasWaterSelfAndLine*/)) { can = false; } } //移动水泡喷水 else if (endobj.GetComponent() && ( endobj.GetComponent().Flow > 0 )) { can = false; } else if (endobj.GetComponent() && ( endobj.GetComponent().Flow > 0 )) { can = false; } else if (endobj.GetComponent()) { //Transform P_FireRobotFollowHose = GameObject.Find("P_AllParent/P_Tools/P_FireRobotFollowHose").transform; //if (P_FireRobotFollowHose.Find(endobj.name).childCount > 0) //{ // can = false; //} if (endobj.GetComponent().GetSelfConsumedLength()>0.2f) { can = false; } if (endobj.GetComponent().Flow > 0) { can = false; } } return can; } }