position | The position of the handle. |
rotation | The rotation of the handle. |
size | The size of the handle. |
capFunc | The function to use for drawing the handle (e.g. Handles.RectangleCap). |
snap | The grid size to snap movement to. |
Vector3 The new 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.
Make an unconstrained movement handle.
This can move freely in all directions. Hold down CMD to snap, CMD-SHIFT to raysnap against colliders in the Scene.
Free Move handle in the Scene View.
Note: Use HandleUtility.GetHandleSize if you want the handle to always remain the same size on the screen.
// Name this script "FreeMoveEditor" using UnityEngine; using UnityEditor;
[CustomEditor(typeof(FreeMove))] [CanEditMultipleObjects] public class FreeMoveEditor : Editor { public void OnSceneGUI() { FreeMove t = (target as FreeMove);
EditorGUI.BeginChangeCheck(); Vector3 pos = Handles.FreeMoveHandle(t.lookAtPoint, Quaternion.identity,.5f,new Vector3(.5f,.5f,.5f),Handles.RectangleCap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Free Move LookAt Point"); t.lookAtPoint = pos; t.Update(); } } }
And the script attached to this handle:
// Name this script "FreeMove" using UnityEngine;
[ExecuteInEditMode] public class FreeMove : MonoBehaviour { public Vector3 lookAtPoint = Vector3.zero;
public void Update() { transform.LookAt(lookAtPoint); } }