贺州人民医院电子沙盘
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.

136 lines
5.3 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SpreadFireData
{
public long sourceId;
public string name;
public Vector3 position;//位置
public Vector3 eulerAngles;//旋转
public Vector3 scale;//缩放
public string buildNum;//楼号
public int floorNum;//层号
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
public int Layer;
public string UserId;
}
[Serializable]
public class SpreadFireRecordData//蔓延出来的火的帧数据
{
public List<SpreadFireData> spreadFiredataList = new List<SpreadFireData>();
}
public class SpreadFireManager : MonoBehaviour
{
public static SpreadFireManager Instance;
public GameObject firePrefab;
private void Awake()
{
Instance = this;
}
void Start()
{
MessageDispatcher.AddListener("ReplayFrame", ReplayFrameData);
MessageDispatcher.AddListener("ReplayEvent", ReplayEventData);
}
public SpreadFireRecordData GetFrameData()
{
SpreadFireRecordData recordData = new SpreadFireRecordData();
foreach (Transform item in transform)
{
SpreadFireData data = new SpreadFireData();
data.name = item.name;
data.sourceId = item.GetComponent<SpreadFire>().SourceId;
data.position = item.localPosition;
data.eulerAngles = item.localRotation.eulerAngles;
data.scale = item.localScale;
data.buildNum = item.GetComponent<CloneGameObjInfo>().buildNum;//楼号
data.floorNum = item.GetComponent<CloneGameObjInfo>().floorNum;//层号
data.interlayerNum = item.GetComponent<CloneGameObjInfo>().interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
data.Layer = item.GetComponent<CloneGameObjInfo>().Layer;
recordData.spreadFiredataList.Add(data);
}
return recordData;
}
private void ReplayFrameData(IMessage obj)
{
var baseData = (ObjectData)obj.Data;
if (baseData.cloneObjType == CloneObjType.SpreadFireFrame)
{
ClearObject();
SpreadFireRecordData data = Newtonsoft.Json.JsonConvert.DeserializeObject<SpreadFireRecordData>(baseData.json);
if (data.spreadFiredataList.Count > 0)
{
foreach (var item in data.spreadFiredataList)
{
GameObject spreadfire = Instantiate(firePrefab, transform);
spreadfire.name = item.name;
spreadfire.transform.localPosition = item.position;
spreadfire.transform.localRotation = Quaternion.Euler
(item.eulerAngles.x, item.eulerAngles.y, item.eulerAngles.z) * Quaternion.identity;
spreadfire.transform.localScale = item.scale;
spreadfire.GetComponent<SpreadFire>().SourceId = item.sourceId;
spreadfire.GetComponent<CloneGameObjInfo>().buildNum = item.buildNum;
spreadfire.GetComponent<CloneGameObjInfo>().floorNum = item.floorNum;
spreadfire.GetComponent<CloneGameObjInfo>().interlayerNum = item.interlayerNum;
spreadfire.GetComponent<CloneGameObjInfo>().Layer = item.Layer;
}
}
}
}
private void ClearObject()
{
foreach (Transform item in transform)
{
Destroy(item.gameObject);
}
}
private void ReplayEventData(IMessage obj)
{
var baseEventData = (EventData)obj.Data;
if (baseEventData.eventType == RecordEventType.SpreadFireCreat)
{
SpreadFireCreatData data = Newtonsoft.Json.JsonConvert.DeserializeObject<SpreadFireCreatData>(baseEventData.json);
GameObject spreadfire = Instantiate(firePrefab, transform);
spreadfire.name = data.name;
spreadfire.transform.localPosition = data.position;
spreadfire.transform.localRotation = Quaternion.Euler
(data.eulerAngles.x, data.eulerAngles.y, data.eulerAngles.z) * Quaternion.identity;
spreadfire.transform.localScale = data.scale;
spreadfire.GetComponent<SpreadFire>().SourceId = data.sourceId;
spreadfire.GetComponent<CloneGameObjInfo>().buildNum = data.buildNum;
spreadfire.GetComponent<CloneGameObjInfo>().floorNum = data.floorNum;
spreadfire.GetComponent<CloneGameObjInfo>().interlayerNum = data.interlayerNum;
spreadfire.GetComponent<CloneGameObjInfo>().Layer = data.Layer;
}
else if (baseEventData.eventType == RecordEventType.SpreadFireDestory)
{
foreach (Transform item in transform)
{
if (item.GetComponent<SpreadFire>())
{
SpreadFireDestoryData data = (SpreadFireDestoryData)obj.Data;
if (item.GetComponent<SpreadFire>().SourceId == data.sourceId)
{
Destroy(item.gameObject);
}
}
}
}
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventData);
MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameData);
}
}