id | 手柄的控件 ID。 |
rotation | 手柄的方向。 |
position | 3D 空间中手柄的中心位置。 |
size | 手柄的大小。 注意:如果您希望拥有恒定屏幕大小的手柄,请使用 HandleUtility.GetHandleSize。 |
Quaternion 通过用户与手柄的交互修改的新旋转值。如果用户没有移动手柄,则将返回您传递给相应函数的值。
创建一个不受约束的旋转手柄。
The handle can rotate freely on all axes. The rotation gizmo has no visible axes and is simply a circle in the Scene view. Users can click and drag from within the circle to provide input rotation to your editor script.
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; } }