/// <summary> /// Draws a single-sided rectangle in 3D. /// </summary> /// <param name="area">Determines the position, orientation and size of the rectangle.</param> /// <param name="size">Uniform scale to apply on top of the existing transform. Primarily used for maintaining /// handle size regardless of distance from camera.</param> public static void DrawRect(Rect3 area, float size = 1.0f) { Vector3 center = area.Center; Vector3 axisHorz = area.AxisHorz; Vector3 axisVert = area.AxisVert; Internal_DrawRect(ref center, ref axisHorz, ref axisVert, area.ExtentHorz, area.ExtentVert, size); }
/// <inheritdoc/> protected internal override void Draw() { HandleDrawing.Layer = 1; HandleDrawing.Transform = Matrix4.TRS(Position, Rotation, Vector3.One); float handleSize = Handles.GetHandleSize(EditorApplication.SceneViewCamera, position); // Draw 1D arrows if (xAxis.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.White; } else if (xAxis.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.BansheeOrange; } else { HandleDrawing.Color = Color.Red; } Vector3 xConeStart = Vector3.XAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(Vector3.Zero, xConeStart, handleSize); HandleDrawing.DrawCone(xConeStart, Vector3.XAxis, CONE_HEIGHT, CONE_RADIUS, handleSize); if (yAxis.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.White; } else if (yAxis.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.BansheeOrange; } else { HandleDrawing.Color = Color.Green; } Vector3 yConeStart = Vector3.YAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(Vector3.Zero, yConeStart, handleSize); HandleDrawing.DrawCone(yConeStart, Vector3.YAxis, CONE_HEIGHT, CONE_RADIUS, handleSize); if (zAxis.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.White; } else if (zAxis.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.BansheeOrange; } else { HandleDrawing.Color = Color.Blue; } Vector3 zConeStart = Vector3.ZAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(Vector3.Zero, zConeStart, handleSize); HandleDrawing.DrawCone(zConeStart, Vector3.ZAxis, CONE_HEIGHT, CONE_RADIUS, handleSize); // Draw 2D planes Color planeNormal = new Color(1.0f, 1.0f, 1.0f, 0.2f); Color planeHover = new Color(1.0f, 1.0f, 1.0f, 0.4f); Color planeActive = new Color(1.0f, 1.0f, 1.0f, 0.6f); Vector3 planeXOffset = Vector3.XAxis * 0.3f; Vector3 planeYOffset = Vector3.YAxis * 0.3f; Vector3 planeZOffset = Vector3.ZAxis * 0.3f; //// XY plane HandleDrawing.Color = Color.Blue; HandleDrawing.DrawLine(planeXOffset, planeXOffset + planeYOffset, handleSize); HandleDrawing.DrawLine(planeYOffset, planeYOffset + planeXOffset, handleSize); if (xyPlane.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.Blue * planeActive; } else if (xyPlane.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.Blue * planeHover; } else { HandleDrawing.Color = Color.Blue * planeNormal; } Rect3 xyPlaneArea = new Rect3( (planeXOffset + planeYOffset) * 0.5f, new Vector3[] { Vector3.XAxis, Vector3.YAxis }, new float[] { 0.15f, 0.15f }); HandleDrawing.DrawRect(xyPlaneArea, handleSize); //// YZ plane HandleDrawing.Color = Color.Red; HandleDrawing.DrawLine(planeYOffset, planeYOffset + planeZOffset, handleSize); HandleDrawing.DrawLine(planeZOffset, planeZOffset + planeYOffset, handleSize); if (yzPlane.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.Red * planeActive; } else if (yzPlane.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.Red * planeHover; } else { HandleDrawing.Color = Color.Red * planeNormal; } Rect3 yzPlaneArea = new Rect3( (planeYOffset + planeZOffset) * 0.5f, new Vector3[] { Vector3.YAxis, Vector3.ZAxis }, new float[] { 0.15f, 0.15f }); HandleDrawing.DrawRect(yzPlaneArea, handleSize); //// ZX plane HandleDrawing.Color = Color.Green; HandleDrawing.DrawLine(planeZOffset, planeZOffset + planeXOffset, handleSize); HandleDrawing.DrawLine(planeXOffset, planeXOffset + planeZOffset, handleSize); if (zxPlane.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.Green * planeActive; } else if (zxPlane.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.Green * planeHover; } else { HandleDrawing.Color = Color.Green * planeNormal; } Rect3 zxPlaneArea = new Rect3( (planeZOffset + planeXOffset) * 0.5f, new Vector3[] { Vector3.ZAxis, Vector3.XAxis }, new float[] { 0.15f, 0.15f }); HandleDrawing.DrawRect(zxPlaneArea, handleSize); }