Зарегистрирует CustomPivotMode или CustomPivotRotation в качестве настроек редактора. Используйте PivotManager API или UI накладки Настройки инструмента для активации зарегистрированных настроек.
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 icon
public 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 icon
public 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;
}