/// <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 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.DrawLine(bottomLeft, bottomRight, handleSize); HandleDrawing.DrawLine(bottomLeft, topLeft, handleSize); HandleDrawing.DrawLine(topLeft, topRight, handleSize); HandleDrawing.DrawLine(bottomRight, topRight, handleSize); }