DrawGizmo Manual     Reference     Scripting  
Scripting > Editor Classes > DrawGizmo
DrawGizmo Class, inherits from System.Attribute

The DrawGizmo attribute allows you to supply a gizmo renderer for any Component.

Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.

At the moment you can only supply gizmo drawers for engine-components. All gizmo drawing methods need to be static.

/// The RenderLightGizmo function will be called if the light is not selected.
/// The gizmo is drawn when picking.
@DrawGizmo (GizmoType.NotSelected | GizmoType.Pickable)
static function RenderLightGizmo (light : Light, gizmoType : GizmoType)
{
var position = light.transform.position;
// Draw the light icon
// (A bit above the one drawn by the builtin light gizmo renderer)
Gizmos.DrawIcon (position + Vector3.up, "Light Gizmo.tiff");

// Are we selected? Draw a solid sphere surrounding the light
if ((gizmoType & GizmoType.SelectedOrChild) != 0)
{
// Indicate that this is the active object by using a brighter color.
if ((gizmoType & GizmoType.Active) != 0)
Gizmos.color = Color.red;
else
Gizmos.color = Color.red * 0.5;
Gizmos.DrawSphere (position, light.range);
}
}

/*
// Draw the gizmo if it is selected or a child of the selection.
// This is the most common way to render a gizmo
@DrawGizmo (GizmoType.SelectedOrChild)

// Draw the gizmo only if it is the active object.
@DrawGizmo (GizmoType.Active)]
*/

/// C# example
using UnityEditor;
using UnityEngine;

class GizmoTest
{
/// The RenderLightGizmo function will be called if the light is not selected.
/// The gizmo is drawn when picking.
[DrawGizmo (GizmoType.NotSelected | GizmoType.Pickable)]
static void RenderLightGizmo (Light light, GizmoType gizmoType)
{
Vector3 position = light.transform.position;
// Draw the light icon
// (A bit above the one drawn by the builtin light gizmo renderer)
Gizmos.DrawIcon (position + Vector3.up, "Light Gizmo.tiff");

// Are we selected? Draw a solid sphere surrounding the light
if ((gizmoType & GizmoType.SelectedOrChild) != 0)
{
// Indicate that this is the active object by using a brighter color.
if ((gizmoType & GizmoType.Active) != 0)
Gizmos.color = Color.red;
else
Gizmos.color = Color.red * 0.5F;
Gizmos.DrawSphere (position, light.range);
}
}
}
/*
// Draw the gizmo if it is selected or a child of the selection.
// This is the most common way to render a gizmo
[DrawGizmo (GizmoType.SelectedOrChild)]

// Draw the gizmo only if it is the active object.
[DrawGizmo (GizmoType.Active)]
*/

Constructors
DrawGizmo

Defines when the gizmo should be invoked for drawing.