DrawGizmo
The DrawGizmo attribute allows you to supply a gizmo renderer for any Component.
Read time 4 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEditor
- Assembly: UnityEditor
- Inherits from: Attribute
- Implements: _Attribute
public sealed class DrawGizmo : Attribute, _Attribute
Remarks
The renderer function must be static, and take two parameters: the object for which the gizmo is being drawn, and a GizmoType parameter which indicates the context in which the gizmo is being drawn.
The renderer function can be defined in any class, including editor scripts. This allows you to keep your gizmo-drawing code out of your component scripts so that it is not included in builds.
Additional Resources: GizmoType.
Examples
using UnityEngine;using UnityEditor;public class MyScript : MonoBehaviour{}// The icon has to be stored in Assets/Gizmospublic class MyScriptGizmoDrawer{ [DrawGizmo(GizmoType.Selected | GizmoType.Active)] static void DrawGizmoForMyScript(MyScript scr, GizmoType gizmoType) { Vector3 position = scr.transform.position; if (Vector3.Distance(position, Camera.current.transform.position) > 10f) Gizmos.DrawIcon(position, "MyScript Gizmo.tiff"); }}
Constructors
Constructor | Description |
|---|---|
| DrawGizmo(UnityEditor.GizmoType) | Defines when the gizmo should be invoked for drawing. |
| DrawGizmo(UnityEditor.GizmoType,System.Type) | Same as above. drawnGizmoType determines of what type the object we are drawing the gizmo of has to be. |