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.
125 lines
4.9 KiB
125 lines
4.9 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class ReplayMultiLine : ReplaySimpleObject |
|
{ |
|
protected CloneMultiLine cloneMultiLine; |
|
public override void Start() |
|
{ |
|
cloneMultiLine = GetComponent<CloneMultiLine>(); |
|
base.Start(); |
|
} |
|
/// <summary> |
|
/// 回放克隆 |
|
/// </summary> |
|
/// <param name="json"></param> |
|
public override void CloneObject(string json) |
|
{ |
|
var jsonData = JsonUtility.FromJson<RecordMultiLine>(json); |
|
if (jsonData.isEvent == false) |
|
{ |
|
ReplayFrame(jsonData); |
|
} |
|
else |
|
{ |
|
ReplayEvent(jsonData); |
|
} |
|
} |
|
/// <summary> |
|
/// 回放事件 |
|
/// </summary> |
|
/// <param name="jsonData"></param> |
|
protected virtual void ReplayEvent(RecordMultiLine jsonData) |
|
{ |
|
//克隆子物体 |
|
if (jsonData.isChild) |
|
{ |
|
Transform parent = transform.Find(jsonData.objectName); |
|
var clonedChild = Instantiate(cloneMultiLine.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<CloneGameObjInfo>(); |
|
objMsg.gameObjID = parent.GetComponent<CloneGameObjInfo>().gameObjID; |
|
objMsg.gameObjType = jsonData.gameObjType; |
|
objMsg.buildNum = jsonData.buildNum; |
|
objMsg.floorNum = jsonData.floorNum; |
|
objMsg.interlayerNum = jsonData.interlayerNum; |
|
|
|
SetCloneGameObject(clonedChild, ""); |
|
} |
|
//克隆父物体 |
|
else |
|
{ |
|
var clonedObj = EntitiesManager.Instance.CreateObj(cloneMultiLine.parentPrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName)); |
|
clonedObj.name = jsonData.objectName;//名字即ID |
|
|
|
SetBaseGameObjectMultiLine(clonedObj, jsonData); |
|
SetCloneGameObject(clonedObj, ""); |
|
} |
|
} |
|
public override void SetCloneGameObject(GameObject obj, string json) |
|
{ |
|
obj.AddComponent<ObjSelectCtrl>(); |
|
obj.AddComponent<ObjDelete>(); |
|
} |
|
/// <summary> |
|
/// 回放状态 |
|
/// </summary> |
|
/// <param name="jsonData"></param> |
|
protected virtual void ReplayFrame(RecordMultiLine jsonData) |
|
{ |
|
var clonedObj = EntitiesManager.Instance.CreateObj(cloneMultiLine.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(cloneMultiLine.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<CloneGameObjInfo>(); |
|
objMsg.gameObjID = clonedObj.GetComponent<CloneGameObjInfo>().gameObjID; |
|
objMsg.gameObjType = childData.gameObjType; |
|
objMsg.buildNum = childData.buildNum; |
|
objMsg.floorNum = childData.floorNum; |
|
objMsg.interlayerNum = childData.interlayerNum; |
|
|
|
SetCloneGameObject(clonedChild, ""); |
|
} |
|
} |
|
/// <summary> |
|
/// 设置基本属性 |
|
/// </summary> |
|
/// <param name="clonedObj"></param> |
|
/// <param name="jsonData"></param> |
|
public void SetBaseGameObjectMultiLine(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<CloneGameObjInfo>(); |
|
objMsg.gameObjID = long.Parse(jsonData.objectName); |
|
objMsg.gameObjType = jsonData.gameObjType; |
|
objMsg.buildNum = jsonData.buildNum; |
|
objMsg.floorNum = jsonData.floorNum; |
|
objMsg.interlayerNum = jsonData.interlayerNum; |
|
} |
|
}
|
|
|