rotation | 手柄的方向。 |
position | 3D 空间中手柄的中心位置。 |
Quaternion 通过用户与手柄的交互修改的新旋转值。如果用户没有移动手柄,则将返回您传递给相应函数的值。
创建一个场景视图旋转手柄。
此手柄的行为类似于 Unity 中的内置旋转工具。如果您已经向 Undo.SetSnapshotTarget 分配了某些内容,它将完全支持 Undo。
注意:如果您希望拥有恒定屏幕大小的手柄,请使用 HandleUtility.GetHandleSize。
Rotate the attached object from the Rotation Handle.
// Name this script "RotateAtPointEditor"
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(RotateAtPoint))]
[CanEditMultipleObjects]
public class RotateAtPointEditor : Editor
{
public void OnSceneGUI()
{
RotateAtPoint t = (target as RotateAtPoint);
EditorGUI.BeginChangeCheck();
Quaternion rot = Handles.RotationHandle(t.rot, Vector3.zero);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Rotated RotateAt Point");
t.rot = rot;
t.Update();
}
}
}
附加到此游戏对象的脚本:
// Name this script "RotateAtPoint"
using UnityEngine;
[ExecuteInEditMode]
public class RotateAtPoint : MonoBehaviour
{
public Quaternion rot = Quaternion.identity;
public void Update()
{
transform.rotation = rot;
}
}