diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index e28fb6e..1c24dd7 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -716,7 +716,7 @@ MonoBehaviour: m_FallbackScreenDPI: 96 m_DefaultSpriteDPI: 96 m_DynamicPixelsPerUnit: 1 - m_PresetInfoIsWorld: 1 + m_PresetInfoIsWorld: 0 --- !u!223 &978445652 Canvas: m_ObjectHideFlags: 0 @@ -1165,11 +1165,11 @@ RectTransform: - {fileID: 1623115969} m_Father: {fileID: 978445653} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 578, y: 400} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -180, y: -40} m_SizeDelta: {x: 100, y: 100} - m_Pivot: {x: 0.5, y: 0.5} + m_Pivot: {x: 1, y: 1} --- !u!1 &1483225868 GameObject: m_ObjectHideFlags: 0 @@ -1440,11 +1440,11 @@ RectTransform: - {fileID: 1899526669} m_Father: {fileID: 978445653} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 709, y: 400} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -40, y: -40} m_SizeDelta: {x: 100, y: 100} - m_Pivot: {x: 0.5, y: 0.5} + m_Pivot: {x: 1, y: 1} --- !u!1 &1623115968 GameObject: m_ObjectHideFlags: 0 @@ -1963,11 +1963,11 @@ RectTransform: - {fileID: 1172632111} m_Father: {fileID: 978445653} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 447, y: 400} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -320, y: -40} m_SizeDelta: {x: 100, y: 100} - m_Pivot: {x: 0.5, y: 0.5} + m_Pivot: {x: 1, y: 1} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/New/MeasureGroup.cs b/Assets/Scripts/New/MeasureGroup.cs index f34c6ae..9193448 100644 --- a/Assets/Scripts/New/MeasureGroup.cs +++ b/Assets/Scripts/New/MeasureGroup.cs @@ -25,6 +25,7 @@ public abstract class MeasureGroup : MonoBehaviour protected List points = new List(); public virtual void Init( + LineRenderer line, GameObject labelPrefab, GameObject deleteButtonPrefab, GameObject lineinfoPopupPrefab, @@ -35,6 +36,7 @@ public abstract class MeasureGroup : MonoBehaviour float lineWidth, Material lineMaterial) { + this.line = line; this.labelPrefab = labelPrefab; this.deleteButtonPrefab = deleteButtonPrefab; this.lineInfoPopupPrefab = lineinfoPopupPrefab; @@ -44,13 +46,6 @@ public abstract class MeasureGroup : MonoBehaviour this.lineScaleMultiplier = lineScaleMultiplier; this.lineWidth = lineWidth; - - line = gameObject.AddComponent(); - line.material = lineMaterial; - line.widthMultiplier = lineWidth; - line.positionCount = 0; - line.useWorldSpace = true; - cesiumGeoreference = FindAnyObjectByType(); cam = Camera.main; } diff --git a/Assets/Scripts/New/MeasureManager.cs b/Assets/Scripts/New/MeasureManager.cs index eb762a0..950a664 100644 --- a/Assets/Scripts/New/MeasureManager.cs +++ b/Assets/Scripts/New/MeasureManager.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; +using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; public enum MeasureMode { + None, Line, Rectangle, Polygon @@ -31,7 +33,7 @@ public class MeasureManager : MonoBehaviour private float lineWidth = 0.02f; public bool isMeasuring = false; - public MeasureMode currentMeasureMode = MeasureMode.Line; + public MeasureMode currentMeasureMode = MeasureMode.None; private void Awake() { @@ -40,7 +42,6 @@ public class MeasureManager : MonoBehaviour private void Update() { - if (Input.GetMouseButtonDown(0) && TryGetClickPosition(out Vector3 hitPos)) { if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject()) @@ -83,21 +84,34 @@ public class MeasureManager : MonoBehaviour private void CreateMeasureGroup() { MeasureGroup group = null; - Debug.Log("currentMeasureMode " + currentMeasureMode); + Color color = Color.white; + switch (currentMeasureMode) { case MeasureMode.Line: group = new GameObject("LineMeasureGroup").AddComponent(); + color = Color.white; break; case MeasureMode.Rectangle: group = new GameObject("RectangleMeasureGroup").AddComponent(); + color = Color.red; break; case MeasureMode.Polygon: group = new GameObject("PolygonMeasureGroup").AddComponent(); + color = Color.yellow; break; } + LineRenderer line = group.gameObject.AddComponent(); + line.material = lineMaterial; + line.widthMultiplier = lineWidth; + line.positionCount = 0; + line.useWorldSpace = true; + line.startColor = color; + line.endColor = color; + group.Init( + line, distanceLabelPrefab, deleteButtonPrefab, lineInfoPrefab, diff --git a/Assets/Scripts/New/RectangleMeasureGroup.cs b/Assets/Scripts/New/RectangleMeasureGroup.cs index d720174..f6854c6 100644 --- a/Assets/Scripts/New/RectangleMeasureGroup.cs +++ b/Assets/Scripts/New/RectangleMeasureGroup.cs @@ -52,20 +52,9 @@ public class RectangleMeasureGroup : MeasureGroup private void AddThirdPoint(Vector3 pos) { - Vector3 a = points[0]; - Vector3 b = points[1]; - Vector3 ab = b - a; - - Vector3 perp = new Vector3(-ab.z, 0, ab.x).normalized; - - Vector3 ac = pos - a; - float length = Vector3.Dot(ac, perp); - - Vector3 c = b + perp * length; - - deleteButton = Instantiate(deleteButtonPrefab, c, Quaternion.identity, infoPopupRoot); + deleteButton = Instantiate(deleteButtonPrefab, points[0], Quaternion.identity, infoPopupRoot); deleteButton.GetComponentInChildren