using AX.InputSystem; using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// ///克隆单一物体 /// [DisallowMultipleComponent] public class CloneSingleObj : CloneBase { [SerializeField] [Tooltip("距离地面距离")] protected float Height = 0; protected long gameObjID; protected CloneCmdArgs data; protected GameObject clonedObj; public override void Execute(IMessage obj) { gameObjID = (long)obj.Sender; data = ((CloneCmdArgs)obj.Data); if (data.cloneObjType == cloneObjType) { Clone(); } } protected virtual void Clone() { var hitPoint = data.hitPos; Vector3 clonedObjPos = new Vector3(hitPoint.x, hitPoint.y + Height, hitPoint.z); clonedObj = EntitiesManager.Instance.CreateObj(clonePrefab, clonedObjPos, transform, gameObjID); clonedObj.name = gameObjID.ToString();//名字即ID //clonedObj.name = CloneObjectTool.Instance().getCloneObjectName(cloneObjType); ////有需要的类型赋值头顶名 //string topname = CloneObjName.Instance.GetCloneNameByType(cloneObjType); SelectedObjs.gameObjs.Add(clonedObj); //设置克隆物体所在楼层属性,属性从点击的对象上获取 var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID); number++; CloneGameObjInfo objMsg = clonedObj.GetComponent(); objMsg.gameObjType = cloneObjType; if (hitObj.GetComponent()) { CloneGameObjInfo floorMsg = hitObj.GetComponent(); objMsg.buildNum = floorMsg.buildNum; objMsg.floorNum = floorMsg.floorNum; objMsg.interlayerNum = floorMsg.interlayerNum; } SetCloneGameObject(clonedObj); AddRecordEventClone(clonedObj.transform);//测试 } public virtual void SetCloneGameObject(GameObject obj) { obj.AddComponent(); obj.AddComponent(); obj.AddComponent(); } /// /// 添加初始状态记录 /// /// public override void AddRecordFrame(List list) { foreach (Transform child in transform) { var data = new RecordObjectBase(); SetBaseData(data, child); string json = JsonUtility.ToJson(data); var objectJson = new ObjectData(); objectJson.cloneObjType = cloneObjType; objectJson.json = json; list.Add(objectJson); } } public void SetBaseData(RecordObjectBase data, Transform obj) { var msg = obj.GetComponent(); data.gameObjType = msg.gameObjType; data.objectName = obj.gameObject.name; data.buildNum = msg.buildNum; data.floorNum = msg.floorNum; data.interlayerNum = msg.interlayerNum; data.myTransform.setMyPosition(obj.localPosition); data.myTransform.setMyRotation(obj.localRotation); data.myTransform.setMyScale(obj.localScale); data.isActive = obj.gameObject.activeSelf; if (obj.GetComponent()) { data.IsSelect= obj.GetComponent().selected; } } /// /// 添加记录(克隆) /// public override void AddRecordEventClone(Transform obj) { if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) { var eventData = new EventData(); eventData.time = RecordManager.Instance.RecordTimer; eventData.cloneObjType = cloneObjType; eventData.eventType = RecordEventType.Clone; var data = new RecordObjectBase(); SetBaseData(data, obj); string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } public override void AddRecordTag(List list) { } }