海淀天下城电子沙盘单机版
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.

134 lines
5.0 KiB

4 years ago
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class PoChaiData
{
public string name;
public bool standWrong;
}
public class ForcibleEntryPointControl : ObjDoubleClick
{
private bool has;
private bool standWrong = false;
public Transform WrongArea;
public Transform RightArea;
public Transform RightArea1;
public void Start()
{
MessageDispatcher.AddListener("ReplayEvent", ReplayEventPoChai);
WrongArea = transform.Find("WrongArea");
RightArea = transform.Find("RightArea");
RightArea1 = transform.Find("RightArea1");
}
private void ReplayEventPoChai(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.PoChai)
{
PoChaiData data = JsonUtility.FromJson<PoChaiData>(eventData.json);
if (data.name == gameObject.name)
{
gameObject.SetActive(false);
ResourceLoadWindow.Instance.LoadTextHintWindow("破拆完毕", 1f);
}
}
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventPoChai);
}
public override void ClickFunc()
{
base.ClickFunc();
List<KeyValuePair<FireManMessage, bool>> FireManList = new List<KeyValuePair<FireManMessage, bool>>();//保存就近消防员
foreach (Transform child in GameObject.Find("P_AllParent/P_People/P_FireMan").transform)
{
Vector3 pos1 = new Vector3(child.transform.position.x, WrongArea.position.y, child.transform.position.z);
float dis1 = Vector3.Distance(pos1, WrongArea.position);//站位错误
if (dis1 < 0.7f)
{
standWrong = true;
FireManList.Add(new KeyValuePair<FireManMessage, bool>(child.GetComponent<FireManMessage>(), standWrong));
continue;
}
Vector3 pos2 = new Vector3(child.transform.position.x, RightArea.position.y, child.transform.position.z);
float dis2 = Vector3.Distance(pos2, RightArea.position);//站位正确
if (dis2 < 0.7f)
{
standWrong = false;
FireManList.Add(new KeyValuePair<FireManMessage, bool>(child.GetComponent<FireManMessage>(), standWrong));
continue;
}
Vector3 pos3 = new Vector3(child.transform.position.x, RightArea1.position.y, child.transform.position.z);
float dis3 = Vector3.Distance(pos3, RightArea1.position);//站位正确
if (dis3 < 0.7f)
{
standWrong = false;
FireManList.Add(new KeyValuePair<FireManMessage, bool>(child.GetComponent<FireManMessage>(), standWrong));
continue;
}
}
if (FireManList.Count == 0)
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请消防员站在破拆区域破拆", 1f);
}
else
{
for (int i = 0; i < FireManList.Count; i++)
{
if (FireManList[i].Key.workType != FireManSkills.ForcibleEntry)
{
FireManList.Remove(FireManList[i]);
i--;
}
}
if (FireManList.Count == 0)
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请消防员选中破拆技能", 1f);
}
else if (FireManList.Count == 1)
{
if (FireManList[0].Value == true)
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请消防员站在正确的位置破拆", 1f);
}
else
{
gameObject.SetActive(false);
ResourceLoadWindow.Instance.LoadTextHintWindow("破拆完毕", 1f);
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.PoChai, JsonUtility.ToJson(
new PoChaiData() { name = gameObject.name, standWrong = this.standWrong }));
}
}
else
{
foreach (var item in FireManList)
{
if (item.Value == false)
{
has = true;
break;
}
}
if (has)
{
gameObject.SetActive(false);
ResourceLoadWindow.Instance.LoadTextHintWindow("破拆完毕", 1f);
RecordEvent.AddEventData(CloneObjType.None, RecordEventType.PoChai, JsonUtility.ToJson(
new PoChaiData() { name = gameObject.name, standWrong = this.standWrong }));
}
else
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请消防员站在正确的位置破拆", 1f);
}
}
}
}
}