id | The control ID of the handle. |
rotation | The orientation of the handle in 3D space. |
position | The center of the handle in 3D space. |
size | 手柄的大小。 **注意**:如果您希望拥有恒定屏幕大小的手柄,请使用 HandleUtility.GetHandleSize。 |
Quaternion 通过用户与手柄的交互修改的新旋转值。如果用户没有移动手柄,则将返回您传递给相应函数的值。
创建一个不受约束的旋转手柄。
手柄可以在所有轴上自由旋转。旋转辅助图标没有可见轴,只是场景视图中的一个圆形。用户可以在圆圈内执行单击和拖动操作,以向编辑器脚本提供输入旋转。
\
在场景视图中看到的 FreeRotate 手柄。
// 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; } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.