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.
202 lines
8.1 KiB
202 lines
8.1 KiB
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<DrawLineRecordData>(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<DrawLinMessage>().Linelength = data.linelength; |
|
// Line.GetComponent<DrawLinMessage>().AllLength = data.alllength; |
|
// Line.GetComponent<CloneGameObjInfo>().buildNum = data.buildNum; |
|
// Line.GetComponent<CloneGameObjInfo>().floorNum = data.floorNum; |
|
// Line.GetComponent<CloneGameObjInfo>().interlayerNum = data.interlayerNum; |
|
// } |
|
//} |
|
} |
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("ReplayEvent", ReplayAgent); |
|
} |
|
public void RecordDiverseData(List<KeyValueData> SpecialData, GameObject gameObject) |
|
{ |
|
XiaoFangYuanDrawLine DrawLine = gameObject.GetComponent<XiaoFangYuanDrawLine>(); |
|
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<AgentController>().corners; |
|
DrawlineList.MoveAble = gameObject.GetComponent<NavMeshAgent>().enabled; |
|
DrawlineList.num = DrawLine.num; |
|
if (DrawLine.Line != null) |
|
{ |
|
DrawlineList.LineType = DrawLine.Line.GetComponent<CloneGameObjInfo>().gameObjType; |
|
} |
|
SpecialData.Add(new KeyValueData() |
|
{ |
|
Key = typeof(DrawLineListRecordData).ToString(), |
|
Value = JsonUtility.ToJson(DrawlineList) |
|
}); |
|
} |
|
|
|
public void ReplayDiverseData(List<KeyValueData> SpecialData, GameObject gameObject) |
|
{ |
|
Bag bag = gameObject.GetComponent<Bag>(); |
|
DrawLineListRecordData DrawlinelistData = null; |
|
for (int i = 0; i < SpecialData.Count; i++) |
|
{ |
|
if (SpecialData[i].Key == typeof(DrawLineListRecordData).ToString()) |
|
{ |
|
DrawlinelistData = JsonUtility.FromJson<DrawLineListRecordData>(SpecialData[i].Value); |
|
break; |
|
} |
|
} |
|
var xiaofangyuanDraw = gameObject.GetComponent<XiaoFangYuanDrawLine>(); |
|
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<AgentController>().corners = DrawlinelistData.nowPath; |
|
gameObject.GetComponent<NavMeshAgent>().enabled = DrawlinelistData.MoveAble; |
|
gameObject.GetComponent<AgentController>().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<DrawLinMessage>().Recorddata.IsEndDraw = true; |
|
// } |
|
// else |
|
// { |
|
// Draw(data); |
|
// GameObject line = GameObject.Find(data.objectName); |
|
// line.GetComponent<DrawLinMessage>().Recorddata.IsEndDraw = true; |
|
// } |
|
//} |
|
Draw(data); |
|
if (data.IsEndDraw) |
|
{ |
|
GameObject line = GameObject.Find(data.objectName); |
|
line.GetComponent<DrawLinMessage>().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<DrawLinMessage>().Linelength = data.linelength; |
|
Line.GetComponent<DrawLinMessage>().AllLength = data.alllength; |
|
Line.GetComponent<CloneGameObjInfo>().buildNum = data.buildNum; |
|
Line.GetComponent<CloneGameObjInfo>().floorNum = data.floorNum; |
|
Line.GetComponent<CloneGameObjInfo>().interlayerNum = data.interlayerNum; |
|
Line.GetComponent<DrawLinMessage>().Recorddata = data; |
|
} |
|
} |
|
}
|
|
|