/// <inheritdoc/> protected internal override void Draw() { HandleDrawing.Layer = LAYER; HandleDrawing.Transform = Matrix4.TRS(position, rotation, Vector3.One); Vector3 cameraForward = EditorApplication.SceneViewCamera.SceneObject.Forward; // Draw 1D arrows Color xColor = Color.Red; if (xAxis.State == HandleSlider.StateType.Active) { xColor = Color.White; } else if (xAxis.State == HandleSlider.StateType.Hover) { xColor = Color.BansheeOrange; } xColor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)), 0.8f, 1.0f); HandleDrawing.Color = xColor; Vector3 xLineStart = Vector3.XAxis * BOX_EXTENT; Vector3 xConeStart = Vector3.XAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(xLineStart, xConeStart); HandleDrawing.DrawCone(xConeStart, Vector3.XAxis, CONE_HEIGHT, CONE_RADIUS); Color yColor = Color.Green; if (yAxis.State == HandleSlider.StateType.Active) { yColor = Color.White; } else if (yAxis.State == HandleSlider.StateType.Hover) { yColor = Color.BansheeOrange; } yColor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)), 0.8f, 1.0f); HandleDrawing.Color = yColor; Vector3 yLineStart = Vector3.YAxis * BOX_EXTENT; Vector3 yConeStart = Vector3.YAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(yLineStart, yConeStart); HandleDrawing.DrawCone(yConeStart, Vector3.YAxis, CONE_HEIGHT, CONE_RADIUS); Color zColor = Color.Blue; if (zAxis.State == HandleSlider.StateType.Active) { zColor = Color.White; } else if (zAxis.State == HandleSlider.StateType.Hover) { zColor = Color.BansheeOrange; } zColor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)), 0.8f, 1.0f); HandleDrawing.Color = zColor; Vector3 zLineStart = Vector3.ZAxis * BOX_EXTENT; Vector3 zConeStart = Vector3.ZAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(zLineStart, zConeStart); HandleDrawing.DrawCone(zConeStart, Vector3.ZAxis, CONE_HEIGHT, CONE_RADIUS); // Draw negative 1D arrows Color xNegColor = Color.LightGray; if (xNegAxis.State == HandleSlider.StateType.Active) { xNegColor = Color.White; } else if (xNegAxis.State == HandleSlider.StateType.Hover) { xNegColor = Color.BansheeOrange; } xNegColor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)), 0.8f, 1.0f); HandleDrawing.Color = xNegColor; Vector3 xNegLineStart = -Vector3.XAxis * BOX_EXTENT; Vector3 xNegConeStart = -Vector3.XAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(xNegLineStart, xNegConeStart); HandleDrawing.DrawCone(xNegConeStart, -Vector3.XAxis, CONE_HEIGHT, CONE_RADIUS); Color yNegColor = Color.LightGray; if (yNegAxis.State == HandleSlider.StateType.Active) { yNegColor = Color.White; } else if (yNegAxis.State == HandleSlider.StateType.Hover) { yNegColor = Color.BansheeOrange; } yNegColor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)), 0.8f, 1.0f); HandleDrawing.Color = yNegColor; Vector3 yNegLineStart = -Vector3.YAxis * BOX_EXTENT; Vector3 yNegConeStart = -Vector3.YAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(yNegLineStart, yNegConeStart); HandleDrawing.DrawCone(yNegConeStart, -Vector3.YAxis, CONE_HEIGHT, CONE_RADIUS); Color zNegcolor = Color.LightGray; if (zNegAxis.State == HandleSlider.StateType.Active) { zNegcolor = Color.White; } else if (zNegAxis.State == HandleSlider.StateType.Hover) { zNegcolor = Color.BansheeOrange; } zNegcolor.a = MathEx.Lerp(1.0f, 0.0f, MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)), 0.8f, 1.0f); HandleDrawing.Color = zNegcolor; Vector3 zNegLineStart = -Vector3.ZAxis * BOX_EXTENT; Vector3 zNegConeStart = -Vector3.ZAxis * (1.0f - CONE_HEIGHT); HandleDrawing.DrawLine(zNegLineStart, zNegConeStart); HandleDrawing.DrawCone(zNegConeStart, -Vector3.ZAxis, CONE_HEIGHT, CONE_RADIUS); // Draw projection type handle if (projTypePlane.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.White; } else if (projTypePlane.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.BansheeOrange; } else { HandleDrawing.Color = Color.White; } HandleDrawing.DrawCube(Vector3.Zero, new Vector3(BOX_EXTENT, BOX_EXTENT, BOX_EXTENT)); }
/// <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); }
/// <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 sliders Vector3 smallCubeExtents = new Vector3(SMALL_CUBE_SIZE * 0.5f, SMALL_CUBE_SIZE * 0.5f, SMALL_CUBE_SIZE * 0.5f); 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 xCubeOffset = Vector3.XAxis * SMALL_CUBE_SIZE * 0.5f; Vector3 xCubeStart = Vector3.XAxis - xCubeOffset; HandleDrawing.DrawLine(Vector3.Zero, xCubeStart, handleSize); HandleDrawing.DrawCube(xCubeStart + xCubeOffset, smallCubeExtents, 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 yCubeOffset = Vector3.YAxis * SMALL_CUBE_SIZE * 0.5f; Vector3 yCubeStart = Vector3.YAxis - yCubeOffset; HandleDrawing.DrawLine(Vector3.Zero, yCubeStart, handleSize); HandleDrawing.DrawCube(yCubeStart + yCubeOffset, smallCubeExtents, 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 zCubeOffset = Vector3.ZAxis * SMALL_CUBE_SIZE * 0.5f; Vector3 zCubeStart = Vector3.ZAxis - zCubeOffset; HandleDrawing.DrawLine(Vector3.Zero, zCubeStart, handleSize); HandleDrawing.DrawCube(zCubeStart + zCubeOffset, smallCubeExtents, handleSize); // Draw free scale handle if (freeAxis.State == HandleSlider.StateType.Active) { HandleDrawing.Color = Color.White; } else if (freeAxis.State == HandleSlider.StateType.Hover) { HandleDrawing.Color = Color.BansheeOrange; } else { HandleDrawing.Color = Color.White; } //// Rotate it so it always faces the camera, and move it forward a bit to always render in front Vector3 bottomLeft = -Vector3.XAxis * 0.2f - Vector3.YAxis * 0.2f; Vector3 topLeft = -Vector3.XAxis * 0.2f + Vector3.YAxis * 0.2f; Vector3 topRight = Vector3.XAxis * 0.2f + Vector3.YAxis * 0.2f; Vector3 bottomRight = Vector3.XAxis * 0.2f - Vector3.YAxis * 0.2f; Vector3 offset = Vector3.ZAxis * 0.1f; Quaternion cameraRot = EditorApplication.SceneViewCamera.SceneObject.Rotation; bottomLeft = cameraRot.Rotate(bottomLeft + offset); topLeft = cameraRot.Rotate(topLeft + offset); topRight = cameraRot.Rotate(topRight + offset); bottomRight = cameraRot.Rotate(bottomRight + offset); HandleDrawing.Transform = Matrix4.TRS(Position, Quaternion.Identity, Vector3.One); HandleDrawing.DrawLine(bottomLeft, bottomRight, handleSize); HandleDrawing.DrawLine(bottomLeft, topLeft, handleSize); HandleDrawing.DrawLine(topLeft, topRight, handleSize); HandleDrawing.DrawLine(bottomRight, topRight, handleSize); }