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.
434 lines
13 KiB
434 lines
13 KiB
3 years ago
|
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<GameObject> zhuTiList=new List<GameObject>();//主体
|
||
|
bool bShowArrow = true;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 是否双击了着火层
|
||
|
/// </summary>
|
||
|
public bool ChangFloorFlag { set; get; }
|
||
|
private void Awake()
|
||
|
{
|
||
|
Instance = this;
|
||
|
}
|
||
|
|
||
|
public List<int> cengList = new List<int>();
|
||
|
|
||
|
Toggle tgl;
|
||
|
private void Start()
|
||
|
{
|
||
|
if (!MySceneManager.GetActiveScene().name.Equals("11"))
|
||
|
{
|
||
|
transform.parent.gameObject.SetActive(false);
|
||
|
return;//上下夹击功能只有11场景可用
|
||
|
}
|
||
|
//tgl = GetComponent<Toggle>();
|
||
|
//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<new TimeSpan(0,0,0,0,400))
|
||
|
// {
|
||
|
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||
|
// RaycastHit hitinfo;
|
||
|
// if (Physics.Raycast(ray, out hitinfo, Mathf.Infinity, LayerMask.GetMask("shineiFloor")) ||
|
||
|
// Physics.Raycast(ray, out hitinfo, Mathf.Infinity, LayerMask.GetMask("wall")))
|
||
|
// {
|
||
|
// if (hitinfo.collider.gameObject.GetComponent<CengID>() == false) return;
|
||
|
// int cengId = hitinfo.collider.gameObject.GetComponent<CengID>().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<Toggle>();
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 上下夹攻的方法
|
||
|
/// </summary>
|
||
|
public void UpAndDownAttack(bool b)
|
||
|
{
|
||
|
PrePareModeSet.instance.CloseAssitToggle();//关闭打开的菜单栏
|
||
|
GetComponent<ToolHuaGuo>().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);
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 清楚存火的层
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
private void OnDisable()
|
||
|
{
|
||
|
if (cengList!=null&&cengList.Count!=0)
|
||
|
{
|
||
|
cengList.Clear();
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("ResetTheScene", ResetScene);
|
||
|
MessageDispatcher.RemoveListener("RecordArrow", RecordArrow);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 返回火焰所在的楼层
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
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<CengID>();
|
||
|
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<CengID>(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;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
///
|
||
|
/// </summary>
|
||
|
/// <param name="objArrow"></param>
|
||
|
/// <returns></returns>
|
||
|
private bool CheckArrowName(string arrowName)
|
||
|
{
|
||
|
if (objPArrowFather == null)
|
||
|
{
|
||
|
init();
|
||
|
}
|
||
|
Transform[] transArray = objPArrowFather.GetComponentsInChildren<Transform>();
|
||
|
for (int i = 0; i < transArray.Length; i++)
|
||
|
{
|
||
|
if (transArray[i].name.Equals(arrowName))
|
||
|
{
|
||
|
return true;//说明已经有箭头存在了,就不再实例化
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取当前层的火的链表
|
||
|
/// </summary>
|
||
|
/// <param name="cengID">所在层</param>
|
||
|
/// <returns></returns>
|
||
|
public List<Transform> GetFloorFireList(int cengID)
|
||
|
{
|
||
|
Transform fireParent = GameObject.Find("AllParent/pfire").transform;
|
||
|
if (fireParent.childCount == 0) return null;
|
||
|
CengID[] cengArray = fireParent.GetComponentsInChildren<CengID>();
|
||
|
List<Transform> floorFireList = new List<Transform>();
|
||
|
foreach (var item in cengArray)
|
||
|
{
|
||
|
if (item.cengID == cengID)
|
||
|
{
|
||
|
floorFireList.Add(item.transform);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
return floorFireList;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 清除已经生成的夹攻箭头
|
||
|
/// </summary>
|
||
|
private void ClearUpAndDownArrow()
|
||
|
{
|
||
|
Transform arrowParent = GameObject.Find("AllParent/pUpAndDownArrow").transform;
|
||
|
if (arrowParent.childCount == 0) return ;
|
||
|
RecordInstantiateEvent[] arrowArray = arrowParent.GetComponentsInChildren<RecordInstantiateEvent>();
|
||
|
for (int i = 0; i < arrowArray.Length; i++)
|
||
|
{
|
||
|
Destroy(arrowArray[i].gameObject);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
List<Transform> hideTransList = new List<Transform>();//用来记录被隐掉的楼层;
|
||
|
/// <summary>
|
||
|
/// 用来控制主体与透明主体的显隐
|
||
|
/// </summary>
|
||
|
/// <param name="hideorshow"></param>
|
||
|
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<string> arrowList = new List<string>();//箭头名称
|
||
|
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");
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 点击开始录制时,记录下是否有上下夹攻的箭头
|
||
|
/// </summary>
|
||
|
/// <param name="msg"></param>
|
||
|
void RecordArrow(IMessage msg)
|
||
|
{
|
||
|
RecordManager.Instance.record.hasUpDownArrow = objPArrowFather.transform.childCount>0;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|