using System.Collections; using System.Collections.Generic; using AX.InputSystem; using AX.MessageSystem; using UnityEngine; public class CloneSetArea : CloneBase { //public Transform PolyVerticeFather; public override void Awake() { cloneObjType = CloneObjType.SetArea; ResourcesName = "Prefab/Tool/SetArea"; MessageDispatcher.AddListener("DrewEnd", DrewEnd); //PolyVerticeFather = GameObject.Find("Canvas/SetAreaPanel/PolyVerticeFather").transform; base.Awake(); } private void DrewEnd(IMessage obj) { var clonetype = (CloneObjType)obj.Data; if (clonetype == cloneObjType) { var game = EntitiesManager.Instance.GetEntityByID(GameobjID); if (!game) { return; } if (game.GetComponent()) if (game.GetComponent().worldPositions.Count < 3) { EntitiesManager.Instance.DeleteObj(game); } } } [SerializeField] [Tooltip("距离地面距离")] private float Height = 0; /// /// 是否正在设置区域 /// public static bool isSetArea; public long GameobjID; public override void Execute(IMessage obj) { var gameObjID = (long)obj.Sender; var data = ((CloneCmdArgs)obj.Data); if (data.cloneObjType == cloneObjType) { GameObject PolygonPlane = GameObject.Find("Canvas/SetAreaPanel/PolygonPlaneBase").gameObject; GameObject PolygonPlaneChild = PolygonPlane.transform.Find("Plane").gameObject; var hitPoint = data.hitPos; Vector3 clonedObjPos = new Vector3(hitPoint.x, hitPoint.y + Height, hitPoint.z); if (PolygonPlaneChild.activeInHierarchy) { var hitObj = EntitiesManager.Instance.GetEntityByID(GameobjID); //执行点击事件 hitObj.GetComponent().SetPolygon(hitPoint, data.mousePosition); AddRecordDrawEventClone(hitObj.transform, hitPoint, data.mousePosition); } else { GameobjID = 0; PolygonPlaneChild.SetActive(true); PolygonPlaneChild.transform.position = new Vector3(hitPoint.x, hitPoint.y + 0.1f, hitPoint.z); var clonedObj = EntitiesManager.Instance.CreateObj(clonePrefab, clonedObjPos, transform, gameObjID); clonedObj.transform.position = Vector3.zero; //clonedObj.name = cloneObjType.ToString() + number++; clonedObj.name = gameObjID.ToString(); //以ID命名 clonedObj.GetComponent().material.color = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, 1f); // clonedObj.GetComponent().Info(); clonedObj.GetComponent().PolyVerticeFather = GameObject.Find("Canvas/SetAreaPanel/PolyVerticeFather").GetComponent(); var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID); 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; } SelectedObjs.gameObjs.Add(clonedObj); GameobjID = gameObjID; AddRecordEventClone(clonedObj.transform); //记录克隆第一步 } } } /// /// 添加初始状态记录 /// /// public override void AddRecordFrame(List list) { foreach (Transform child in transform) { var data = new RecordSetArea(); SetBaseData(data, child); data.isEvent = false; var polyController = child.GetComponent(); DeepCopy(polyController.worldPositions, data.worldPositions); DeepCopy(polyController.screenPositions, data.screenPositions); var setArea = child.GetComponent(); data.color = setArea.Color; data.height = setArea.High; data.areName = setArea.Name; string json = JsonUtility.ToJson(data); var objectJson = new ObjectData(); objectJson.cloneObjType = cloneObjType; objectJson.json = json; list.Add(objectJson); } } private void DeepCopy(List source, List target) { foreach (Vector3 v in source) { target.Add(v); } } 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; } /// /// 添加记录(克隆) /// 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 RecordSetArea(); SetBaseData(data, obj); data.isEvent = true; string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void AddRecordDrawEventClone(Transform obj, Vector3 hitPos, Vector3 mousePos) { 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.ToolTask; var data = new RecordSetArea(); SetBaseData(data, obj); data.hitPos = hitPos; data.mousePos = mousePos; data.isEvent = true; string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } public override void AddRecordTag(List list) { } }