public static Quaternion RotationHandle (Quaternion rotation, Vector3 position);

Parameters

rotation手柄的方向。
position3D 空间中手柄的中心位置。

Returns

Quaternion 通过用户与手柄的交互修改的新旋转值。如果用户没有移动手柄,则将返回您传递给相应函数的值。

Description

创建一个场景视图旋转手柄。

This will behave like the built-in rotation tool in Unity. If you have assigned something to Undo.SetSnapshotTarget, it will work fully with Undo. Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles.


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; } }