rotation | 手柄的方向。 |
position | 3D 空间中手柄的中心位置。 |
size | 手柄的大小。 注意:如果您希望拥有恒定屏幕大小的手柄,请使用 HandleUtility.GetHandleSize。 |
Quaternion 通过用户与手柄的交互修改的新旋转值。如果用户没有移动手柄,则将返回您传递给相应函数的值。
创建一个不受约束的旋转手柄。
手柄可以在所有轴上自由旋转。旋转辅助图标没有可见轴,只是场景视图中的一个圆形。用户可以在圆圈内执行单击和拖动操作,以向编辑器脚本提供输入旋转。
FreeRotate handle seen in the Scene View.
// Name this script "FreeRotateEditor"
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(FreeRotate))]
[CanEditMultipleObjects]
public class FreeRotateEditor : Editor
{
public void OnSceneGUI()
{
FreeRotate t = (target as FreeRotate);
EditorGUI.BeginChangeCheck();
Quaternion rot = Handles.FreeRotateHandle(t.rot, Vector3.zero, 2);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Free Rotate");
t.rot = rot;
t.Update();
}
}
}
附加到此手柄的脚本:
// Name this script "FreeRotate"
using UnityEngine;
[ExecuteInEditMode]
public class FreeRotate : MonoBehaviour
{
public Quaternion rot = Quaternion.identity;
public void Update()
{
transform.rotation = rot;
}
}