Registers a CustomPivotMode or CustomPivotRotation as a custom editor pivot setting. Use the PivotManager API or the Tool Settings overlay's UI to activate a registered setting.
using UnityEditor;using UnityEngine;using UnityEditor.EditorTools;// Register a custom Pivot Mode that places the tool handle at the top middle point of the active object's local bounds.// This Pivot Mode will be available for any tool or context as neither the targetTool nor targetToolContext are specified.[CustomPivot(k_DisplayName, tooltip = k_Tooltip, priority = CustomPivotAttribute.defaultPriority + 2)][Icon(k_Icon)] // Use IconAttribute to customize pivot setting's iconpublic sealed class TopPivotMode : CustomPivotMode{ const string k_DisplayName = "Top"; const string k_Icon = "ToolHandleGlobal"; const string k_Tooltip = "The tool handle is placed at the top middle point of active object's local bounds."; public override Vector3 position { get { Transform t = Selection.activeTransform; if (!t) return Vector3.zero; var renderer = t.GetComponent<MeshRenderer>(); if (!renderer) return Vector3.zero; var localBounds = renderer.localBounds; var localTopPivot = new Vector3(localBounds.center.x, localBounds.max.y, localBounds.center.z); var topPivotPosition = t.TransformPoint(localTopPivot); return topPivotPosition; } }}
using UnityEditor;using UnityEngine;using UnityEditor.EditorTools;// Register a custom Pivot Rotation that orients the tool handle to always face the Scene View's camera.// This Pivot Rotation will be available for any tool or context as neither targetTool nor targetToolContext are specified.[CustomPivot(k_DisplayName, tooltip = k_Tooltip, priority = CustomPivotAttribute.defaultPriority + 2)][Icon("ToolHandleGlobal")] // Use IconAttribute to customize pivot setting's iconpublic sealed class ViewPivotRotation : CustomPivotRotation{ const string k_DisplayName = "View"; const string k_Tooltip = "The tool handle is rotated to align with Scene View camera's orientation."; public override Quaternion rotation => SceneView.lastActiveSceneView.camera.transform.rotation;}
The default value for CustomPivotAttribute.priority. Specify a priority lower than this value to display a pivot setting before the default entries, or specify a higher value to display it after the default entries.