场景视图中的自定义 3D GUI 控件和绘制操作。
手柄是 Unity 用于操作场景视图中的项的 3D 控件。内置的 Handle GUI 有很多,如通过变换组件定位、缩放和旋转对象的熟悉的工具。不过,您也可以自行定义 Handle GUI,以与自定义组件编辑器结合使用。此类 GUI 对于编辑以程序方式生成的场景内容、“不可见”项和相关对象的组(如路径点和位置标记)非常实用。
您还可以使用覆盖在场景视图上的 2D 按钮和其他控件来补充场景中的 3D 手柄 GUI。这是通过将标准 Unity GUI 调用封装在 Editor.OnSceneGUI 函数中的 Handles.BeginGUI 和 Handles.EndGUI 对中完成的。可以使用 HandleUtility.GUIPointToWorldRay 和 HandleUtility.WorldToGUIPoint 在 2D GUI 与 3D 世界坐标之间转换坐标。
using UnityEngine; using UnityEditor; public class ExampleScript : MonoBehaviour { public float value = 7.0f; }
// A tiny custom editor for ExampleScript component [CustomEditor(typeof(ExampleScript))] public class ExampleEditor : Editor { // Custom in-scene UI for when ExampleScript // component is selected. public void OnSceneGUI() { var t = target as ExampleScript; var tr = t.transform; var pos = tr.position; // display an orange disc where the object is var color = new Color(1, 0.8f, 0.4f, 1); Handles.color = color; Handles.DrawWireDisc(pos, tr.up, 1.0f); // display object "value" in scene GUI.color = color; Handles.Label(pos, t.value.ToString("F1")); } }
.
centerColor | 用于表示某物体中心的手柄的颜色。 |
color | 手柄的颜色。 |
inverseMatrix | 所有手柄操作的矩阵的逆矩阵。 |
lighting | 手柄是否亮起? |
lineThickness | Retrieves the user preference setting that controls the thickness of tool handle lines. (Read Only) |
matrix | 所有手柄操作的矩阵。 |
preselectionColor | 用于突出显示鼠标指针下当前未选中的手柄的颜色。 |
secondaryColor | 用于一般物体的柔和色。 |
selectedColor | 用于当前处于活动状态的手柄的颜色。 |
UIColliderHandleColor | Color to use for the Unity UI's padding visualization. |
xAxisColor | 用于操纵某物体 X 坐标的手柄的颜色。 |
yAxisColor | 用于操纵某物体 Y 坐标的手柄的颜色。 |
zAxisColor | 用于操纵某物体 Z 坐标的手柄的颜色。 |
zTest | 手柄的 zTest。 |
currentCamera | 为当前摄像机设置视口和相关内容。 |
ArrowHandleCap | 绘制一个类似于移动工具所用箭头的箭头。 |
BeginGUI | 在 3D 手柄 GUI 内开始一个 2D GUI 块。 |
Button | 创建一个 3D 按钮。 |
CircleHandleCap | 绘制一个圆形手柄。将此手柄传递给 handle 函数。 |
ClearCamera | 清除摄像机。 |
ConeHandleCap | 绘制一个锥体手柄。将此手柄传递给 handle 函数。 |
CubeHandleCap | 绘制一个立方体手柄。将此手柄传递给 handle 函数。 |
CylinderHandleCap | 绘制一个圆柱体手柄。将此手柄传递给 handle 函数。 |
Disc | 创建一个可使用鼠标拖动的 3D 圆盘。 |
DotHandleCap | 绘制一个圆点手柄。将此手柄传递给 handle 函数。 |
DrawAAConvexPolygon | 绘制使用点数组指定的抗锯齿凸多边形。 |
DrawAAPolyLine | 绘制使用点数组和宽度指定的抗锯齿线。 |
DrawBezier | 绘制通过给定切线的起点和终点的纹理化贝塞尔曲线。 |
DrawCamera | 在矩形内绘制一个摄像机。 |
DrawDottedLine | 绘制一条从 p1 到 p2 的虚线。 |
DrawDottedLines | 绘制一系列虚线段。 |
DrawGizmos | 为给定摄像机绘制 Gizmos 的子集(在后处理之前或之后)。 |
DrawLine | Draws a line from p1 to p2. |
DrawLines | 绘制一系列线段。 |
DrawOutline | Draws an outline around the specified GameObjects in the Scene View. |
DrawPolyLine | 绘制一条穿过 points 列表的线。 |
DrawSelectionFrame | 绘制一个面向选择框的摄像机。 |
DrawSolidArc | 在 3D 空间中绘制一个圆扇形(饼图)。 |
DrawSolidDisc | 在 3D 空间中绘制一个实心平面圆盘。 |
DrawSolidRectangleWithOutline | 在 3D 空间中绘制一个实心轮廓矩形。 |
DrawTexture3DSDF | Draws a 3D texture using Signed Distance Field rendering mode in 3D space. |
DrawTexture3DSlice | Draws a 3D texture using Slice rendering mode in 3D space. |
DrawTexture3DVolume | Draws a 3D texture using Volume rendering mode in 3D space. |
DrawWireArc | Draws a circular arc in 3D space. |
DrawWireCube | 使用 center 和 size 绘制一个线框盒体。 |
DrawWireDisc | Draws the outline of a flat disc in 3D space. |
EndGUI | 结束一个 2D GUI 块并返回到 3D 手柄 GUI。 |
FreeMoveHandle | 创建一个不受约束的移动手柄。 |
FreeRotateHandle | 创建一个不受约束的旋转手柄。 |
GetMainGameViewSize | 获取主游戏视图的宽度和高度。 |
Label | 在 3D 空间中创建一个文本标签。 |
MakeBezierPoints | 返回表示贝塞尔曲线的点数组。 |
PositionHandle | 创建一个位置手柄。 |
RadiusHandle | 创建一个场景视图半径手柄。 |
RectangleHandleCap | 绘制一个矩形手柄。将此手柄传递给 handle 函数。 |
RotationHandle | 创建一个场景视图旋转手柄。 |
ScaleHandle | 创建一个场景视图缩放手柄。 |
ScaleSlider | 创建一个定向缩放滑动条。 |
ScaleValueHandle | 创建一个缩放单个浮点的 3D 手柄。 |
SetCamera | 设置当前摄像机,以便所有手柄和辅助图标均使用相应设置进行绘制。 |
ShouldRenderGizmos | 确定是否绘制 Gizmos。 |
Slider | 创建一个沿着一个轴移动的 3D 滑动条。 |
Slider2D | 创建一个沿两个轴定义的平面移动的 3D 滑动条。 |
SnapToGrid | 将每个 Transform.position 四舍五入到 EditorSnap.move 的最接近倍数。 |
SnapValue | 如果对齐为 active,则将 value 四舍五入到 snap 的最接近倍数。注意,snap 只能为正数。 |
SphereHandleCap | 绘制一个球体手柄。将此手柄传递给 handle 函数。 |
TransformHandle | 创建变换手柄。 |
CapFunction | 用于绘制手柄的函数,如 Handles.RectangleCap。 |
SizeFunction | 用于根据手柄的当前位置获取手柄大小的委托类型。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.