protected override void UpdateOverride() { base.UpdateOverride(); RaycastHit hit; if (Physics.Raycast(Window.Pointer, out hit)) { Vector3 point = SnapToVertex(hit.point); if (Editor.Input.GetPointerDown(0)) { if (m_points.Count == 2) { m_points.Clear(); } else { m_points.Add(point); m_points.Add(point); } Renderer.Vertices = m_points.ToArray(); Renderer.Refresh(); } else { PointerRenderer.transform.position = point; if (m_points.Count == 2) { m_points[1] = point; Renderer.Vertices = m_points.ToArray(); Renderer.Refresh(true); } if (Output != null) { Output.transform.position = point; if (m_points.Count == 2) { float mag = (m_points[1] - m_points[0]).magnitude; Output.text = m_metric ? mag.ToString("F2") : UnitsConverter.MetersToFeetInches(mag); Output.text += System.Environment.NewLine + System.Environment.NewLine; } else { Output.text = ""; } } } } }
private void UpdateText() { if (m_txtSize1 == null && m_txtSize2 == null) { return; } if (m_points == null) { return; } Vector3[] v = m_points.sharedMesh.vertices; if (m_txtSize1 != null) { float size; Vector3 offset = Vector3.zero; Quaternion textRotation; if (m_currentAxis == RuntimeHandleAxis.XY) { size = m_bounds.size.x * m_localScale.x; textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.identity : Quaternion.Euler(0, 180, 0); } else if (m_currentAxis == RuntimeHandleAxis.XZ) { size = m_bounds.size.x * m_localScale.x; textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.Euler(270, 0, 180) : Quaternion.Euler(90, 0, 0); } else { textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.Euler(180, -90, -90) : Quaternion.Euler(0, -90, -90); size = m_bounds.size.y * m_localScale.y; } m_txtSize1.transform.localRotation = m_rotation * textRotation; m_txtSize1.transform.position = m_points.transform.TransformPoint(v[0] + (v[1] - v[0]) / 2); m_txtSize1.text = m_metric ? size.ToString("F2") : UnitsConverter.MetersToFeetInches(size); } if (m_txtSize2 != null) { float size; Quaternion textRotation; Vector3 position = m_points.transform.TransformPoint(v[1] + (v[2] - v[1]) / 2); if (m_currentAxis == RuntimeHandleAxis.XY) { size = m_bounds.size.y * m_localScale.y; textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.Euler(0, 0, 90) : Quaternion.Euler(180, 0, 90); } else if (m_currentAxis == RuntimeHandleAxis.XZ) { size = m_bounds.size.z * m_localScale.z; textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.Euler(270, 0, 90) : Quaternion.Euler(90, 0, 90); } else { size = m_bounds.size.z * m_localScale.z; textRotation = Mathf.Sign(m_currentDot) > 0 ? Quaternion.Euler(0, -270, 0) : Quaternion.Euler(0, -90, 0); position = m_points.transform.TransformPoint(v[0] + (v[3] - v[0]) / 2); } m_txtSize2.transform.localRotation = m_rotation * textRotation; m_txtSize2.transform.position = position; m_txtSize2.text = m_metric ? size.ToString("F2") : UnitsConverter.MetersToFeetInches(size); } }