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.
173 lines
6.1 KiB
173 lines
6.1 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
using System.Xml;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class RecordManager : MonoBehaviour
|
||
|
{
|
||
|
public static RecordManager Instance;
|
||
|
public RecordStatus recordStatus;
|
||
|
public float RecordTimer = 0;
|
||
|
public JsonData jsonData;
|
||
|
private Transform parent;
|
||
|
void Awake()
|
||
|
{
|
||
|
if (Instance == null)
|
||
|
{
|
||
|
Instance = this;
|
||
|
}
|
||
|
}
|
||
|
// Use this for initialization
|
||
|
void Start()
|
||
|
{
|
||
|
parent = GameObject.Find("P_AllParent").transform;
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
void FixedUpdate()
|
||
|
{
|
||
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && recordStatus == RecordStatus.normal)
|
||
|
{
|
||
|
RecordTimer += Time.deltaTime;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 记录状态数据
|
||
|
/// </summary>
|
||
|
public void RecordFrame()
|
||
|
{
|
||
|
var frameData = new FrameData();
|
||
|
frameData.time = RecordTimer;
|
||
|
AddData(parent, frameData.objectDataList);
|
||
|
{//添加相机初始化信息
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.Camera;
|
||
|
data.json = JsonUtility.ToJson(Camera.main.GetComponent<CameraManager>().GetNowCameraData());
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
{//添加天气初始化信息
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.Weather;
|
||
|
WeatherSettingManager manager = GameObject.Find("Canvas").transform.Find("WeatherSettingPanel").GetComponent<WeatherSettingManager>();
|
||
|
data.json = JsonUtility.ToJson(manager.GetNowSettingData());
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
//{//添加场景中自动水炮初始化信息
|
||
|
// foreach (Transform item in GameObject.Find("Scene").transform.Find("XFSS"))
|
||
|
// {
|
||
|
// if (item.GetComponent<CloneGameObjInfo>())
|
||
|
// {
|
||
|
// if (item.GetComponent<CloneGameObjInfo>().gameObjType== CloneObjType.ZDSP)
|
||
|
// {
|
||
|
// ObjectData data = new ObjectData();
|
||
|
// data.cloneObjType = CloneObjType.ZDSP;
|
||
|
// data.json = JsonUtility.ToJson(item.GetComponent<FCGSPControl>().GetData());
|
||
|
// frameData.objectDataList.Add(data);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
{//添加选中状态记录
|
||
|
//if (SelectedObjs.selectedObj != null)
|
||
|
//{
|
||
|
// ObjectData data = new ObjectData();
|
||
|
// data.cloneObjType = CloneObjType.Selected;
|
||
|
// data.json = SelectedObjs.selectedObj.name;
|
||
|
// frameData.objectDataList.Add(data);
|
||
|
//}
|
||
|
//else if (SelectedObjs.selectedCharacters.Count > 0)
|
||
|
//{
|
||
|
// ObjectData data = new ObjectData();
|
||
|
// data.cloneObjType = CloneObjType.Selected;
|
||
|
// foreach (var item in SelectedObjs.selectedCharacters)
|
||
|
// {
|
||
|
// data.json += (item.name + "&");
|
||
|
// }
|
||
|
// frameData.objectDataList.Add(data);
|
||
|
//}
|
||
|
}
|
||
|
{//添加场景中罐区消防系统
|
||
|
var StorageTankSystem = GameObject.Find("P_AllParent").GetComponentsInChildren<StorageTankSystem>();
|
||
|
foreach (StorageTankSystem item in StorageTankSystem)
|
||
|
{
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.StorageTankSystem;
|
||
|
data.json = JsonUtility.ToJson(item.AddRecordFrameData());
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
}
|
||
|
{//添加场景中楼层选中情况
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.UIFloor;
|
||
|
data.json = JsonUtility.ToJson(GlobalVariable.CurrentFloor);
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
{//添加工具栏显示情况
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.ToolsOn;
|
||
|
data.json = GlobalVariable.ToolsOn.ToString();
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
{//添加楼层信息显示情况
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.FloorsOn;
|
||
|
data.json = GlobalVariable.FloorsOn.ToString();
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
{//添加楼层信息显示滑动条情况
|
||
|
ObjectData data = new ObjectData();
|
||
|
data.cloneObjType = CloneObjType.FloorsScrollBar;
|
||
|
data.json = GlobalVariable.FloorsScrollBarValue.ToString();
|
||
|
frameData.objectDataList.Add(data);
|
||
|
}
|
||
|
jsonData.frameDataList.Add(frameData);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 添加所有克隆对象数据
|
||
|
/// </summary>
|
||
|
/// <param name="trs"></param>
|
||
|
/// <param name="objectData"></param>
|
||
|
private void AddData(Transform trs, List<ObjectData> objectData)
|
||
|
{
|
||
|
if (trs.GetComponent<CloneBase>())
|
||
|
{
|
||
|
trs.GetComponent<CloneBase>().AddRecordFrame(objectData);
|
||
|
}
|
||
|
foreach (Transform child in trs)
|
||
|
{
|
||
|
AddData(child, objectData);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 保存数据文件
|
||
|
/// </summary>
|
||
|
/// <param name="nodeName"></param>
|
||
|
public void SaveRecord(string nodeName)
|
||
|
{
|
||
|
string path = Application.dataPath + @"/Data/" + DisasterManager.disaster.Id + "/File/XmlData/";
|
||
|
if (!Directory.Exists(path))
|
||
|
{
|
||
|
Directory.CreateDirectory(path);
|
||
|
}
|
||
|
string filePath = path + nodeName + ".xml";
|
||
|
if (File.Exists(filePath))
|
||
|
{
|
||
|
File.Delete(filePath);
|
||
|
}
|
||
|
XmlDocument document = new XmlDocument();
|
||
|
XmlDeclaration xmldecl = document.CreateXmlDeclaration("1.0", "UTF-8", "yes");
|
||
|
document.AppendChild(xmldecl);
|
||
|
XmlElement record = document.CreateElement("Record");
|
||
|
record.InnerText = JsonUtility.ToJson(jsonData);
|
||
|
document.AppendChild(record);
|
||
|
document.Save(filePath);
|
||
|
}
|
||
|
}
|