void OnGUI() { GUILayout.BeginHorizontal(); if (measurementState.Equals(measurementStates.none)) { if (GUILayout.Button("Measure")) { measurementState = measurementStates.first; } } else if (measurementState.Equals(measurementStates.first)) { GUILayout.Label("Pick first point"); } else if (measurementState.Equals(measurementStates.second)) { GUILayout.Label("Pick last point"); } else if (measurementState.Equals(measurementStates.showing)) { GUILayout.Label(Vector3.Distance(first, second).ToString()); } if (GUILayout.Button("Restart")) { Restart(); } GUILayout.EndHorizontal(); }
public void OnSceneGUI(SceneView sceneView) { Color t = new Color(1, 1, 1, .1f); if (measurementState.Equals(measurementStates.first) && DropPoint(out first)) { measurementState = measurementStates.second; } else if (measurementState.Equals(measurementStates.first)) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } else if (measurementState.Equals(measurementStates.second) && DropPoint(out second)) { measurementState = measurementStates.showing; HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } else if (measurementState.Equals(measurementStates.second)) { CheckCancel(); //Handles.DotHandleCap(42, first, Quaternion.identity, 0.05f, EventType.MouseDown); Handles.color = t; Handles.SphereCap(42, first, Quaternion.identity, 0.05f); Ray mouseRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (Physics.Raycast(mouseRay, out hit, 100f)) { Handles.color = Color.white; Handles.DrawLine(first, hit.point); //Handles.DotHandleCap(42, hit.point, Quaternion.identity, 0.05f, EventType.MouseDown); Handles.color = t; Handles.SphereCap(42, hit.point, Quaternion.identity, 0.05f); } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } else if (measurementState.Equals(measurementStates.showing)) { CheckCancel(); HandleUtility.Repaint(); Handles.color = Color.white; Handles.DrawLine(first, second); //Handles.DotHandleCap(42, first, Quaternion.identity, 0.05f, EventType.MouseDown); //Handles.DotHandleCap(42, second, Quaternion.identity, 0.05f, EventType.MouseDown); Handles.color = t; Handles.SphereCap(42, first, Quaternion.identity, 0.05f); Handles.SphereCap(42, second, Quaternion.identity, 0.05f); if (Event.current != null && (Event.current.button == 0) && Event.current.type.Equals(EventType.MouseDown)) { Restart(); } this.Repaint(); } else { HandleUtility.Repaint(); } SceneView.RepaintAll(); }
public void OnSceneGUI(SceneView sceneView) { if (measurementState.Equals(measurementStates.first) && DropPoint(out first)) { measurementState = measurementStates.second; } else if (measurementState.Equals(measurementStates.first)) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } else if (measurementState.Equals(measurementStates.second) && DropPoint(out second)) { measurementState = measurementStates.showing; HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); }else if (measurementState.Equals(measurementStates.second)){ CheckCancel(); Handles.SphereCap(42, first, Quaternion.identity, 0.05f); Ray mouseRay = HandleUtility.GUIPointToWorldRay(Event.current .mousePosition); RaycastHit hit; if (Physics.Raycast(mouseRay, out hit, 100f)) { Handles.DrawLine(first, hit.point); Handles.SphereCap(42, hit.point, Quaternion.identity, 0.05f); } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); } else if (measurementState.Equals(measurementStates.showing)) { CheckCancel(); HandleUtility.Repaint(); Handles.DrawLine(first, second); Handles.SphereCap(42, first, Quaternion.identity, 0.05f); Handles.SphereCap(42, second, Quaternion.identity, 0.05f); if (Event.current != null && (Event.current.button == 0) && Event.current.type.Equals(EventType.mouseDown)) { Restart(); } this.Repaint(); } else { HandleUtility.Repaint(); } SceneView.RepaintAll(); }
void OnGUI() { GUILayout.BeginHorizontal(); if (measurementState.Equals(measurementStates.none)) { if (GUILayout.Button("Measure")) { measurementState = measurementStates.first; } } else if (measurementState.Equals(measurementStates.first)) { GUILayout.Label("Pick first point"); } else if (measurementState.Equals(measurementStates.second)) { GUILayout.Label("Pick last point"); } else if (measurementState.Equals(measurementStates.showing)) { GUILayout.Label(Vector3.Distance(first,second).ToString()); } if (GUILayout.Button("Restart")) { Restart(); } GUILayout.EndHorizontal(); }
private void Restart() { measurementState = measurementStates.none; first = Vector3.zero; second = Vector3.zero; }