using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReplaySimpleObject : ReplayBase { /// <summary> /// 回放克隆 /// </summary> /// <param name="json"></param> public override void CloneObject(string json) { var jsonData = JsonUtility.FromJson<RecordObjectBase>(json); var clonedObj = EntitiesManager.Instance.CreateObj(cloneBase.clonePrefab, jsonData.myTransform.getMyPosition(), transform, long.Parse(jsonData.objectName)); clonedObj.name = jsonData.objectName;//名字即ID SetBaseGameObject(clonedObj, jsonData); SetCloneGameObject(clonedObj, json); if (clonedObj.GetComponent<ObjSelectCtrl>()) { clonedObj.GetComponent<ObjSelectCtrl>().SetSelect(json); } } /// <summary> /// 设置基本属性 /// </summary> /// <param name="clonedObj"></param> /// <param name="jsonData"></param> public void SetBaseGameObject(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.gameObjType = jsonData.gameObjType; objMsg.buildNum = jsonData.buildNum; objMsg.floorNum = jsonData.floorNum; objMsg.interlayerNum = jsonData.interlayerNum; clonedObj.SetActive(jsonData.isActive); } /// <summary> /// 设置特殊属性 /// </summary> /// <param name="obj"></param> public virtual void SetCloneGameObject(GameObject obj, string json) { obj.AddComponent<ObjSelectCtrl>(); obj.AddComponent<ObjDrag>(); obj.AddComponent<ObjDelete>(); } }