大连中石油电子沙盘
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.
 
 
 
 

165 lines
6.9 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReplayCurtainLine : ReplaySimpleObject
{
protected CloneCurtainLine cloneCurtainLine;
public override void Start()
{
cloneCurtainLine = GetComponent<CloneCurtainLine>();
base.Start();
}
/// <summary>
/// 回放克隆
/// </summary>
/// <param name="json"></param>
public override void CloneObject(string json)
{
var jsonData = JsonUtility.FromJson<RecordCurtainLine>(json);
if (jsonData.isEvent == false)
{
var data= JsonUtility.FromJson<RecordCurtainLineParent>(json);
ReplayFrame(data);
}
else
{
if (jsonData.isChild)
{
var data = JsonUtility.FromJson<RecordCurtainLineChild>(json);
ReplayEventCloneChild(data);
}
else
{
var data= JsonUtility.FromJson<RecordCurtainLineParent>(json);
ReplayEventCloneParent(data);
}
}
}
/// <summary>
/// 回放事件:克隆父物体
/// </summary>
/// <param name="data"></param>
private void ReplayEventCloneParent(RecordCurtainLineParent data)
{
var parentObj = EntitiesManager.Instance.CreateObj(cloneCurtainLine.parentPrefab, data.myTransform.getMyPosition(), transform, long.Parse(data.objectName));
SetBaseGameObjectData(parentObj, data);
parentObj.AddComponent<WaterCurtainAttribute>();
parentObj.AddComponent<ObjSelectCtrl>();
parentObj.AddComponent<ObjDelete>();
}
private void SetBaseGameObjectData(GameObject obj, RecordCurtainLineParent data)
{
obj.name = data.objectName;
obj.transform.localRotation = data.myTransform.getMyRotation();
obj.transform.localPosition = data.myTransform.getMyPosition();
obj.transform.localScale = data.myTransform.getMyScale();
SelectedObjs.gameObjs.Add(obj);
CloneGameObjInfo objMsg = obj.GetComponent<CloneGameObjInfo>();
objMsg.gameObjType = data.gameObjType;
objMsg.buildNum = data.buildNum;
objMsg.floorNum = data.floorNum;
objMsg.interlayerNum = data.interlayerNum;
obj.SetActive(data.isActive);
}
/// <summary>
/// 回放事件:克隆子物体
/// </summary>
/// <param name="data"></param>
private void ReplayEventCloneChild(RecordCurtainLineChild data)
{
Transform parent = transform.Find(data.objectName);
var clonedChild = Instantiate(cloneCurtainLine.clonePrefab, parent);
clonedChild.transform.localPosition = data.myTransform.getMyPosition();
clonedChild.name = data.objectName;
clonedChild.transform.localRotation = data.myTransform.getMyRotation();
clonedChild.transform.localScale = data.myTransform.getMyScale();
CurtainLineItem objMsg = clonedChild.GetComponent<CurtainLineItem>();
objMsg.gameObjID = parent.GetComponent<CloneGameObjInfo>().gameObjID;
objMsg.gameObjType = data.gameObjType;
objMsg.buildNum = data.buildNum;
objMsg.floorNum = data.floorNum;
objMsg.interlayerNum = data.interlayerNum;
objMsg.prePos = data.prePos;
objMsg.curPos = data.curPos;
CreateCurtain(objMsg.prePos, objMsg.curPos,parent);
SelectedObjs.gameObjs.Add(clonedChild);
}
/// <summary>
/// 回放状态
/// </summary>
/// <param name="jsonData"></param>
protected void ReplayFrame(RecordCurtainLineParent jsonData)
{
var parentObj = EntitiesManager.Instance.CreateObj(cloneCurtainLine.parentPrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName));
parentObj.name = jsonData.objectName;//名字即ID
SetBaseGameObject(parentObj, jsonData);
parentObj.AddComponent<WaterCurtainAttribute>();
parentObj.AddComponent<ObjSelectCtrl>();
parentObj.AddComponent<ObjDelete>();
//生成子物体
var list = jsonData.list;
foreach (RecordCurtainLineChild childData in list)
{
var clonedChild = Instantiate(cloneCurtainLine.clonePrefab, parentObj.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);
CurtainLineItem objMsg = clonedChild.GetComponent<CurtainLineItem>();
objMsg.gameObjID = parentObj.GetComponent<CloneGameObjInfo>().gameObjID;
objMsg.gameObjType = childData.gameObjType;
objMsg.buildNum = childData.buildNum;
objMsg.floorNum = childData.floorNum;
objMsg.interlayerNum = childData.interlayerNum;
objMsg.prePos = childData.prePos;
objMsg.curPos = childData.curPos;
CreateCurtain(objMsg.prePos, objMsg.curPos, parentObj.transform); //生成该段水幕
}
parentObj.GetComponent<WaterCurtainAttribute>().ReplayTask(jsonData.task);
}
/// <summary>
/// 生成水幕
/// </summary>
/// <param name="prePos"></param>
/// <param name="curPos"></param>
private void CreateCurtain(Vector3 prePos, Vector3 curPos, Transform parent)
{
Vector3 vertPos;
var Distance = Vector3.Distance(prePos, curPos);
float pos = Mathf.CeilToInt(Distance);
float count = Mathf.CeilToInt(pos / 2);
int dex = 1;
if (count < 1)
{
count = 1;
dex = 0;
}
for (int i = 0; i < count + dex; i++)
{
if (count > 1)
{
if (i != 0)
{
vertPos = new Vector3(prePos.x + (i / (float)count) * (curPos.x - prePos.x), prePos.y + (i / (float)count) * (curPos.y - prePos.y) + 0.6f, prePos.z + (i / (float)count) * (curPos.z - prePos.z));
GameObject curtain = Instantiate(cloneCurtainLine.curtainPrefab, vertPos, Quaternion.identity) as GameObject;
curtain.transform.parent = parent;
curtain.transform.forward = -Vector3.up;
curtain.name = "Curtain-" + parent.name;
var curtainCtrl = curtain.AddComponent<WaterCurtainControl>();
curtainCtrl.gameObjID = parent.GetComponent<CloneGameObjInfo>().gameObjID;
CloneGameObjInfo floorMsg = parent.GetComponent<CloneGameObjInfo>();
curtainCtrl.buildNum = floorMsg.buildNum;
curtainCtrl.floorNum = floorMsg.floorNum;
curtainCtrl.interlayerNum = floorMsg.interlayerNum;
}
}
}
}
}