position | The position of the handle. |
rotation | The rotation of the handle. this defines the space along. |
size | The size of the handle. |
capFunc | The function to use for drawing the handle, eg, Handles.RectangleCap Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles. |
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 agains colliders in the scene.
Free Move handle in the Scene View.
// 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); } }