Browse Source

修改设置区域跟火蔓延的记录回访。

添加标签,点击文字内容是报错修改
develop
曹衍涛 4 years ago
parent
commit
b420e84c58
  1. BIN
      Assets/Prefab/P_AllParent.prefab
  2. BIN
      Assets/Scene/MainScene_New.unity
  3. 43
      Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs
  4. 79
      Assets/Scripts/DisasterSetting/SpreadFire.cs
  5. 135
      Assets/Scripts/DisasterSetting/SpreadFireManager.cs
  6. 11
      Assets/Scripts/DisasterSetting/SpreadFireManager.cs.meta
  7. 1
      Assets/Scripts/HelpScripts/CloneObjType.cs
  8. 2
      Assets/Scripts/InputSystem/InputManager/InputManager.cs
  9. 5
      Assets/Scripts/Replay/JsonObject.cs
  10. 4
      Assets/Scripts/Replay/NodeDetailShow.cs
  11. 7
      Assets/Scripts/Tool/InstanceText/TextControl.cs
  12. 2
      Assets/Scripts/Tool/RecordSetArea.cs
  13. 72
      Assets/Scripts/Tool/SetArea/DragVertice.cs
  14. 2
      Assets/Scripts/Tool/SetArea/Polygon.cs
  15. 205
      Assets/Scripts/Tool/SetArea/PolygonController.cs
  16. 6
      Assets/Scripts/Tool/SetArea/SetArea.cs

BIN
Assets/Prefab/P_AllParent.prefab

Binary file not shown.

BIN
Assets/Scene/MainScene_New.unity

Binary file not shown.

43
Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs

