public static void DrawSolidArc(Vector3 center, Vector3 normal, Vector3 from, float angle, float radius) { if (Event.current.type != EventType.Repaint) { return; } Vector3[] array = new Vector3[60]; SetDiscSectionPoints(array, 60, center, normal, from, angle, radius); Shader.SetGlobalColor("_HandleColor", color * new Color(1f, 1f, 1f, 0.5f)); Shader.SetGlobalFloat("_HandleSize", 1f); RuntimeHandlesUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(matrix); GL.Begin(4); for (int i = 1; i < array.Length; i++) { GL.Color(color); GL.Vertex(center); GL.Vertex(array[i - 1]); GL.Vertex(array[i]); GL.Vertex(center); GL.Vertex(array[i]); GL.Vertex(array[i - 1]); } GL.End(); GL.PopMatrix(); }
private static bool BeginLineDrawing(Matrix4x4 matrix, bool dottedLines) { if (Event.current.type != EventType.Repaint) { return(false); } Color c = s_Color * lineTransparency; RuntimeHandlesUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(matrix); GL.Begin(1); GL.Color(c); return(true); }
public static void SetCamera(Rect position, Camera camera) { Rect rect = GUIClipUtil.Unclip(position); rect = RuntimeHandlesUtility.PointsToPixels(rect); Rect pixelRect = new Rect(rect.xMin, (float)Screen.height - rect.yMax, rect.width, rect.height); camera.pixelRect = pixelRect; Event current = Event.current; if (current.type == EventType.Repaint) { Camera.SetupCurrent(camera); } else { currentCamera = camera; } }
private void OnGUI() { if (camera == null) { camera = Player.Camera; return; } var current = Event.current; RuntimeHandles.SetCamera(camera.pixelRect, camera); RuntimeHandlesUtility.BeginHandles(); RuntimeHandles.currentCamera = camera; WorldProp selection = RuntimeSelection.activeProp; if (selection != null) { switch (Tools.current) { case RuntimeTool.Move: MoveToolGUI(MoveToolGUI); break; case RuntimeTool.Rotate: RuntimeEditorGUI.BeginChangeCheck(); Quaternion rotation = RuntimeHandles.DoRotationHandle(selection.Rotation, Tools.handlePosition); if (RuntimeEditorGUI.EndChangeCheck()) { UndoManager.PushUndo("Rotate", r => selection.SetRotation((Quaternion)r, true), selection.Rotation); } selection.SetRotation(rotation, true); break; case RuntimeTool.Scale: Vector3 scale = RuntimeHandles.DoScaleHandle(selection.Scale, Tools.handlePosition, Tools.handleRotation); selection.SetScale(scale, true); break; } } RuntimeHandlesUtility.EndHandles(); }
private static Vector3 DoPositionHandle_Internal(Vector3 position, Quaternion rotation) { float handleSize = RuntimeHandlesUtility.GetHandleSize(position); Color color = RuntimeHandles.color; bool flag = !Tools.s_Hidden; RuntimeHandles.color = ((!flag) ? xAxisColor : Color.Lerp(xAxisColor, staticColor, staticBlend)); GUI.SetNextControlName("xAxis"); position = Slider(position, rotation * Vector3.right, handleSize, ArrowCap, RuntimeSnapSettings.move.x); RuntimeHandles.color = ((!flag) ? yAxisColor : Color.Lerp(yAxisColor, staticColor, staticBlend)); GUI.SetNextControlName("yAxis"); position = Slider(position, rotation * Vector3.up, handleSize, ArrowCap, RuntimeSnapSettings.move.x); RuntimeHandles.color = ((!flag) ? zAxisColor : Color.Lerp(zAxisColor, staticColor, staticBlend)); GUI.SetNextControlName("zAxis"); position = Slider(position, rotation * Vector3.forward, handleSize, ArrowCap, RuntimeSnapSettings.move.x); position = DoPlanarHandle(PlaneHandle.xzPlane, position, rotation, handleSize * 0.25f); position = DoPlanarHandle(PlaneHandle.xyPlane, position, rotation, handleSize * 0.25f); position = DoPlanarHandle(PlaneHandle.yzPlane, position, rotation, handleSize * 0.25f); RuntimeHandles.color = color; return(position); }
public static Quaternion DoRotationHandle(Quaternion rotation, Vector3 position) { float handleSize = RuntimeHandlesUtility.GetHandleSize(position); Color color = RuntimeHandles.color; bool flag = !Tools.s_Hidden; RuntimeHandles.color = ((!flag) ? xAxisColor : Color.Lerp(xAxisColor, staticColor, staticBlend)); rotation = Disc(rotation, position, rotation * Vector3.right, handleSize, true, RuntimeSnapSettings.rotation); RuntimeHandles.color = ((!flag) ? yAxisColor : Color.Lerp(yAxisColor, staticColor, staticBlend)); rotation = Disc(rotation, position, rotation * Vector3.up, handleSize, true, RuntimeSnapSettings.rotation); RuntimeHandles.color = ((!flag) ? zAxisColor : Color.Lerp(zAxisColor, staticColor, staticBlend)); rotation = Disc(rotation, position, rotation * Vector3.forward, handleSize, true, RuntimeSnapSettings.rotation); if (!flag) { RuntimeHandles.color = centerColor; rotation = Disc(rotation, position, currentCamera.transform.forward, handleSize * 1.1f, false, 0f); //rotation = FreeRotateHandle(rotation, position, handleSize); } RuntimeHandles.color = color; return(rotation); }
public static void DrawSolidRectangleWithOutline(Vector3[] verts, Color faceColor, Color outlineColor) { if (Event.current.type != EventType.Repaint) { return; } RuntimeHandlesUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(matrix); if (faceColor.a > 0f) { Color c = faceColor * color; GL.Begin(4); for (int i = 0; i < 2; i++) { GL.Color(c); GL.Vertex(verts[i * 2]); GL.Vertex(verts[i * 2 + 1]); GL.Vertex(verts[(i * 2 + 2) % 4]); GL.Vertex(verts[i * 2]); GL.Vertex(verts[(i * 2 + 2) % 4]); GL.Vertex(verts[i * 2 + 1]); } GL.End(); } if (outlineColor.a > 0f) { Color c2 = outlineColor * color; GL.Begin(1); GL.Color(c2); for (int j = 0; j < 4; j++) { GL.Vertex(verts[j]); GL.Vertex(verts[(j + 1) % 4]); } GL.End(); } GL.PopMatrix(); }
private static Vector2 CalcDeltaAlongDirections(int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, RuntimeHandles.DrawCapFunction drawFunc, Vector2 snap, bool drawHelper) { Vector2 vector = new Vector2(0f, 0f); Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (((RuntimeHandlesUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) && GUIUtility.hotControl == 0) { Plane plane = new Plane(RuntimeHandles.matrix.MultiplyVector(handleDir), RuntimeHandles.matrix.MultiplyPoint(handlePos)); Ray ray = RuntimeHandlesUtility.GUIPointToWorldRay(current.mousePosition); float distance = 0f; plane.Raycast(ray, out distance); GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; Slider2D.s_CurrentMousePosition = current.mousePosition; Slider2D.s_StartPosition = handlePos; Vector3 a = RuntimeHandles.s_InverseMatrix.MultiplyPoint(ray.GetPoint(distance)); Vector3 lhs = a - handlePos; Slider2D.s_StartPlaneOffset.x = Vector3.Dot(lhs, slideDir1); Slider2D.s_StartPlaneOffset.y = Vector3.Dot(lhs, slideDir2); current.Use(); //EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { Slider2D.s_CurrentMousePosition += current.delta; Vector3 a2 = RuntimeHandles.matrix.MultiplyPoint(handlePos); Vector3 normalized = RuntimeHandles.matrix.MultiplyVector(slideDir1).normalized; Vector3 normalized2 = RuntimeHandles.matrix.MultiplyVector(slideDir2).normalized; Ray ray2 = RuntimeHandlesUtility.GUIPointToWorldRay(Slider2D.s_CurrentMousePosition); Plane plane2 = new Plane(a2, a2 + normalized, a2 + normalized2); float distance2 = 0f; if (plane2.Raycast(ray2, out distance2)) { Vector3 point = RuntimeHandles.s_InverseMatrix.MultiplyPoint(ray2.GetPoint(distance2)); vector.x = RuntimeHandlesUtility.PointOnLineParameter(point, Slider2D.s_StartPosition, slideDir1); vector.y = RuntimeHandlesUtility.PointOnLineParameter(point, Slider2D.s_StartPosition, slideDir2); vector -= Slider2D.s_StartPlaneOffset; if (snap.x > 0f || snap.y > 0f) { vector.x = RuntimeHandles.SnapValue(vector.x, snap.x); vector.y = RuntimeHandles.SnapValue(vector.y, snap.y); } GUI.changed = true; } current.Use(); } break; case EventType.Repaint: if (drawFunc != null) { Vector3 vector2 = handlePos + offset; Quaternion rotation = Quaternion.LookRotation(handleDir, slideDir1); Color color = Color.white; if (id == GUIUtility.keyboardControl) { color = RuntimeHandles.color; RuntimeHandles.color = RuntimeHandles.selectedColor; } drawFunc(id, vector2, rotation, handleSize); if (id == GUIUtility.keyboardControl) { RuntimeHandles.color = color; } if (drawHelper && GUIUtility.hotControl == id) { Vector3[] array = new Vector3[4]; float d = handleSize * 10f; array[0] = vector2 + (slideDir1 * d + slideDir2 * d); array[1] = array[0] - slideDir1 * d * 2f; array[2] = array[1] - slideDir2 * d * 2f; array[3] = array[2] + slideDir1 * d * 2f; Color color2 = RuntimeHandles.color; RuntimeHandles.color = Color.white; float num = 0.6f; RuntimeHandles.DrawSolidRectangleWithOutline(array, new Color(1f, 1f, 1f, 0.05f), new Color(num, num, num, 0.4f)); RuntimeHandles.color = color2; } } break; case EventType.Layout: if (drawFunc == RuntimeHandles.ArrowCap) { RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToLine(handlePos + offset, handlePos + handleDir * handleSize)); RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(handlePos + offset + handleDir * handleSize, handleSize * 0.2f)); } else if (drawFunc == RuntimeHandles.RectangleCap) { RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToRectangle(handlePos + offset, Quaternion.LookRotation(handleDir, slideDir1), handleSize)); } else { RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(handlePos + offset, handleSize * 0.5f)); } break; } return(vector); }
internal static Vector3 Do(int id, Vector3 position, Vector3 handleDirection, Vector3 slideDirection, float size, RuntimeHandles.DrawCapFunction drawFunc, float snap) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if (((RuntimeHandlesUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) && GUIUtility.hotControl == 0) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; Slider1D.s_CurrentMousePosition = (Slider1D.s_StartMousePosition = current.mousePosition); Slider1D.s_StartPosition = position; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { Slider1D.s_CurrentMousePosition += current.delta; float num = RuntimeHandlesUtility.CalcLineTranslation(Slider1D.s_StartMousePosition, Slider1D.s_CurrentMousePosition, Slider1D.s_StartPosition, slideDirection); num = RuntimeHandles.SnapValue(num, snap); Vector3 a = RuntimeHandles.matrix.MultiplyVector(slideDirection); Vector3 v = RuntimeHandles.s_Matrix.MultiplyPoint(Slider1D.s_StartPosition) + a * num; position = RuntimeHandles.s_InverseMatrix.MultiplyPoint(v); GUI.changed = true; current.Use(); } break; case EventType.Repaint: { Color color = Color.white; if (id == GUIUtility.keyboardControl && GUI.enabled) { color = RuntimeHandles.color; RuntimeHandles.color = RuntimeHandles.selectedColor; } drawFunc(id, position, Quaternion.LookRotation(handleDirection), size); if (id == GUIUtility.keyboardControl) { RuntimeHandles.color = color; } break; } case EventType.Layout: if (drawFunc == new RuntimeHandles.DrawCapFunction(RuntimeHandles.ArrowCap)) { RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToLine(position, position + slideDirection * size)); RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(position + slideDirection * size, size * 0.2f)); } else { RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(position, size * 0.2f)); } break; } return(position); }
public static void SetMinDragDifferenceForPos(Vector3 position) { minDragDifference = Vector3.one * (RuntimeHandlesUtility.GetHandleSize(position) / 80f); }
public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap) { if (Mathf.Abs(Vector3.Dot(RuntimeHandles.currentCamera.transform.forward, axis)) > 0.999f) { cutoffPlane = false; } Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ((RuntimeHandlesUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; Tools.LockHandlePosition(); if (cutoffPlane) { Vector3 normalized = Vector3.Cross(axis, RuntimeHandles.currentCamera.transform.forward).normalized; Disc.s_StartPosition = RuntimeHandlesUtility.ClosestPointToArc(position, axis, normalized, 180f, size); } else { Disc.s_StartPosition = RuntimeHandlesUtility.ClosestPointToDisc(position, axis, size); } Disc.s_RotationDist = 0f; Disc.s_StartRotation = rotation; Disc.s_StartAxis = axis; Disc.s_CurrentMousePosition = (Disc.s_StartMousePosition = Event.current.mousePosition); current.Use(); //EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { Tools.UnlockHandlePosition(); GUIUtility.hotControl = 0; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { bool flag = RuntimeEditorGUI.actionKey && current.shift; if (flag) { if (RuntimeHandlesUtility.ignoreRaySnapObjects == null) { RuntimeHandles.SetupIgnoreRaySnapObjects(); } object obj = RuntimeHandlesUtility.RaySnap(RuntimeHandlesUtility.GUIPointToWorldRay(current.mousePosition)); if (obj != null && (double)Vector3.Dot(axis.normalized, rotation * Vector3.forward) < 0.999) { Vector3 vector = ((RaycastHit)obj).point - position; Vector3 forward = vector - Vector3.Dot(vector, axis.normalized) * axis.normalized; rotation = Quaternion.LookRotation(forward, rotation * Vector3.up); } } else { Vector3 normalized2 = Vector3.Cross(axis, position - Disc.s_StartPosition).normalized; Disc.s_CurrentMousePosition += current.delta; Disc.s_RotationDist = RuntimeHandlesUtility.CalcLineTranslation(Disc.s_StartMousePosition, Disc.s_CurrentMousePosition, Disc.s_StartPosition, normalized2) / size * 30f; Disc.s_RotationDist = RuntimeHandles.SnapValue(Disc.s_RotationDist, snap); rotation = Quaternion.AngleAxis(Disc.s_RotationDist * -1f, Disc.s_StartAxis) * Disc.s_StartRotation; } GUI.changed = true; current.Use(); } break; case EventType.KeyDown: if (current.keyCode == KeyCode.Escape && GUIUtility.hotControl == id) { Tools.UnlockHandlePosition(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.Repaint: { Color color = Color.white; if (id == GUIUtility.keyboardControl) { color = RuntimeHandles.color; RuntimeHandles.color = RuntimeHandles.selectedColor; } if (GUIUtility.hotControl == id) { Color color2 = RuntimeHandles.color; Vector3 normalized3 = (Disc.s_StartPosition - position).normalized; RuntimeHandles.color = RuntimeHandles.secondaryColor; RuntimeHandles.DrawLine(position, position + normalized3 * size * 1.1f); float angle = Mathf.Repeat(-Disc.s_RotationDist - 180f, 360f) - 180f; Vector3 a = Quaternion.AngleAxis(angle, axis) * normalized3; RuntimeHandles.DrawLine(position, position + a * size * 1.1f); RuntimeHandles.color = RuntimeHandles.secondaryColor * new Color(1f, 1f, 1f, 0.2f); RuntimeHandles.DrawSolidArc(position, axis, normalized3, angle, size); RuntimeHandles.color = color2; } if (cutoffPlane) { Vector3 normalized4 = Vector3.Cross(axis, RuntimeHandles.currentCamera.transform.forward).normalized; RuntimeHandles.DrawWireArc(position, axis, normalized4, 180f, size); } else { RuntimeHandles.DrawWireDisc(position, axis, size); } if (id == GUIUtility.keyboardControl) { RuntimeHandles.color = color; } break; } case EventType.Layout: { float distance; if (cutoffPlane) { Vector3 normalized5 = Vector3.Cross(axis, RuntimeHandles.currentCamera.transform.forward).normalized; distance = RuntimeHandlesUtility.DistanceToArc(position, axis, normalized5, 180f, size) / 2f; } else { distance = RuntimeHandlesUtility.DistanceToDisc(position, axis, size) / 2f; } RuntimeHandlesUtility.AddControl(id, distance); break; } } return(rotation); }
public static Vector3 DoScaleHandle(Vector3 scale, Vector3 position, Quaternion rotation) { return(DoScaleHandle(scale, position, rotation, RuntimeHandlesUtility.GetHandleSize(position))); }
public static Vector3 Slider(Vector3 position, Vector3 direction) { return(Slider(position, direction, RuntimeHandlesUtility.GetHandleSize(position), ArrowCap, -1f)); }
public static float DoCenter(int id, float value, Vector3 position, Quaternion rotation, float size, RuntimeHandles.DrawCapFunction capFunc, float snap) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ((RuntimeHandlesUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; SliderScale.s_StartScale = value; SliderScale.s_ValueDrag = 0f; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; SliderScale.s_ScaleDrawLength = 1f; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { SliderScale.s_ValueDrag += RuntimeHandlesUtility.niceMouseDelta * 0.01f; value = (RuntimeHandles.SnapValue(SliderScale.s_ValueDrag, snap) + 1f) * SliderScale.s_StartScale; SliderScale.s_ScaleDrawLength = value / SliderScale.s_StartScale; GUI.changed = true; current.Use(); } break; case EventType.KeyDown: if (GUIUtility.hotControl == id && current.keyCode == KeyCode.Escape) { value = SliderScale.s_StartScale; SliderScale.s_ScaleDrawLength = 1f; GUIUtility.hotControl = 0; GUI.changed = true; current.Use(); } break; case EventType.Repaint: { Color color = Color.white; if (id == GUIUtility.keyboardControl) { color = RuntimeHandles.color; RuntimeHandles.color = RuntimeHandles.selectedColor; } capFunc(id, position, rotation, size * 0.15f); if (id == GUIUtility.keyboardControl) { RuntimeHandles.color = color; } break; } case EventType.Layout: RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(position, size * 0.15f)); break; } return(value); }
public static float DoAxis(int id, float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap) { Event current = Event.current; switch (current.GetTypeForControl(id)) { case EventType.MouseDown: if ((RuntimeHandlesUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) { GUIUtility.keyboardControl = id; GUIUtility.hotControl = id; SliderScale.s_CurrentMousePosition = (SliderScale.s_StartMousePosition = current.mousePosition); SliderScale.s_StartScale = scale; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(1); } break; case EventType.MouseUp: if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) { GUIUtility.hotControl = 0; current.Use(); //EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == id) { SliderScale.s_CurrentMousePosition += current.delta; float num = 1f + RuntimeHandlesUtility.CalcLineTranslation(SliderScale.s_StartMousePosition, SliderScale.s_CurrentMousePosition, position, direction) / size; num = RuntimeHandles.SnapValue(num, snap); scale = SliderScale.s_StartScale * num; GUI.changed = true; current.Use(); } break; case EventType.Repaint: { Color color = Color.white; if (id == GUIUtility.keyboardControl) { color = RuntimeHandles.color; RuntimeHandles.color = RuntimeHandles.selectedColor; } float num2 = size; if (GUIUtility.hotControl == id) { num2 = size * scale / SliderScale.s_StartScale; } RuntimeHandles.CubeCap(id, position + direction * num2 * SliderScale.s_ScaleDrawLength, rotation, size * 0.1f); RuntimeHandles.DrawLine(position, position + direction * (num2 * SliderScale.s_ScaleDrawLength - size * 0.05f)); if (id == GUIUtility.keyboardControl) { RuntimeHandles.color = color; } break; } case EventType.Layout: RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToLine(position, position + direction * size)); RuntimeHandlesUtility.AddControl(id, RuntimeHandlesUtility.DistanceToCircle(position + direction * size, size * 0.2f)); break; } return(scale); }