Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Handles.FreeRotateHandle

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function FreeRotateHandle(rotation: Quaternion, position: Vector3, size: float): Quaternion;
public static Quaternion FreeRotateHandle(Quaternion rotation, Vector3 position, float size);

Parameters

rotation Orientation of the handle.
position Center of the handle in 3D space.
size The size of the handle.

Returns

Quaternion The new rotation value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the same value as you passed into the function.

Description

Make an unconstrained rotation handle.

This 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.

Note: Use HandleUtility.GetHandleSize if you want the handle to always remain the same size on the screen.

#pragma strict
// Name this script "FreeRotateEditor"
@CustomEditor(FreeRotate)
@CanEditMultipleObjects
public class FreeRotateEditor extends Editor {
	public function OnSceneGUI() {
		var t: FreeRotate = (target as FreeRotate);
		EditorGUI.BeginChangeCheck();
		var rot: Quaternion = Handles.FreeRotateHandle(t.rot, Vector3.zero, 2);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "Free Rotate");
			t.rot = rot;
			t.Update();
		}
	}
}
// 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(); } } }

And the script attached to this Handle:

#pragma strict
// Name this script "FreeRotate"
@ExecuteInEditMode
public class FreeRotate extends MonoBehaviour {
	public var rot: Quaternion = Quaternion.identity;
	public function Update() {
		transform.rotation = rot;
	}
}
// Name this script "FreeRotate"
using UnityEngine;

[ExecuteInEditMode] public class FreeRotate : MonoBehaviour { public Quaternion rot = Quaternion.identity; public void Update() { transform.rotation = rot; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961