using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReplayDashedLine : ReplaySimpleObject { protected CloneDashedLine cloneDashedLine; public override void Start() { cloneDashedLine = GetComponent(); base.Start(); } /// /// 回放克隆 /// /// public override void CloneObject(string json) { var jsonData = JsonUtility.FromJson(json); if (jsonData.isEvent == false) { ReplayFrame(jsonData); } else { ReplayEvent(jsonData); } } /// /// 回放事件 /// /// private void ReplayEvent(RecordDashedLine jsonData) { //克隆子物体 if (jsonData.isChild) { Transform parent = transform.Find(jsonData.objectName); var clonedChild = Instantiate(cloneDashedLine.clonePrefab, parent); clonedChild.transform.localPosition = jsonData.myTransform.getMyPosition(); clonedChild.name = jsonData.objectName; clonedChild.transform.localRotation = jsonData.myTransform.getMyRotation(); clonedChild.transform.localScale = jsonData.myTransform.getMyScale(); SelectedObjs.gameObjs.Add(clonedChild); CloneGameObjInfo objMsg = clonedChild.GetComponent(); objMsg.gameObjID = parent.GetComponent().gameObjID; objMsg.gameObjType = jsonData.gameObjType; objMsg.buildNum = jsonData.buildNum; objMsg.floorNum = jsonData.floorNum; objMsg.interlayerNum = jsonData.interlayerNum; SetCloneGameObject(clonedChild, ""); clonedChild.AddComponent(); //添加控制箭头大小 } //克隆父物体 else { var clonedObj = EntitiesManager.Instance.CreateObj(cloneDashedLine.parentPrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName)); clonedObj.name = jsonData.objectName;//名字即ID SetBaseGameObjectDashedLine(clonedObj, jsonData); SetCloneGameObject(clonedObj, ""); } } /// /// 回放状态 /// /// private void ReplayFrame(RecordDashedLine jsonData) { var clonedObj = EntitiesManager.Instance.CreateObj(cloneDashedLine.parentPrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName)); clonedObj.name = jsonData.objectName;//名字即ID SetBaseGameObject(clonedObj, jsonData); SetCloneGameObject(clonedObj, ""); //生成子物体 var list = jsonData.list; foreach (RecordObjectBase childData in list) { var clonedChild = Instantiate(cloneDashedLine.clonePrefab, clonedObj.transform); clonedChild.transform.localPosition = childData.myTransform.getMyPosition(); clonedChild.name = childData.objectName; clonedChild.transform.localRotation = childData.myTransform.getMyRotation(); clonedChild.transform.localScale = childData.myTransform.getMyScale(); SelectedObjs.gameObjs.Add(clonedChild); CloneGameObjInfo objMsg = clonedChild.GetComponent(); objMsg.gameObjID = clonedObj.GetComponent().gameObjID; objMsg.gameObjType = childData.gameObjType; objMsg.buildNum = childData.buildNum; objMsg.floorNum = childData.floorNum; objMsg.interlayerNum = childData.interlayerNum; SetCloneGameObject(clonedChild, ""); clonedChild.AddComponent(); //添加控制箭头大小 } } /// /// 设置基本属性 /// /// /// public void SetBaseGameObjectDashedLine(GameObject clonedObj, RecordObjectBase jsonData) { clonedObj.name = jsonData.objectName; clonedObj.transform.localRotation = jsonData.myTransform.getMyRotation(); clonedObj.transform.localPosition = jsonData.myTransform.getMyPosition(); clonedObj.transform.localScale = jsonData.myTransform.getMyScale(); SelectedObjs.gameObjs.Add(clonedObj); CloneGameObjInfo objMsg = clonedObj.GetComponent(); objMsg.gameObjID = long.Parse(jsonData.objectName); objMsg.gameObjType = jsonData.gameObjType; objMsg.buildNum = jsonData.buildNum; objMsg.floorNum = jsonData.floorNum; objMsg.interlayerNum = jsonData.interlayerNum; } public override void SetCloneGameObject(GameObject obj, string json) { obj.AddComponent(); obj.AddComponent(); } }