using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.MessageSystem; using AX.TrackRecord; using System; using DevelopEngine; public class UPAndDownAttack : MonoBehaviour { public static UPAndDownAttack Instance; GameObject objTouMing;//透明 GameObject objZhuTi; List zhuTiList=new List();//主体 bool bShowArrow = true; /// /// 是否双击了着火层 /// public bool ChangFloorFlag { set; get; } private void Awake() { Instance = this; } public List cengList = new List(); Toggle tgl; private void Start() { if (!MySceneManager.GetActiveScene().name.Equals("11")) { transform.parent.gameObject.SetActive(false); return;//上下夹击功能只有11场景可用 } //tgl = GetComponent(); //tgl.onValueChanged.AddListener(b => { UpAndDownAttack(b); }); //objPArrowFather = GameObject.Find("AllParent/pUpAndDownArrow"); //objTouMing = GameObject.Find("SceneAll").transform.Find("toumingzhuti").gameObject; //objZhuTi = objTouMing.transform.parent.Find("ZhuTi").gameObject; MessageDispatcher.AddListener("ResetTheScene", ResetScene); MessageDispatcher.AddListener("RecordArrow", RecordArrow); init(); transform.parent.gameObject.SetActive(false); } //DateTime t1, t2; //private void Update() //{ // if (Input.GetMouseButtonDown(0)) // { // t2 = DateTime.Now; // if (t2-t1() == false) return; // int cengId = hitinfo.collider.gameObject.GetComponent().cengID; // if (cengList.Contains(cengId)) // { // if (ChangFloorFlag == false) // { // MessageDispatcher.SendMessage("MoveUpFloor", (object)cengId); // } // else // { // MessageDispatcher.SendMessage("MoveDownFloor", (object)cengId); // } // ChangFloorFlag = !ChangFloorFlag; // } // } // } // t1 = t2; // } //} void init() { tgl = GetComponent(); tgl.onValueChanged.AddListener(b => { UpAndDownAttack(b); }); objPArrowFather = GameObject.Find("AllParent/pUpAndDownArrow"); objTouMing = GameObject.Find("SceneAll").transform.Find("toumingzhuti").gameObject; objZhuTi = objTouMing.transform.parent.Find("ZhuTi").gameObject; ChangFloorFlag = true; } /// /// 上下夹攻的方法 /// public void UpAndDownAttack(bool b) { PrePareModeSet.instance.CloseAssitToggle();//关闭打开的菜单栏 GetComponent().ResetText(); GetFireCeng(); if (cengList.Count==0) { MessageDispatcher.SendMessage("Operatinghints", (object)"场景中无火源!"); return; } if (!objTouMing) { return; } if (objTouMing.activeInHierarchy) { bShowArrow = true; } else { bShowArrow = false; } if (!bShowArrow) {//没有显示箭头----就开始显示箭头,并将主体隐掉,将透明主体显示出来 ShowArrow(); ChangFloorFlag = false; } else { MessageDispatcher.SendMessage("MoveDownFloor"); ClearUpAndDownArrow(); MainBodyControl(false); ChangFloorFlag = true; cengList.Clear(); } if (RecordManager.Instance.IsRecording) { TrackRecordHelpClass.RecordTriggerEvent("UpAndDownAttack"); } } public void ShowArrow() { if (cengList.Count == 0) return; MessageDispatcher.SendMessage("SetArrow", cengList); MainBodyControl(true); } /// /// 清楚存火的层 /// /// private void OnDisable() { if (cengList!=null&&cengList.Count!=0) { cengList.Clear(); } } private void OnDestroy() { MessageDispatcher.RemoveListener("ResetTheScene", ResetScene); MessageDispatcher.RemoveListener("RecordArrow", RecordArrow); } /// /// 返回火焰所在的楼层 /// /// void GetFireCeng() { Transform fireParent = GameObject.Find("AllParent/pfire").transform; Transform shiNeiFireParent = GameObject.Find("AllParent/pShineihuo").transform; if (fireParent.childCount == 0&& shiNeiFireParent.childCount==0) return ; CengID[] cengArray = fireParent.GetComponentsInChildren(); foreach (CengID cengID in cengArray) { //0层是是外层,没有上下夹攻一说 if (cengID.cengID == 0) { continue; } if (!cengList.Contains(cengID.cengID)) { cengList.Add(cengID.cengID); } } foreach (CengID cengID in shiNeiFireParent.GetComponentsInChildren(true)) { //0层是是外层,没有上下夹攻一说 if (cengID.cengID == 0) { continue; } if (!cengList.Contains(cengID.cengID)) { cengList.Add(cengID.cengID); } } } Transform transUp = null; Transform transDown = null; Transform transNow = null; public void InsUpArrow(Transform transParent,Transform transFireNow) { if (CheckArrowName(transParent.name + "-shang")) return; transUp = transParent; transNow = transFireNow; GameObject objUpArrow = Instantiate(Resources.Load("Prefabs/ToolPrefab/UpArrow") as GameObject, transParent.parent);//朝上箭头 objUpArrow.transform.position = transParent.position; objUpArrow.name = transParent.name+"-shang"; objUpArrow.transform.parent = objPArrowFather.transform; } GameObject objPArrowFather = null; public void InsDowanArrow(Transform transParent, Transform transFireNow) { if (CheckArrowName(transParent.name+"-xia")) return; transDown = transParent; transNow = transFireNow; GameObject objDownArrow = Instantiate(Resources.Load("Prefabs/ToolPrefab/DownArrow") as GameObject, transParent.parent);//朝下箭头 objDownArrow.transform.position = transParent.position; objDownArrow.name = transParent.name+"-xia"; objDownArrow.transform.parent = objPArrowFather.transform; } /// /// /// /// /// private bool CheckArrowName(string arrowName) { if (objPArrowFather == null) { init(); } Transform[] transArray = objPArrowFather.GetComponentsInChildren(); for (int i = 0; i < transArray.Length; i++) { if (transArray[i].name.Equals(arrowName)) { return true;//说明已经有箭头存在了,就不再实例化 } } return false; } /// /// 获取当前层的火的链表 /// /// 所在层 /// public List GetFloorFireList(int cengID) { Transform fireParent = GameObject.Find("AllParent/pfire").transform; if (fireParent.childCount == 0) return null; CengID[] cengArray = fireParent.GetComponentsInChildren(); List floorFireList = new List(); foreach (var item in cengArray) { if (item.cengID == cengID) { floorFireList.Add(item.transform); } } return floorFireList; } /// /// 清除已经生成的夹攻箭头 /// private void ClearUpAndDownArrow() { Transform arrowParent = GameObject.Find("AllParent/pUpAndDownArrow").transform; if (arrowParent.childCount == 0) return ; RecordInstantiateEvent[] arrowArray = arrowParent.GetComponentsInChildren(); for (int i = 0; i < arrowArray.Length; i++) { Destroy(arrowArray[i].gameObject); } } List hideTransList = new List();//用来记录被隐掉的楼层; /// /// 用来控制主体与透明主体的显隐 /// /// private void MainBodyControl(bool hideorshow) { if (objTouMing == null || !objZhuTi || !transNow) return; objTouMing.SetActive(hideorshow); objZhuTi.SetActive(!hideorshow); Transform transQian = transNow.parent.parent.GetChild(0); Transform transHou = transNow.parent.parent.GetChild(1); if (hideorshow) { Transform child = null; for (int i = 0; i < transQian.childCount; i++) { child = transQian.GetChild(i); if (child == transNow) { continue; } else if (transQian && child == transUp) { transUp.gameObject.SetActive(true); continue; } else if (transDown && child == transDown) { transDown.gameObject.SetActive(true); continue; } else { if (child.gameObject.activeInHierarchy/*&&!hideTransList.Contains(child)*/) { child.gameObject.SetActive(false); hideTransList.Add(child); } } } for (int i = 0; i < transHou.childCount; i++) { child = transQian.GetChild(i); if (child == transNow) { continue; } else if (transQian && child == transUp) { transUp.gameObject.SetActive(true); continue; } else if (transDown && child == transDown) { transDown.gameObject.SetActive(true); continue; } else { if (child.gameObject.activeInHierarchy /*&& /*!hideTransList.Contains(child)*/) { child.gameObject.SetActive(false); hideTransList.Add(child); } } } } else { foreach (var item in hideTransList) { item.gameObject.SetActive(true); } if (transDown != null) { transDown.gameObject.SetActive(false); } hideTransList.Clear(); } } IEnumerator DelayCheck() { yield return new WaitForEndOfFrame(); if (objPArrowFather.transform.childCount!=0) { List arrowList = new List();//箭头名称 for (int i = 0; i < objPArrowFather.transform.childCount; i++) { arrowList.Add(objPArrowFather.transform.GetChild(0).name.Split('-')[0]); } Transform transQian = transNow.parent.parent.GetChild(0); Transform transHou = transNow.parent.parent.GetChild(1); for (int i = 0; i < arrowList.Count; i++) { for (int j = 0; j < transQian.childCount; j++) { Transform transTemp = transQian.GetChild(j); if (transTemp.gameObject.activeInHierarchy&&!transTemp.name.Contains(arrowList[i])) { transTemp.gameObject.SetActive(false); hideTransList.Add(transTemp);//需要隐藏的 } } } } } void ResetScene(IMessage msg) { objTouMing.gameObject.SetActive(false); objZhuTi.SetActive(true); ClearUpAndDownArrow(); MessageDispatcher.SendMessage("MoveDownFloor"); } /// /// 点击开始录制时,记录下是否有上下夹攻的箭头 /// /// void RecordArrow(IMessage msg) { RecordManager.Instance.record.hasUpDownArrow = objPArrowFather.transform.childCount>0; } }