Unity3D 场景编辑器扩展学习笔记-Handles

Handles

Namespace: UnityEditor
Description

Custom 3D GUI controls and drawing in the scene view.

Handles are the 3D controls that Unity uses to manipulate items in the scene view. There are a number of built-in Handle GUIs, such as the familiar tools to position, scale and rotate an object via the Transform component. However, it is also possible to define your own Handle GUIs to use with custom component editors. Such GUIs can be a very useful way to edit procedurally-generated scene content, "invisible" items and groups of related objects, such as waypoints and location markers.You can also supplement the 3D Handle GUI in the scene with 2D buttons and other controls overlaid on the scene view. This is done by enclosing standard Unity GUI calls in a Handles.BeginGUI / EndGUI pair within the / OnSceneGUI/ function. You can use HandleUtility.GUIPointToWorldRay and HandleUtility.WorldToGUIPoint to convert coordinates between 2D GUI and 3D world coordinates.

总的来说,Handles就是在SceneView里画一些能响应用户操作的几何图案,并影响指定的变量数值。
这个类的接口大致分为以下几种:

Draw类:绘制元几何体,如点、线、面等。

DrawAAPolyLine Draw anti-aliased line specified with point array and width.
DrawBezier Draw textured bezier line through start and end points with the given tangents. To get an anti-aliased effect use a texture that is 1x2 pixels with one transparent white pixel and one opaque white pixel. The bezier curve will be swept using this texture.
DrawLine Draw a line from p1 to p2.
DrawPolyLine Draw a line going through the list of all points.
DrawSolidArc Draw a circular sector (pie piece) in 3D space.
DrawSolidDisc Draw a solid flat disc in 3D space.
DrawSolidRectangleWithOutline Draw a solid outlined rectangle in 3D space.
DrawWireArc Draw a circular arc in 3D space.
DrawWireDisc Draw the outline of a flat disc in 3D space.


Handle类:可视化操作数值,比如Vector3,Vector2,float等

DoPositionHandle 类似对象移动的三向操作器
DoRotationHandle 类似对象旋转的三向圆环操作器
DoScaleHandle 类似对象缩放的三轴操作器
FreeMoveHandle Make an unconstrained movement handle.
FreeRotateHandle Make an unconstrained rotation handle.
PositionHandle Make a 3D Scene view position handle.
RadiusHandle Make a Scene view radius handle.
RotationHandle Make a Scene view rotation handle.
ScaleHandle Make a Scene view scale handle.
ScaleValueHandle Make a single-float draggable handle.


Caps类:绘制多边形几何体,比如方块,点精灵,球形,圆锥等。

ArrowCap Draw an arrow like those used by the move tool.
SphereCap Draw a Sphere. Pass this into handle functions.
CircleCap Draw a camera-facing Circle. Pass this into handle functions.
ConeCap Draw a Cone. Pass this into handle functions.
CubeCap Draw a cube. Pass this into handle functions.
CylinderCap Draw a Cylinder. Pass this into handle functions.
DotCap Draw a camera-facing dot. Pass this into handle functions.
RectangleCap 画个矩形
SelectionFrame Draw a camera facing selection frame.

转载,来自github

using UnityEditor;
using UnityEngine;

namespace Developer.MechanicalDrive
{
    [CustomEditor(typeof(Gear), true)]
    [CanEditMultipleObjects]
    public class GearEditor : MechanismEditor
    {
         protected Gear script { get { return target as Gear; } }

         protected virtual void OnSceneGUI()
        {
            Handles.color = blue;
            DrawSphereCap(script.transform.position, Quaternion.identity, nodeSize);
            DrawCircleCap(script.transform.position, script.transform.rotation, script.radius);
            DrawArrow(script.transform.position, script.transform.forward, arrowLength, nodeSize, "Axis", blue);
        }
        #endregion
    }
}


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值