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

184 lines
7.0 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireControl : ObjDoubleClick
{
public FireSettingData MyData;
public TextMesh WDtext;
public TextMesh RFStext;
public void Start()
{
MessageDispatcher.AddListener("ReplayEvent", ReplayEventFire);
MessageDispatcher.AddListener("ReplayEvent", ReplayEventFireReset);
MessageDispatcher.AddListener("ReplayEvent", ReplayFireTemperature);
MessageDispatcher.AddListener("ReplayEvent", ReplayFireRadiation);
MessageDispatcher.AddListener("ShowHideInfo", InfoActive);
AgentController.checkCautionAreaEntering += CheckEnterCautionArea;
InitInfo();
}
public void OnDestroy()
{
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventFire);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventFireReset);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayFireTemperature);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayFireRadiation);
MessageDispatcher.RemoveListener("ShowHideInfo", InfoActive);
AgentController.checkCautionAreaEntering -= CheckEnterCautionArea;
}
private void InfoActive(IMessage obj)
{
WDtext.gameObject.SetActive(GlobalVariable.InfoActive);
RFStext.gameObject.SetActive(GlobalVariable.InfoActive);
}
private void InitInfo()
{
WDtext.gameObject.SetActive(GlobalVariable.InfoActive);
RFStext.gameObject.SetActive(GlobalVariable.InfoActive);
}
private void ReplayEventFire(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.Fire)
{
FireSettingData data = JsonUtility.FromJson<FireSettingData>(eventData.json);
if (data.name == gameObject.name)
{
MyData = data;
//UI回放
//FireSettingPanel.GetActiveInstance.SettingFire(gameObject);
//StartCoroutine(hide());
}
}
}
private void ReplayEventFireReset(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.FireReset)
{
FireSettingData data = JsonUtility.FromJson<FireSettingData>(eventData.json);
if (data.name == gameObject.name)
{
MyData = data;
//重置路径时,如果是已经蔓延过一次及存在蔓延出来的火,重置删除蔓延路径的同时,删除蔓延出来的火
Transform pfire = GameObject.Find("P_AllParent").transform.Find("P_Disaster/P_SpreadFire");
foreach (Transform child in pfire)
{
if (child.GetComponent<SpreadFire>() && child.GetComponent<SpreadFire>().SourceId == MyData.id)
{
Destroy(child.gameObject);
}
}
gameObject.GetComponent<FireSpreadCtrl>().Reset();
}
}
}
IEnumerator hide()
{
yield return new WaitForSeconds(0.5f);
FireSettingPanel.GetInstance.gameObject.SetActive(false);
}
public override void ClickFunc()
{
base.ClickFunc();
if (MyData == null)
{
MyData = new FireSettingData();
}
if (MyData.id == 0)
{
MyData.id = GetComponent<CloneGameObjInfo>().gameObjID;
}
MyData.name = gameObject.name;
FireSettingPanel.GetActiveInstance.SettingFire(gameObject);
}
public void SetTemperatureText()
{
WDtext.text = string.IsNullOrEmpty(MyData.temperature) ? "" : "温度:" + MyData.temperature;
AddRecordFireTemperatureEvent();
}
private void AddRecordFireTemperatureEvent()
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = GetComponent<CloneGameObjInfo>().gameObjType;
eventData.eventType = RecordEventType.FireTemperature;
FireTemperatureData data = new FireTemperatureData();
data.gameObjID = GetComponent<CloneGameObjInfo>().gameObjID;
data.temperature = MyData.temperature;
eventData.json = JsonUtility.ToJson(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
private void ReplayFireTemperature(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.FireTemperature)
{
FireTemperatureData data = JsonUtility.FromJson<FireTemperatureData>(eventData.json);
if (data.gameObjID == GetComponent<CloneGameObjInfo>().gameObjID)
{
WDtext.text = string.IsNullOrEmpty(data.temperature) ? "" : "温度:" + data.temperature;
}
}
}
public void SetRadiationText()
{
RFStext.text = string.IsNullOrEmpty(MyData.radiation) ? "" : "热辐射:" + MyData.radiation;
AddRecordFireRadiationEvent();
}
private void AddRecordFireRadiationEvent()
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = GetComponent<CloneGameObjInfo>().gameObjType;
eventData.eventType = RecordEventType.FireRadiation;
FireRadiationData data = new FireRadiationData();
data.gameObjID = GetComponent<CloneGameObjInfo>().gameObjID;
data.radiation = MyData.radiation;
eventData.json = JsonUtility.ToJson(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
private void ReplayFireRadiation(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.FireRadiation)
{
FireRadiationData data = JsonUtility.FromJson<FireRadiationData>(eventData.json);
if (data.gameObjID == GetComponent<CloneGameObjInfo>().gameObjID)
{
RFStext.text = string.IsNullOrEmpty(data.radiation) ? "" : "热辐射:" + data.radiation;
}
}
}
/// <summary>
/// 检测人员是否进入警戒区,警戒区:火焰外围15米范围内
/// </summary>
/// <param name="point"></param>
/// <param name="data"></param>
/// <returns></returns>
private IntData CheckEnterCautionArea(Vector3 point,IntData data)
{
float distance = Vector3.Distance(point, transform.position);
if (distance <= 15) //如果距离小于15,计数
{
data.value += 1;
}
return data;
}
}