using AX.MessageSystem; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class DrawLineRecord : MonoBehaviour, IRecordDiverseData, IReplayDiverseData { public GameObject DrawLine; public GameObject LiftLine; private void OnEnable() { MessageDispatcher.AddListener("ReplayEvent", ReplayAgent); } private void ReplayAgent(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.eventType == RecordEventType.DrawLine) { var data = JsonUtility.FromJson(eventData.json); DrawLineFunc(data); //if (!data.IsCreat) //{ // Destroy(GameObject.Find(data.objectName)); //} //else //{ // if (data.IsEndDraw) // { // GameObject.Find(data.objectName).name += "-endLine"; // } // else // { // GameObject Line = null; // if (data.gameObjType == CloneObjType.DrawLine) // { // Line = Instantiate(DrawLine, data.clonepos, Quaternion.identity); // } // else if (data.gameObjType == CloneObjType.LiftLightLine) // { // Line = Instantiate(LiftLine, data.clonepos, Quaternion.identity); // } // Line.transform.parent = GameObject.Find(data.parentobjname).transform; // Line.transform.localPosition = data.myTransform.getMyPosition(); // Line.transform.localRotation = data.myTransform.getMyRotation(); // Line.transform.localScale = data.myTransform.getMyScale(); // Line.name = data.objectName; // Line.GetComponent().Linelength = data.linelength; // Line.GetComponent().AllLength = data.alllength; // Line.GetComponent().buildNum = data.buildNum; // Line.GetComponent().floorNum = data.floorNum; // Line.GetComponent().interlayerNum = data.interlayerNum; // } //} } } private void OnDestroy() { MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent); } public void RecordDiverseData(List SpecialData, GameObject gameObject) { XiaoFangYuanDrawLine DrawLine = gameObject.GetComponent(); if (DrawLine == null) { return; } DrawLine.CreatParent(); var DrawlineList = new DrawLineListRecordData(); DrawlineList.data = DrawLine.GetmessageList(); DrawlineList.gameobjname = gameObject.name; DrawlineList.Allline = DrawLine.AllLine; DrawlineList.AllLineDistance = DrawLine.AllLineDistance; DrawlineList.Allpath = DrawLine.Allpath; DrawlineList.BeginLiftLineNum = DrawLine.BeginLiftLineNum; DrawlineList.BeginLineNum = DrawLine.BeginLineNum; DrawlineList.nowPath = gameObject.GetComponent().corners; DrawlineList.MoveAble = gameObject.GetComponent().enabled; DrawlineList.num = DrawLine.num; if (DrawLine.Line != null) { DrawlineList.LineType = DrawLine.Line.GetComponent().gameObjType; } SpecialData.Add(new KeyValueData() { Key = typeof(DrawLineListRecordData).ToString(), Value = JsonUtility.ToJson(DrawlineList) }); } public void ReplayDiverseData(List SpecialData, GameObject gameObject) { Bag bag = gameObject.GetComponent(); DrawLineListRecordData DrawlinelistData = null; for (int i = 0; i < SpecialData.Count; i++) { if (SpecialData[i].Key == typeof(DrawLineListRecordData).ToString()) { DrawlinelistData = JsonUtility.FromJson(SpecialData[i].Value); break; } } var xiaofangyuanDraw = gameObject.GetComponent(); if (DrawlinelistData != null && xiaofangyuanDraw != null) { xiaofangyuanDraw.RecordInit(); if (DrawlinelistData.gameobjname==gameObject.name) { //xiaofangyuanDraw.RecordInit(); for (int i = 0; i < DrawlinelistData.data.Count; i++) { DrawLineFunc(DrawlinelistData.data[i]); } } xiaofangyuanDraw.AllLine = DrawlinelistData.Allline; xiaofangyuanDraw.Allpath = DrawlinelistData.Allpath; xiaofangyuanDraw.AllLineDistance = DrawlinelistData.AllLineDistance; xiaofangyuanDraw.BeginLiftLineNum = DrawlinelistData.BeginLiftLineNum; xiaofangyuanDraw.BeginLineNum = DrawlinelistData.BeginLineNum; gameObject.GetComponent().corners = DrawlinelistData.nowPath; gameObject.GetComponent().enabled = DrawlinelistData.MoveAble; gameObject.GetComponent().enabled = DrawlinelistData.MoveAble; xiaofangyuanDraw.num = DrawlinelistData.num; if (DrawlinelistData.LineType == CloneObjType.DrawLine) { xiaofangyuanDraw.Line = xiaofangyuanDraw.Guanxian; } else if (DrawlinelistData.LineType == CloneObjType.LiftLightLine) { xiaofangyuanDraw.Line = xiaofangyuanDraw.Zhaomingxian; } else { xiaofangyuanDraw.Line = null; } } } private void DrawLineFunc(DrawLineRecordData data ) { if (!data.IsCreat) { Destroy(GameObject.Find(data.objectName)); } else { //if (!data.IsEndDraw) //{ // Draw(data); //} //else //{ // if (GameObject.Find(data.objectName)) // { // GameObject line = GameObject.Find(data.objectName); // line.GetComponent().Recorddata.IsEndDraw = true; // } // else // { // Draw(data); // GameObject line = GameObject.Find(data.objectName); // line.GetComponent().Recorddata.IsEndDraw = true; // } //} Draw(data); if (data.IsEndDraw) { GameObject line = GameObject.Find(data.objectName); line.GetComponent().Recorddata.IsEndDraw = true; } } } private void Draw(DrawLineRecordData data) { GameObject Line = null; if (data.gameObjType == CloneObjType.DrawLine) { Line = Instantiate(DrawLine, data.clonepos, Quaternion.identity); } else if (data.gameObjType == CloneObjType.LiftLightLine) { Line = Instantiate(LiftLine, data.clonepos, Quaternion.identity); } if (GameObject.Find(data.parentobjname)) { Line.transform.parent = GameObject.Find(data.parentobjname).transform; Line.transform.localPosition = data.myTransform.getMyPosition(); Line.transform.localRotation = data.myTransform.getMyRotation(); Line.transform.localScale = data.myTransform.getMyScale(); Line.name = data.objectName; Line.GetComponent().Linelength = data.linelength; Line.GetComponent().AllLength = data.alllength; Line.GetComponent().buildNum = data.buildNum; Line.GetComponent().floorNum = data.floorNum; Line.GetComponent().interlayerNum = data.interlayerNum; Line.GetComponent().Recorddata = data; } } }