Unity 6.3
0 онлайн 63 гостей 3 в системе
Вход

CustomPivotAttribute

класс в UnityEditor.EditorTools

Описание

Зарегистрирует 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;
}

Статические свойства

Свойство Описание
defaultPriorityЗначение по умолчанию для CustomPivotAttribute.priority. Укажите приоритет ниже этого значения, чтобы отобразить параметр pivot перед записями по умолчанию, или укажите более высокое значение, чтобы отобразить его после записей по умолчанию.

Свойства

Свойство Описание
displayNameИмя, которое будет отображаться для этой настройки в редакторе UI.
priorityПриоритет определяет порядок отображения настроек поворота в выпадающих меню накладки Инструменты — Настройки.
targetToolЕсли указано, то настройка pivot доступна только тогда, когда ToolManager.activeToolType равен targetTool.
targetToolContextЕсли указано, то настройка pivot доступна только тогда, когда ToolManager.activeContextType равен targetToolContext.
tooltiptooltip для отображения в редакторе UI для этой настройки pivot.

Конструкторы

Конструктор Описание
CustomPivotAttributeЗарегистрирует CustomPivotMode или CustomPivotRotation в качестве дополнительной опции к встроенным в Редактор настройкам режима поворота или вращения.