|
|
|
@ -63,41 +63,41 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
private void ExecuteEvent(IMessage obj) |
|
|
|
|
{ |
|
|
|
|
var eventData = (EventData)obj.Data; |
|
|
|
|
if(eventData.cloneObjType == CloneObjType.SetArea) |
|
|
|
|
if (eventData.cloneObjType == CloneObjType.SetArea) |
|
|
|
|
{ |
|
|
|
|
if (eventData.eventType == RecordEventType.ToolTask) |
|
|
|
|
{ |
|
|
|
|
var arg = JsonUtility.FromJson<RecordSetArea>(eventData.json); |
|
|
|
|
var arg = Newtonsoft.Json.JsonConvert.DeserializeObject<RecordSetArea>(eventData.json); |
|
|
|
|
if (arg.objectName == gameObject.name) |
|
|
|
|
{ |
|
|
|
|
SetPolygon(arg.hitPos, arg.mousePos); |
|
|
|
|
SetPolygon(arg.hitPos, arg.mousePos, arg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (eventData.eventType == RecordEventType.SetAreaChange) |
|
|
|
|
{ |
|
|
|
|
var arg = JsonUtility.FromJson<RecordSetAreaChange>(eventData.json); |
|
|
|
|
var arg = Newtonsoft.Json.JsonConvert.DeserializeObject<RecordSetAreaChange>(eventData.json); |
|
|
|
|
if (arg.objectName == gameObject.name) |
|
|
|
|
{ |
|
|
|
|
ReplayChangePosition(arg.index, arg.position, arg.mousePosition); |
|
|
|
|
ReplayChangePosition(arg.index, arg.position, arg.point, arg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if(eventData.eventType == RecordEventType.SetAreaAdd) |
|
|
|
|
else if (eventData.eventType == RecordEventType.SetAreaAdd) |
|
|
|
|
{ |
|
|
|
|
var arg = JsonUtility.FromJson<RecordSetAreaAdd>(eventData.json); |
|
|
|
|
var arg = Newtonsoft.Json.JsonConvert.DeserializeObject<RecordSetAreaAdd>(eventData.json); |
|
|
|
|
if (arg.objectName == gameObject.name) |
|
|
|
|
{ |
|
|
|
|
AddPolygon(arg.addIndex, arg.hitPos,arg.MousePos); |
|
|
|
|
AddPolygon(arg.addIndex, arg.hitPos, arg.MousePos, arg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (eventData.eventType == RecordEventType.SetAreaDel) |
|
|
|
|
{ |
|
|
|
|
var arg = JsonUtility.FromJson<RecordSetAreaDel>(eventData.json); |
|
|
|
|
var arg = Newtonsoft.Json.JsonConvert.DeserializeObject<RecordSetAreaDel>(eventData.json); |
|
|
|
|
if (arg.objectName == gameObject.name) |
|
|
|
|
{ |
|
|
|
|
DelPolygon(arg.delIndex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void Start() |
|
|
|
@ -215,6 +215,74 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public void SetPolygon(Vector3 hitPos, Vector3 MousePos, RecordSetArea arg, float offset = 1) |
|
|
|
|
{ |
|
|
|
|
var position = MousePos; |
|
|
|
|
|
|
|
|
|
var index = FindIndex(position); |
|
|
|
|
|
|
|
|
|
if (index == -1) |
|
|
|
|
{ |
|
|
|
|
HeightOffset = new Vector3(0, offset, 0); |
|
|
|
|
var worldPos = hitPos + HeightOffset; |
|
|
|
|
if (worldPositions.Count > 0) |
|
|
|
|
worldPos.Set(worldPos.x, GetHeight(), worldPos.z); |
|
|
|
|
var screenPos = position; |
|
|
|
|
|
|
|
|
|
if (worldPositions.Count == 0) |
|
|
|
|
{ |
|
|
|
|
MessageDispatcher.SendMessage(1f, "NodeTreeHints", (object)"在此区域设置"); |
|
|
|
|
} |
|
|
|
|
screenPositions.Add(screenPos); |
|
|
|
|
worldPositions.Add(worldPos); |
|
|
|
|
|
|
|
|
|
if (worldPositions.Count == 3) |
|
|
|
|
{ |
|
|
|
|
var s = Info.gameObject.AddComponent<CloneGameObjInfo>(); |
|
|
|
|
s.buildNum = GetComponent<CloneGameObjInfo>().buildNum; |
|
|
|
|
s.gameObjType = GetComponent<CloneGameObjInfo>().gameObjType; |
|
|
|
|
s.floorNum = GetComponent<CloneGameObjInfo>().floorNum; |
|
|
|
|
s.interlayerNum = GetComponent<CloneGameObjInfo>().interlayerNum; |
|
|
|
|
//s.deltaFloor = GetComponent<CloneGameObjInfo>().deltaFloor; |
|
|
|
|
//Info.position = worldPositions[0] + new Vector3(0, 1f, 0); |
|
|
|
|
Info.gameObject.SetActive(true); |
|
|
|
|
} |
|
|
|
|
//FIXME: 时间紧迫,将来这里可能需要解耦 |
|
|
|
|
var go = Instantiate(VerticePrefab); |
|
|
|
|
var rectTransform = go.GetComponent<RectTransform>(); |
|
|
|
|
// var polyVerticeFather = Canvas.transform.Find("PolyVerticeFather"); |
|
|
|
|
rectTransform.parent = PolyVerticeFather; |
|
|
|
|
rectTransform.localScale = Vector3.one; |
|
|
|
|
var script = go.GetComponent<DragVertice>(); |
|
|
|
|
script.PolygonController = this; |
|
|
|
|
script.Canvas = Canvas; |
|
|
|
|
vertices.Add(go); |
|
|
|
|
Vector3 nowcamerapos = Camera.main.transform.position; |
|
|
|
|
Quaternion nowrotate = Camera.main.transform.rotation; |
|
|
|
|
Camera.main.transform.localPosition = arg.myTransform.getMyPosition(); |
|
|
|
|
Camera.main.transform.localRotation = arg.myTransform.getMyRotation(); |
|
|
|
|
//go.name = GetComponent<CloneGameObjInfo>().gameObjID.ToString() +"-"+ vertices.IndexOf(go).ToString(); |
|
|
|
|
if (Canvas.renderMode == RenderMode.ScreenSpaceOverlay) |
|
|
|
|
{ |
|
|
|
|
Vector2 anchoredPos; |
|
|
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(PolyVerticeFather, screenPos, null, out anchoredPos)) |
|
|
|
|
rectTransform.anchoredPosition = anchoredPos; |
|
|
|
|
} |
|
|
|
|
else if (Canvas.renderMode == RenderMode.ScreenSpaceCamera) |
|
|
|
|
{ |
|
|
|
|
Vector2 mousePos; |
|
|
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(PolyVerticeFather, screenPos, Canvas.worldCamera, out mousePos)) |
|
|
|
|
rectTransform.anchoredPosition = mousePos; |
|
|
|
|
} |
|
|
|
|
if (worldPositions.Count > 2) |
|
|
|
|
{ |
|
|
|
|
polygon.SetVertices(worldPositions.ToArray()); |
|
|
|
|
Info.position = polygon.getCenterOfGravityPoint(worldPositions) + InfoOffset; |
|
|
|
|
} |
|
|
|
|
Camera.main.transform.position = nowcamerapos; |
|
|
|
|
Camera.main.transform.rotation = nowrotate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
|
/// 回放帧状态 |
|
|
|
|
/// </summary> |
|
|
|
@ -338,6 +406,75 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
} |
|
|
|
|
AddRecordAdd(addIndex, hitPos, MousePos); |
|
|
|
|
} |
|
|
|
|
public void AddPolygon(int addIndex, Vector3 hitPos, Vector3 MousePos, RecordSetAreaAdd arg) |
|
|
|
|
{ |
|
|
|
|
var position = MousePos; |
|
|
|
|
|
|
|
|
|
var index = FindIndex(position); |
|
|
|
|
|
|
|
|
|
if (index == -1) |
|
|
|
|
{ |
|
|
|
|
var worldPos = hitPos + HeightOffset; |
|
|
|
|
if (worldPositions.Count > 0) |
|
|
|
|
worldPos.Set(worldPos.x, GetHeight(), worldPos.z); |
|
|
|
|
var screenPos = position; |
|
|
|
|
|
|
|
|
|
if (worldPositions.Count == 0) |
|
|
|
|
{ |
|
|
|
|
MessageDispatcher.SendMessage(1f, "NodeTreeHints", (object)"在此区域设置"); |
|
|
|
|
} |
|
|
|
|
screenPositions.Insert(addIndex, screenPos); |
|
|
|
|
worldPositions.Insert(addIndex, worldPos); |
|
|
|
|
|
|
|
|
|
if (worldPositions.Count == 3) |
|
|
|
|
{ |
|
|
|
|
var s = Info.gameObject.AddComponent<CloneGameObjInfo>(); |
|
|
|
|
s.buildNum = GetComponent<CloneGameObjInfo>().buildNum; |
|
|
|
|
s.gameObjType = GetComponent<CloneGameObjInfo>().gameObjType; |
|
|
|
|
s.floorNum = GetComponent<CloneGameObjInfo>().floorNum; |
|
|
|
|
s.interlayerNum = GetComponent<CloneGameObjInfo>().interlayerNum; |
|
|
|
|
|
|
|
|
|
//s.deltaFloor = GetComponent<CloneGameObjInfo>().deltaFloor; |
|
|
|
|
//Info.position = worldPositions[0] + new Vector3(0, 1f, 0); |
|
|
|
|
Info.gameObject.SetActive(true); |
|
|
|
|
} |
|
|
|
|
//FIXME: 时间紧迫,将来这里可能需要解耦 |
|
|
|
|
var go = Instantiate(VerticePrefab); |
|
|
|
|
var rectTransform = go.GetComponent<RectTransform>(); |
|
|
|
|
// var polyVerticeFather = Canvas.transform.Find("PolyVerticeFather"); |
|
|
|
|
rectTransform.SetParent(PolyVerticeFather); |
|
|
|
|
rectTransform.localScale = Vector3.one; |
|
|
|
|
var script = go.GetComponent<DragVertice>(); |
|
|
|
|
script.PolygonController = this; |
|
|
|
|
script.Canvas = Canvas; |
|
|
|
|
vertices.Insert(addIndex, go); |
|
|
|
|
Vector3 nowcamerapos = Camera.main.transform.position; |
|
|
|
|
Quaternion nowrotate = Camera.main.transform.rotation; |
|
|
|
|
Camera.main.transform.localPosition = arg.myTransform.getMyPosition(); |
|
|
|
|
Camera.main.transform.localRotation = arg.myTransform.getMyRotation(); |
|
|
|
|
if (Canvas.renderMode == RenderMode.ScreenSpaceOverlay) |
|
|
|
|
{ |
|
|
|
|
Vector2 anchoredPos; |
|
|
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(PolyVerticeFather, screenPos, null, out anchoredPos)) |
|
|
|
|
rectTransform.anchoredPosition = anchoredPos; |
|
|
|
|
} |
|
|
|
|
else if (Canvas.renderMode == RenderMode.ScreenSpaceCamera) |
|
|
|
|
{ |
|
|
|
|
Vector2 mousePos; |
|
|
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(PolyVerticeFather, screenPos, Canvas.worldCamera, out mousePos)) |
|
|
|
|
rectTransform.anchoredPosition = mousePos; |
|
|
|
|
} |
|
|
|
|
if (worldPositions.Count > 2) |
|
|
|
|
{ |
|
|
|
|
polygon.SetVertices(worldPositions.ToArray()); |
|
|
|
|
Info.position = polygon.getCenterOfGravityPoint(worldPositions) + InfoOffset; |
|
|
|
|
} |
|
|
|
|
Camera.main.transform.position = nowcamerapos; |
|
|
|
|
Camera.main.transform.rotation = nowrotate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AddRecordAdd(addIndex, hitPos, MousePos); |
|
|
|
|
} |
|
|
|
|
public void AddRecordAdd(int addIndex, Vector3 hitPos, Vector3 MousePos) |
|
|
|
|
{ |
|
|
|
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) |
|
|
|
@ -352,7 +489,9 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
data.addIndex = addIndex; |
|
|
|
|
data.hitPos = hitPos; |
|
|
|
|
data.MousePos = MousePos; |
|
|
|
|
string json = JsonUtility.ToJson(data); |
|
|
|
|
data.myTransform.setMyPosition(Camera.main.transform.localPosition); |
|
|
|
|
data.myTransform.setMyRotation(Camera.main.transform.localRotation); |
|
|
|
|
string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); |
|
|
|
|
eventData.json = json; |
|
|
|
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
|
|
|
} |
|
|
|
@ -382,8 +521,8 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
var data = new RecordSetAreaDel(); |
|
|
|
|
data.gameObjType = CloneObjType.SetArea; |
|
|
|
|
data.objectName = gameObject.gameObject.name; |
|
|
|
|
data.delIndex = delIndex; |
|
|
|
|
string json = JsonUtility.ToJson(data); |
|
|
|
|
data.delIndex = delIndex; |
|
|
|
|
string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); |
|
|
|
|
eventData.json = json; |
|
|
|
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
|
|
|
} |
|
|
|
@ -413,13 +552,13 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
/// 改变多边形顶点位置,按照屏幕坐标来计算。 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <returns>如果可以改变,返回 true;否则返回 false</returns> |
|
|
|
|
public bool ChangePosition(int index, Vector3 position) |
|
|
|
|
public bool ChangePosition(int index, Vector3 position, bool record = false) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
//Ray ray = Camera.main.ScreenPointToRay(position); |
|
|
|
|
Plane plane = new Plane(Vector3.up, worldPositions[index]); |
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); |
|
|
|
|
AddRecordChangePosition(index, position, Input.mousePosition); |
|
|
|
|
// AddRecordChangePosition(index, position, Input.mousePosition); |
|
|
|
|
//RaycastHit hit; |
|
|
|
|
//int ignoreRaycast = LayerMask.NameToLayer("Ignore Raycast"); |
|
|
|
|
//bool a = Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << ignoreRaycast)); |
|
|
|
@ -437,6 +576,10 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
polygon.SetVertices(worldPositions.ToArray()); |
|
|
|
|
Info.position = polygon.getCenterOfGravityPoint(worldPositions) + InfoOffset; |
|
|
|
|
} |
|
|
|
|
if (record) |
|
|
|
|
{ |
|
|
|
|
AddRecordChangePosition(index, position, point); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -444,27 +587,15 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public bool ReplayChangePosition(int index, Vector3 position,Vector3 mousePosition) |
|
|
|
|
{ |
|
|
|
|
Plane plane = new Plane(Vector3.up, worldPositions[index]); |
|
|
|
|
Ray ray = Camera.main.ScreenPointToRay(mousePosition); |
|
|
|
|
float enter; |
|
|
|
|
if (plane.Raycast(ray, out enter)) |
|
|
|
|
{ |
|
|
|
|
var point = ray.GetPoint(enter); |
|
|
|
|
screenPositions[index] = position; |
|
|
|
|
worldPositions[index] = new Vector3(point.x, worldPositions[index].y, point.z); |
|
|
|
|
public void ReplayChangePosition(int index, Vector3 position, Vector3 mousePosition, RecordSetAreaChange arg) |
|
|
|
|
{ |
|
|
|
|
screenPositions[index] = position; |
|
|
|
|
worldPositions[index] = new Vector3(arg.point.x, worldPositions[index].y, arg.point.z); |
|
|
|
|
|
|
|
|
|
if (worldPositions.Count > 2) |
|
|
|
|
{ |
|
|
|
|
polygon.SetVertices(worldPositions.ToArray()); |
|
|
|
|
Info.position = polygon.getCenterOfGravityPoint(worldPositions) + InfoOffset; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
if (worldPositions.Count > 2) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
polygon.SetVertices(worldPositions.ToArray()); |
|
|
|
|
Info.position = polygon.getCenterOfGravityPoint(worldPositions) + InfoOffset; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
@ -472,7 +603,7 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="index"></param> |
|
|
|
|
/// <param name="position"></param> |
|
|
|
|
public void AddRecordChangePosition(int index, Vector3 position,Vector3 mousePosition) |
|
|
|
|
public void AddRecordChangePosition(int index, Vector3 position,Vector3 point) |
|
|
|
|
{ |
|
|
|
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) |
|
|
|
|
{ |
|
|
|
@ -485,8 +616,8 @@ public class PolygonController : MonoBehaviour
|
|
|
|
|
data.objectName = gameObject.gameObject.name; |
|
|
|
|
data.index = index; |
|
|
|
|
data.position = position; |
|
|
|
|
data.mousePosition = mousePosition; |
|
|
|
|
string json = JsonUtility.ToJson(data); |
|
|
|
|
data.point = point; |
|
|
|
|
string json = Newtonsoft.Json.JsonConvert.SerializeObject(data); |
|
|
|
|
eventData.json = json; |
|
|
|
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
|
|
|
} |
|
|
|
|