Version: 2020.3
LanguageEnglish
  • C#

EditorTool

class in UnityEditor.EditorTools

/

Inherits from:ScriptableObject

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Use this class to implement custom editor tools. This is the base class from which all editor tools are inherited.

Use this class with EditorToolAttribute to register custom editor tools with the Editor.

using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.EditorTools;

// Tagging a class with the EditorTool attribute and no target type registers a global tool. Global tools are valid for any selection, and are accessible through the top left toolbar in the editor. [EditorTool("Platform Tool")] class PlatformTool : EditorTool { // Serialize this value to set a default value in the Inspector. [SerializeField] Texture2D m_ToolIcon;

GUIContent m_IconContent;

void OnEnable() { m_IconContent = new GUIContent() { image = m_ToolIcon, text = "Platform Tool", tooltip = "Platform Tool" }; }

public override GUIContent toolbarIcon { get { return m_IconContent; } }

// This is called for each window that your tool is active in. Put the functionality of your tool here. public override void OnToolGUI(EditorWindow window) { EditorGUI.BeginChangeCheck();

Vector3 position = Tools.handlePosition;

using (new Handles.DrawingScope(Color.green)) { position = Handles.Slider(position, Vector3.right); }

if (EditorGUI.EndChangeCheck()) { Vector3 delta = position - Tools.handlePosition;

Undo.RecordObjects(Selection.transforms, "Move Platform");

foreach (var transform in Selection.transforms) transform.position += delta; } } }

Properties

targetThe object being inspected.
targetsAn array of the objects being inspected.
toolbarIconThe icon and tooltip for this custom editor tool. If this function is not implemented, the toolbar displays the Inspector icon for the target type. If no target type is defined, the toolbar displays the Tool Mode icon.

Public Methods

IsAvailableChecks whether the custom editor tool is available based on the state of the editor.
OnActivatedInvoked after this EditorTool becomes the active tool.
OnToolGUIUse this method to implement a custom editor tool.
OnWillBeDeactivatedInvoked before this EditorTool stops being the active tool.

Inherited Members

Properties

hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the object.

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
CreateInstanceCreates an instance of a scriptable object.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.

Messages

AwakeThis function is called when the ScriptableObject script is started.
OnDestroyThis function is called when the scriptable object will be destroyed.
OnDisableThis function is called when the scriptable object goes out of scope.
OnEnableThis function is called when the object is loaded.
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
ResetReset to default values.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961