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; } } /// /// 记录状态数据 /// 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().GetNowCameraData()); frameData.objectDataList.Add(data); } {//添加天气初始化信息 ObjectData data = new ObjectData(); data.cloneObjType = CloneObjType.Weather; WeatherSettingManager manager = GameObject.Find("Canvas").transform.Find("WeatherSettingPanel").GetComponent(); data.json = JsonUtility.ToJson(manager.GetNowSettingData()); frameData.objectDataList.Add(data); } //{//添加场景中自动水炮初始化信息 // foreach (Transform item in GameObject.Find("Scene").transform.Find("XFSS")) // { // if (item.GetComponent()) // { // if (item.GetComponent().gameObjType== CloneObjType.ZDSP) // { // ObjectData data = new ObjectData(); // data.cloneObjType = CloneObjType.ZDSP; // data.json = JsonUtility.ToJson(item.GetComponent().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(); 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); } /// /// 添加所有克隆对象数据 /// /// /// private void AddData(Transform trs, List objectData) { if (trs.GetComponent()) { trs.GetComponent().AddRecordFrame(objectData); } foreach (Transform child in trs) { AddData(child, objectData); } } /// /// 保存数据文件 /// /// 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); } }