@ -1,9 +1,16 @@
using AX.MessageSystem;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SpreadEndData//蔓延结束
{
public long gameObjectId;
}
[Serializable]
public class FireSpreadData : RecordObjectBase
{
@ -173,6 +180,21 @@ public class FireSpreadCtrl : MonoBehaviour
GetSpreadFirePositions();
StartCoroutine(WaitForStart(data.time));
}
public void AddSpreadEndRecordData()
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
SpreadEndData data = new SpreadEndData();
data.gameObjectId = GetComponent<BaseGameObjInfo>().gameObjID;
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = CloneObjType.None;
eventData.eventType = RecordEventType.FireSpreadEnd;
eventData.json = JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
public IEnumerator WaitForStart(float time)
{
yield return new WaitForSeconds(time * 60 / ReplayManager.playSpeed);
@ -193,6 +215,7 @@ public class FireSpreadCtrl : MonoBehaviour
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
//
private void CtrlFireSpread()
{
if (fire == null)
@ -203,6 +226,12 @@ public class FireSpreadCtrl : MonoBehaviour
{
if (straightSpread)
{
if (spreadFirePositions.Count == 0)
{
CancelInvoke("CtrlFireSpread");
isSpreading = false;
ResourceLoadWindow.Instance.LoadTextHintWindow("路径过窄请重新规划!", 3f);
}
if (index < spreadFirePositions.Count)
{
GameObject spreadFire = Instantiate(fire, spreadFirePositions[index++], Quaternion.identity,
@ -210,11 +239,13 @@ public class FireSpreadCtrl : MonoBehaviour
var spreadedFire = spreadFire.GetComponent<SpreadFire>();
spreadedFire.SourceId = GetComponent<CloneGameObjInfo>().GameObjID;
spreadFire.name = "straightSpread" + (index - 1);
AddRecordEventSpreadFire(gameObject, GetSpreadData());
spreadedFire.AddRecordDataCreat(gameObject);
// AddRecordEventSpreadFire(gameObject, GetSpreadData());
if (index == spreadFirePositions.Count)
{
CancelInvoke("CtrlFireSpread");
isSpreading = false;
AddSpreadEndRecordData();
ResourceLoadWindow.Instance.LoadTextHintWindow("蔓延已经完成!", 0.5f);
}
}
@ -222,6 +253,12 @@ public class FireSpreadCtrl : MonoBehaviour
if (areaSpread || aroundSpread)
{
if (spdFirePositions.Count == 0)
{
CancelInvoke("CtrlFireSpread");
isSpreading = false;
ResourceLoadWindow.Instance.LoadTextHintWindow("路径过窄请重新规划!", 3f);
}
if (index < spdFirePositions.Count)
{
List<Vector3> tempFirePosList = spdFirePositions[index++];
@ -236,12 +273,14 @@ public class FireSpreadCtrl : MonoBehaviour
spreadFire.name = "areaSpread" + (index - 1);
else
spreadFire.name = "aroundSpread" + (index - 1);
spreadedFire.AddRecordDataCreat(gameObject);
}
AddRecordEventSpreadFire(gameObject, GetSpreadData());
//AddRecordEventSpreadFire(gameObject, GetSpreadData());
if (index == spdFirePositions.Count)
{
CancelInvoke("CtrlFireSpread");
isSpreading = false;
AddSpreadEndRecordData();
ResourceLoadWindow.Instance.LoadTextHintWindow("蔓延已经完成!", 0.5f);
}
}

79
Assets/Scripts/DisasterSetting/SpreadFire.cs

@ -1,8 +1,85 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SpreadFireCreatData //蔓延出来的火的创建
{
public long sourceId;
public string name;
public Vector3 position;//位置
public Vector3 eulerAngles;//旋转
public Vector3 scale;//缩放
public string buildNum;//楼号
public int floorNum;//层号
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
public int Layer;
}
[Serializable]
public class SpreadFireDestoryData//蔓延出来的火的删除
{
public long sourceId;
public string name;
}
public class SpreadFire : CloneGameObjInfo
{
public long SourceId;
public void AddRecordDataCreat(GameObject sourceObj)
{
SourceId = sourceObj.GetComponent<CloneGameObjInfo>().gameObjID;
GetComponent<CloneGameObjInfo>().buildNum = sourceObj.GetComponent<CloneGameObjInfo>().buildNum;//楼号
GetComponent<CloneGameObjInfo>().floorNum = sourceObj.GetComponent<CloneGameObjInfo>().floorNum;//层号
GetComponent<CloneGameObjInfo>().interlayerNum = sourceObj.GetComponent<CloneGameObjInfo>().interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
GetComponent<CloneGameObjInfo>().Layer = sourceObj.GetComponent<CloneGameObjInfo>().Layer;
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
SpreadFireCreatData data = new SpreadFireCreatData();
data.name = gameObject.name;
data.sourceId = SourceId;
data.position = transform.localPosition;
data.eulerAngles = transform.localRotation.eulerAngles;
data.scale = transform.localScale;
data.buildNum = sourceObj.GetComponent<CloneGameObjInfo>().buildNum;//楼号
data.floorNum = sourceObj.GetComponent<CloneGameObjInfo>().floorNum;//层号
data.interlayerNum = sourceObj.GetComponent<CloneGameObjInfo>().interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
data.Layer = sourceObj.GetComponent<CloneGameObjInfo>().Layer;
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = CloneObjType.None;
eventData.eventType = RecordEventType.SpreadFireCreat;
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
//if (sourceObj.layer == LayerMask.NameToLayer("Hidden"))//蔓延出来的火如果主火隐藏
//{
// gameObject.layer = LayerMask.NameToLayer("Hidden");
// foreach (Transform child in transform)
// {
// child.gameObject.layer = LayerMask.NameToLayer("Hidden");
// }
//}
}
public void AddRecordDataDestroy()
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
SpreadFireDestoryData data = new SpreadFireDestoryData();
data.name = gameObject.name;
data.sourceId = SourceId;
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = CloneObjType.None;
eventData.eventType = RecordEventType.SpreadFireDestory;
eventData.json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
}

135
Assets/Scripts/DisasterSetting/SpreadFireManager.cs

@ -0,0 +1,135 @@
using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SpreadFireData
{
public long sourceId;
public string name;
public Vector3 position;//位置
public Vector3 eulerAngles;//旋转
public Vector3 scale;//缩放
public string buildNum;//楼号
public int floorNum;//层号
public int interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
public int Layer;
public string UserId;
}
[Serializable]
public class SpreadFireRecordData//蔓延出来的火的帧数据
{
public List<SpreadFireData> spreadFiredataList = new List<SpreadFireData>();
}
public class SpreadFireManager : MonoBehaviour
{
public static SpreadFireManager Instance;
public GameObject firePrefab;
private void Awake()
{
Instance = this;
}
void Start()
{
MessageDispatcher.AddListener("ReplayFrame", ReplayFrameData);
MessageDispatcher.AddListener("ReplayEvent", ReplayEventData);
}
public SpreadFireRecordData GetFrameData()
{
SpreadFireRecordData recordData = new SpreadFireRecordData();
foreach (Transform item in transform)
{
SpreadFireData data = new SpreadFireData();
data.name = item.name;
data.sourceId = item.GetComponent<SpreadFire>().SourceId;
data.position = item.localPosition;
data.eulerAngles = item.localRotation.eulerAngles;
data.scale = item.localScale;
data.buildNum = item.GetComponent<CloneGameObjInfo>().buildNum;//楼号
data.floorNum = item.GetComponent<CloneGameObjInfo>().floorNum;//层号
data.interlayerNum = item.GetComponent<CloneGameObjInfo>().interlayerNum;//夹层号,0表示不是夹层,1表示第一个夹层
data.Layer = item.GetComponent<CloneGameObjInfo>().Layer;
recordData.spreadFiredataList.Add(data);
}
return recordData;
}
private void ReplayFrameData(IMessage obj)
{
var baseData = (ObjectData)obj.Data;
if (baseData.cloneObjType == CloneObjType.SpreadFireFrame)
{
ClearObject();
SpreadFireRecordData data = Newtonsoft.Json.JsonConvert.DeserializeObject<SpreadFireRecordData>(baseData.json);
if (data.spreadFiredataList.Count > 0)
{
foreach (var item in data.spreadFiredataList)
{
GameObject spreadfire = Instantiate(firePrefab, transform);
spreadfire.name = item.name;
spreadfire.transform.localPosition = item.position;
spreadfire.transform.localRotation = Quaternion.Euler
(item.eulerAngles.x, item.eulerAngles.y, item.eulerAngles.z) * Quaternion.identity;
spreadfire.transform.localScale = item.scale;
spreadfire.GetComponent<SpreadFire>().SourceId = item.sourceId;
spreadfire.GetComponent<CloneGameObjInfo>().buildNum = item.buildNum;
spreadfire.GetComponent<CloneGameObjInfo>().floorNum = item.floorNum;
spreadfire.GetComponent<CloneGameObjInfo>().interlayerNum = item.interlayerNum;
spreadfire.GetComponent<CloneGameObjInfo>().Layer = item.Layer;
}
}
}
}
private void ClearObject()
{
foreach (Transform item in transform)
{
Destroy(item.gameObject);
}
}
private void ReplayEventData(IMessage obj)
{
var baseEventData = (EventData)obj.Data;
if (baseEventData.eventType == RecordEventType.SpreadFireCreat)
{
SpreadFireCreatData data = Newtonsoft.Json.JsonConvert.DeserializeObject<SpreadFireCreatData>(baseEventData.json);
GameObject spreadfire = Instantiate(firePrefab, transform);
spreadfire.name = data.name;
spreadfire.transform.localPosition = data.position;
spreadfire.transform.localRotation = Quaternion.Euler
(data.eulerAngles.x, data.eulerAngles.y, data.eulerAngles.z) * Quaternion.identity;
spreadfire.transform.localScale = data.scale;
spreadfire.GetComponent<SpreadFire>().SourceId = data.sourceId;
spreadfire.GetComponent<CloneGameObjInfo>().buildNum = data.buildNum;
spreadfire.GetComponent<CloneGameObjInfo>().floorNum = data.floorNum;
spreadfire.GetComponent<CloneGameObjInfo>().interlayerNum = data.interlayerNum;
spreadfire.GetComponent<CloneGameObjInfo>().Layer = data.Layer;
}
else if (baseEventData.eventType == RecordEventType.SpreadFireDestory)
{
foreach (Transform item in transform)
{
if (item.GetComponent<SpreadFire>())
{
SpreadFireDestoryData data = (SpreadFireDestoryData)obj.Data;
if (item.GetComponent<SpreadFire>().SourceId == data.sourceId)
{
Destroy(item.gameObject);
}
}
}
}
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventData);
MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameData);
}
}

11
Assets/Scripts/DisasterSetting/SpreadFireManager.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e6684051a4af9c4c98aaf06d09e77d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1
Assets/Scripts/HelpScripts/CloneObjType.cs

@ -480,6 +480,7 @@ public enum CloneObjType
/// </summary>
PowerSupplyCar,
#endregion
SpreadFireFrame,
}
/// <summary>
/// 根据克隆类型获取中文名称。

2
Assets/Scripts/InputSystem/InputManager/InputManager.cs

@ -100,7 +100,7 @@ public class InputManager : MonoBehaviour
{
gameObjID = SelectedObjs.selectedObj.GetComponent<BaseGameObjInfo>().GameObjID;
var cmdargs = new WeightCmdArgs();
cmdargs.Weight += Time.deltaTime * 10f;
cmdargs.Weight += Time.deltaTime *10f;
if (Input.GetButtonDown("LeftShift"))
{
LeftShift = true;

5
Assets/Scripts/Replay/JsonObject.cs

@ -121,7 +121,10 @@ public enum RecordEventType
TruckArmRice = 66,
TruckArmRotation = 67,
Rotate,
SprayRotate
SprayRotate,
SpreadFireCreat,
SpreadFireDestory,
FireSpreadEnd
}
public enum FileType
{

4
Assets/Scripts/Replay/NodeDetailShow.cs

@ -15,7 +15,7 @@ public class NodeDetailShow : MonoBehaviour, IPointerClickHandler
// Use this for initialization
void Start()
{
TagShow = transform.GetComponentInParent<TagManager>().transform.Find("TagShow").GetComponent<TagShow>();
TagShow = GameObject.Find("Canvas/TopUI/TagPanel/TagShow") .GetComponent<TagShow>();
}
// Update is called once per frame
@ -48,7 +48,7 @@ public class NodeDetailShow : MonoBehaviour, IPointerClickHandler
TagShow.tagMessage.SetActive(false);
TagShow.gameObject.SetActive(false);
//gameObject.SetActive(false);
gameObject.SetActive(false);
control = false;
replayManager.Play();
}

7
Assets/Scripts/Tool/InstanceText/TextControl.cs

@ -75,7 +75,7 @@ public class TextControl : MonoBehaviour
{
transform.localScale = new Vector3(value, value, 1);
Scale = value;
AddRecordEventChange(transform);
//AddRecordEventChange(transform);
}
/// <summary>
/// 设置文本
@ -84,16 +84,15 @@ public class TextControl : MonoBehaviour
{
text.text = str;
InputField = str;
AddRecordEventChange(transform);
// AddRecordEventChange(transform);
}
/// <summary>
/// 设置颜色
/// </summary>
public void SetColor(Color value)
{
text.GetComponent<MeshRenderer>().materials[0].color = value;
text.color = value;
Color = value;
AddRecordEventChange(transform);
}
private void LateUpdate()
{

2
Assets/Scripts/Tool/RecordSetArea.cs

@ -18,7 +18,7 @@ public class RecordSetAreaChange : RecordObjectBase
{
public int index;
public Vector3 position;
public Vector3 mousePosition;
public Vector3 point;
}
public class RecordSetAreaAdd : RecordObjectBase
{

72
Assets/Scripts/Tool/SetArea/DragVertice.cs

@ -6,7 +6,7 @@ using UnityEngine.EventSystems;
using UnityEngine.UI;
using AX.MessageSystem;
[RequireComponent(typeof(Image))]
public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler
public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IEndDragHandler
{
public PolygonController PolygonController;
RaycastHit hit;
@ -29,12 +29,12 @@ public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
addToggle = addPanel.transform.Find("Add").GetComponent<Toggle>();
delButton = addPanel.transform.Find("DelButton").GetComponent<Button>();
delButton.onClick.AddListener(DelVertice);
MessageDispatcher.AddListener("SelectedVertice", ChangeColor);
MessageDispatcher.AddListener("SelectedVertice", ChangeColor);
}
private void OnDestroy()
{
MessageDispatcher.RemoveListener("SelectedVertice", ChangeColor);
MessageDispatcher.RemoveListener("SelectedVertice", ChangeColor);
}
private void Update()
{
@ -57,6 +57,25 @@ public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
}
}
}
if (Input.GetButtonUp("Fire1") && addToggle.isOn)
{
if (selectedObj == this.gameObject)
{
if (!EventSystem.current.IsPointerOverGameObject())
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var rayCast = getRayCastAll(ray);
if (rayCast)
{
PolygonController.AddPolygon(index + 1, hit.point, Input.mousePosition);
/*if (PolygonController.GetComponent<CloneGameObjInfo>().gameObjType == CloneObjType.EvacuationExit)
{
MessageDispatcher.SendMessage("SaveEvacuationExit", PolygonController.gameObject);
}*/
}
}
}
}
if (Input.GetButtonDown("Fire2") && addToggle.isOn)
{
addToggle.isOn = false;
@ -82,27 +101,27 @@ public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
if (index >= 0 && PolygonController.ChangePosition(index, eventData.position))
{
IsOnDrag = true;
(transform as RectTransform).anchoredPosition = anchoredPosition;
(transform as RectTransform).anchoredPosition = anchoredPosition;
}
}
}
public void OnPointerDown(PointerEventData eventData)
{
index = PolygonController.FindIndex(eventData.position);
selectedObj = this.gameObject;
image.color = Color.red;
addPanel.SetActive(true);
MessageDispatcher.SendMessage("SelectedVertice");
MessageDispatcher.SendMessage("SelectedVertice");
}
public void OnPointerUp(PointerEventData eventData)
{
{
if (IsOnDrag)
{
IsOnDrag = false;
{
IsOnDrag = false;
}
}
}
private void OnDisable()
{
if (selectedObj == this.gameObject)
@ -116,7 +135,16 @@ public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
if (selectedObj == this.gameObject)
{
PolygonController.DelPolygon(index);
if (index < 0)
{
Debug.Log($"-><color=#CD2200>{"index小于0"}</color>");
return;
}
PolygonController.DelPolygon(index);
if (PolygonController.worldPositions.Count < 0)
{
return;
}
if (index == 0)
{
PolygonController.transform.Find("info").transform.position = PolygonController.worldPositions[0];
@ -168,5 +196,21 @@ public class DragVertice : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
}
return rayCast;
}
public void OnEndDrag(PointerEventData eventData)
{
if (!PolygonController.Editable)
return;
Vector2 anchoredPosition;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Canvas.transform as RectTransform, eventData.position, null, out anchoredPosition))
{
if (index >= 0 && PolygonController.ChangePosition(index, eventData.position, true))
{
IsOnDrag = true;
(transform as RectTransform).anchoredPosition = anchoredPosition;
}
}
}
}

2
Assets/Scripts/Tool/SetArea/Polygon.cs

@ -156,7 +156,7 @@ public class Polygon : MonoBehaviour
if (canFragementIndex < 0)
{
Debug.LogError("数据有误找不到可划分顶点");
Debug.Log($"-><color=#CD8500>{""}</color>");
return new List<int>();
}

205
Assets/Scripts/Tool/SetArea/PolygonController.cs

@ -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);
}

6
Assets/Scripts/Tool/SetArea/SetArea.cs

@ -99,7 +99,7 @@ public class SetArea : MonoBehaviour
pos = Vector3.zero;
transform.localPosition = new Vector3(pos.x, pos.y + value, pos.z);
High = value;
AddRecordArea();
//AddRecordArea();
}
public void ReplayFrameData(RecordSetArea data)
{
@ -111,13 +111,13 @@ public class SetArea : MonoBehaviour
{
text.text = value;
Name = value;
AddRecordArea();
//AddRecordArea();
}
public void SetColor(Color value)
{
render.material.color = value;
Color = value;
AddRecordArea();
//AddRecordArea();
}
public void Confirm()
{

Loading…
Cancel
Save