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.
128 lines
5.0 KiB
128 lines
5.0 KiB
3 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ReplayDashedLine : ReplaySimpleObject
|
||
|
{
|
||
|
protected CloneDashedLine cloneDashedLine;
|
||
|
public override void Start()
|
||
|
{
|
||
|
cloneDashedLine = GetComponent<CloneDashedLine>();
|
||
|
base.Start();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 回放克隆
|
||
|
/// </summary>
|
||
|
/// <param name="json"></param>
|
||
|
public override void CloneObject(string json)
|
||
|
{
|
||
|
var jsonData = JsonUtility.FromJson<RecordDashedLine>(json);
|
||
|
if (jsonData.isEvent == false)
|
||
|
{
|
||
|
ReplayFrame(jsonData);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ReplayEvent(jsonData);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 回放事件
|
||
|
/// </summary>
|
||
|
/// <param name="jsonData"></param>
|
||
|
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<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<ArrowScaleControl>(); //添加控制箭头大小
|
||
|
}
|
||
|
//克隆父物体
|
||
|
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, "");
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 回放状态
|
||
|
/// </summary>
|
||
|
/// <param name="jsonData"></param>
|
||
|
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<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, "");
|
||
|
clonedChild.AddComponent<ArrowScaleControl>(); //添加控制箭头大小
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 设置基本属性
|
||
|
/// </summary>
|
||
|
/// <param name="clonedObj"></param>
|
||
|
/// <param name="jsonData"></param>
|
||
|
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<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>();
|
||
|
}
|
||
|
}
|