# EditorToolAttribute

> Registers an EditorTool as either a Global tool or a Component tool for a specific target type.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.EditorTools](/engine/6000.0/script-reference/unityeditor/editortools.md)
* **Assembly:** UnityEditor
* **Inherits from:** [ToolAttribute](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute.md)
* **Implements:** [\_Attribute](https://learn.microsoft.com/dotnet/api/system.runtime.interopservices._attribute)

```csharp
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class EditorToolAttribute : ToolAttribute, _Attribute
```

## Remarks

A Global tool works on any selection. A Global tool is also always available from the top toolbar. A Component tool, like a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md), is only available for selections that match a target type.

```csharp
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;

public static class Drawing
{
    public static void DrawPoints(Transform transform, IList<Vector3> positions, Color color, float size)
    {
        if (positions == null || !positions.Any())
            return;

        var matrix = transform.localToWorldMatrix;
        DrawHandleCaps(matrix, positions, color * .3f, size, CompareFunction.Greater);
        DrawHandleCaps(matrix, positions, color, size, CompareFunction.LessEqual);
    }

    public static void DrawHandleCaps(Matrix4x4 transform, IList<Vector3> positions, Color color, float size, CompareFunction compare)
    {
        if (Event.current.type != EventType.Repaint)
            return;

        var camera = Camera.current;

        Vector3 sideways = (camera == null ? Vector3.right : camera.transform.right);
        Vector3 up = (camera == null ? Vector3.up : camera.transform.up);

        var prevColor = Handles.color;
        Handles.color = color;

        var prevCompare = Handles.zTest;
        Handles.zTest = compare;
        var world = transform.MultiplyPoint3x4(positions[0]);

        // DotHandleCap call sets up the material and GL state, so just re-use it to avoid expensive setup for each quad
        // Done this way because HandleUtility.ApplyWireMaterial is private
        Handles.DotHandleCap(0, world, Quaternion.identity, HandleUtility.GetHandleSize(world) * size, EventType.Repaint);
        GL.Begin(GL.QUADS);

        foreach (var p in positions)
        {
            var position = transform.MultiplyPoint(p);
            var handleSize = HandleUtility.GetHandleSize(position) * size;

            GL.Color(color);
            GL.Vertex(position + (sideways + up) * handleSize);
            GL.Vertex(position + (sideways - up) * handleSize);
            GL.Vertex(position - (sideways + up) * handleSize);
            GL.Vertex(position - (sideways - up) * handleSize);
        }

        GL.End();
        Handles.color = prevColor;
        Handles.zTest = prevCompare;
    }
}
```

You can also use tool variants to group similar tools into a single button in the Tools overlay. Refer to [ToolAttribute.variantGroup](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/variantgroup.md).

```csharp
using System;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

namespace GlobalToolVariants
{
    // Define 3 tools that should be shown as a single button in the Tools Overlay.
    struct ShapeVariantGroup {}

    [EditorTool("Line (Custom Global)", variantGroup = typeof(ShapeVariantGroup), variantPriority = 2)]
    [Icon("Assets/Examples/Icons/Variant-Line.png")]
    class Line : EditorTool {}

    [EditorTool("Circle (Custom Global)", variantGroup = typeof(ShapeVariantGroup), variantPriority = 1)]
    [Icon("Assets/Examples/Icons/Variant-Circle.png")]
    class Circle : EditorTool {}

    [EditorTool("Square (Custom Global)", variantGroup = typeof(ShapeVariantGroup), variantPriority = 0)]
    [Icon("Assets/Examples/Icons/Variant-Square.png")]
    class Square : EditorTool {}
}
```

## Constructors

