using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReplayWaterLine : ReplayMultiLine { /// /// 回放克隆 /// /// public override void CloneObject(string json) { var jsonData = JsonUtility.FromJson(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(); objMsg.gameObjID = parent.GetComponent().gameObjID; objMsg.gameObjType = jsonData.gameObjType; objMsg.buildNum = jsonData.buildNum; objMsg.floorNum = jsonData.floorNum; objMsg.interlayerNum = jsonData.interlayerNum; SetCloneGameObject(clonedChild, ""); //设置水源信息 var waterLineInfo = parent.GetComponent(); 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.state = ConnectState.none; waterLineInfo.SupplierID = jsonData.supplierID; waterLineInfo.ReceiverID = jsonData.receiverID; } } /// /// 回放状态 /// /// 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.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(); objMsg.gameObjID = clonedObj.GetComponent().gameObjID; objMsg.gameObjType = childData.gameObjType; objMsg.buildNum = childData.buildNum; objMsg.floorNum = childData.floorNum; objMsg.interlayerNum = childData.interlayerNum; SetCloneGameObject(clonedChild, ""); } } /// /// 设置基本属性 /// /// /// 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(); 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(); } }