上海杨浦大连路地铁站单机版电子沙盘
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.
 
 
 
 

135 lines
5.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReplayWaterLine : ReplayMultiLine {
/// <summary>
/// 回放克隆
/// </summary>
/// <param name="json"></param>
public override void CloneObject(string json)
{
var jsonData = JsonUtility.FromJson<RecordWaterLine>(json);
if (jsonData.isEvent == false)
{
ReplayWaterLineFrame(jsonData);
}
else
{
ReplayWaterLineEvent(jsonData);
}
}
private void ReplayWaterLineEvent(RecordWaterLine 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, "");
//克隆管线子物体添加物体删除脚本,要不然回放删除的时候会多走一遍,因为父物体跟子物体名字相同,多发了一遍
clonedChild.AddComponent<ObjSelectCtrl>();
//设置水源信息
var waterLineInfo = parent.GetComponent<WaterLineInfo>();
waterLineInfo.state = ConnectState.none;
waterLineInfo.SupplierID = jsonData.supplierID;
waterLineInfo.ReceiverID = jsonData.receiverID;
}
//克隆父物体
else
{
var clonedObj = EntitiesManager.Instance.CreateObj(cloneMultiLine.parentPrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName));
clonedObj.name = jsonData.objectName;//名字即ID
SetBaseGameObjectWaterLine(clonedObj, jsonData);
SetCloneGameObject(clonedObj, "");
//设置水源信息
var waterLineInfo = clonedObj.GetComponent<WaterLineInfo>();
waterLineInfo.state = ConnectState.none;
waterLineInfo.SupplierID = jsonData.supplierID;
waterLineInfo.ReceiverID = jsonData.receiverID;
}
}
/// <summary>
/// 回放状态
/// </summary>
/// <param name="jsonData"></param>
private void ReplayWaterLineFrame(RecordWaterLine 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, "");
//设置水源信息
WaterLineInfo waterLineInfo = clonedObj.GetComponent<WaterLineInfo>();
waterLineInfo.state = ConnectState.none;
waterLineInfo.tipFlag = false;
waterLineInfo.SupplierID = jsonData.supplierID;
waterLineInfo.ReceiverID = jsonData.receiverID;
waterLineInfo.tipFlag = true;
//生成子物体
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;
clonedChild.AddComponent<ObjSelectCtrl>();
// SetCloneGameObject(clonedChild, "");
}
}
/// <summary>
/// 设置基本属性
/// </summary>
/// <param name="clonedObj"></param>
/// <param name="jsonData"></param>
public void SetBaseGameObjectWaterLine(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;
}
public override void SetCloneGameObject(GameObject obj, string json)
{
obj.AddComponent<ObjSelectCtrl>();
obj.AddComponent<ObjDelete>();
}
}