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.
179 lines
7.1 KiB
179 lines
7.1 KiB
4 years ago
|
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<PolygonController>())
|
||
|
if (game.GetComponent<PolygonController>().worldPositions.Count < 3)
|
||
|
{
|
||
|
EntitiesManager.Instance.DeleteObj(game);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
[SerializeField]
|
||
|
[Tooltip("距离地面距离")]
|
||
|
private float Height = 0;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 是否正在设置区域
|
||
|
/// </summary>
|
||
|
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<PolygonController>().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<MeshRenderer>().material.color = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, 1f);
|
||
|
// clonedObj.GetComponent<CloneGameObjInfo>().Info();
|
||
|
clonedObj.GetComponent<PolygonController>().PolyVerticeFather = GameObject.Find("Canvas/SetAreaPanel/PolyVerticeFather").GetComponent<RectTransform>();
|
||
|
|
||
|
var hitObj = EntitiesManager.Instance.GetEntityByID(data.gameObjID);
|
||
|
CloneGameObjInfo objMsg = clonedObj.GetComponent<CloneGameObjInfo>();
|
||
|
objMsg.gameObjType = cloneObjType;
|
||
|
if (hitObj.GetComponent<CloneGameObjInfo>())
|
||
|
{
|
||
|
CloneGameObjInfo floorMsg = hitObj.GetComponent<CloneGameObjInfo>();
|
||
|
objMsg.buildNum = floorMsg.buildNum;
|
||
|
objMsg.floorNum = floorMsg.floorNum;
|
||
|
objMsg.interlayerNum = floorMsg.interlayerNum;
|
||
|
}
|
||
|
|
||
|
SelectedObjs.gameObjs.Add(clonedObj);
|
||
|
GameobjID = gameObjID;
|
||
|
AddRecordEventClone(clonedObj.transform); //记录克隆第一步
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 添加初始状态记录
|
||
|
/// </summary>
|
||
|
/// <param name="list"></param>
|
||
|
public override void AddRecordFrame(List<ObjectData> list)
|
||
|
{
|
||
|
foreach (Transform child in transform)
|
||
|
{
|
||
|
var data = new RecordSetArea();
|
||
|
SetBaseData(data, child);
|
||
|
data.isEvent = false;
|
||
|
var polyController = child.GetComponent<PolygonController>();
|
||
|
DeepCopy(polyController.worldPositions, data.worldPositions);
|
||
|
DeepCopy(polyController.screenPositions, data.screenPositions);
|
||
|
var setArea = child.GetComponent<SetArea>();
|
||
|
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<Vector3> source, List<Vector3> target)
|
||
|
{
|
||
|
foreach (Vector3 v in source)
|
||
|
{
|
||
|
target.Add(v);
|
||
|
}
|
||
|
}
|
||
|
public void SetBaseData(RecordObjectBase data, Transform obj)
|
||
|
{
|
||
|
var msg = obj.GetComponent<CloneGameObjInfo>();
|
||
|
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;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 添加记录(克隆)
|
||
|
/// </summary>
|
||
|
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<ObjectData> list)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|