| Constructor                                                                                                                                                                                                                                  | Description                                                                                                                                                                                                     |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [EditorToolAttribute(System.String,System.Type)](/engine/6000.0/script-reference/unityeditor/editortools/editortoolattribute/ctor.md#editortoolattribute\(string-type\))                                                                     | Registers an [EditorTool](/engine/6000.0/script-reference/unityeditor/editortools/editortool.md) as either a Global tool or a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md) tool. |
| [EditorToolAttribute(System.String,System.Type,System.Type)](/engine/6000.0/script-reference/unityeditor/editortools/editortoolattribute/ctor.md#editortoolattribute\(string-type-type\))                                                    | Registers an [EditorTool](/engine/6000.0/script-reference/unityeditor/editortools/editortool.md) as either a Global tool or a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md) tool. |
| [EditorToolAttribute(System.String,System.Type,System.Type,System.Int32,System.Type)](/engine/6000.0/script-reference/unityeditor/editortools/editortoolattribute/ctor.md#editortoolattribute\(string-type-type-int-type\))                  | Registers an [EditorTool](/engine/6000.0/script-reference/unityeditor/editortools/editortool.md) as either a Global tool or a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md) tool. |
| [EditorToolAttribute(System.String,System.Type,System.Type,System.Int32,System.Type,System.Int32)](/engine/6000.0/script-reference/unityeditor/editortools/editortoolattribute/ctor.md#editortoolattribute\(string-type-type-int-type-int\)) | Registers an [EditorTool](/engine/6000.0/script-reference/unityeditor/editortools/editortool.md) as either a Global tool or a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md) tool. |
| [EditorToolAttribute(System.String,System.Type,System.Type,System.Type)](/engine/6000.0/script-reference/unityeditor/editortools/editortoolattribute/ctor.md#editortoolattribute\(string-type-type-type\))                                   | Registers an [EditorTool](/engine/6000.0/script-reference/unityeditor/editortools/editortool.md) as either a Global tool or a [CustomEditor](/engine/6000.0/script-reference/unityeditor/customeditor.md) tool. |

## Inheritance

**Inherited Members:**

* [ToolAttribute.defaultPriority](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/defaultpriority.md)
* [ToolAttribute.displayName](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/displayname.md)
* [ToolAttribute.targetType](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/targettype.md)
* [ToolAttribute.targetContext](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/targetcontext.md)
* [ToolAttribute.toolPriority](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/toolpriority.md)
* [ToolAttribute.variantGroup](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/variantgroup.md)
* [ToolAttribute.variantPriority](/engine/6000.0/script-reference/unityeditor/editortools/toolattribute/variantpriority.md)
* [Attribute.GetCustomAttributes(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttributes(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(MemberInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo\))
* [Attribute.GetCustomAttributes(MemberInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-memberinfo-system-boolean\))
* [Attribute.IsDefined(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type\))
* [Attribute.IsDefined(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(MemberInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type\))
* [Attribute.GetCustomAttribute(MemberInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-memberinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttributes(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(ParameterInfo, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-parameterinfo-system-boolean\))
* [Attribute.IsDefined(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type\))
* [Attribute.IsDefined(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type\))
* [Attribute.GetCustomAttribute(ParameterInfo, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-parameterinfo-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttributes(Module)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module\))
* [Attribute.GetCustomAttributes(Module, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-boolean\))
* [Attribute.GetCustomAttributes(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-module-system-type-system-boolean\))
* [Attribute.IsDefined(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type\))
* [Attribute.IsDefined(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Module, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type\))
* [Attribute.GetCustomAttribute(Module, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-module-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttributes(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttributes(Assembly)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly\))
* [Attribute.GetCustomAttributes(Assembly, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattributes#system-attribute-getcustomattributes\(system-reflection-assembly-system-boolean\))
* [Attribute.IsDefined(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type\))
* [Attribute.IsDefined(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.isdefined#system-attribute-isdefined\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.GetCustomAttribute(Assembly, Type)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type\))
* [Attribute.GetCustomAttribute(Assembly, Type, bool)](https://learn.microsoft.com/dotnet/api/system.attribute.getcustomattribute#system-attribute-getcustomattribute\(system-reflection-assembly-system-type-system-boolean\))
* [Attribute.Equals(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.equals)
* [Attribute.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.attribute.gethashcode)
* [Attribute.Match(Object)](https://learn.microsoft.com/dotnet/api/system.attribute.match)
* [Attribute.IsDefaultAttribute()](https://learn.microsoft.com/dotnet/api/system.attribute.isdefaultattribute)
* [Attribute.TypeId()](https://learn.microsoft.com/dotnet/api/system.attribute.typeid)
