Skip to content

Instantly share code, notes, and snippets.

@FlaShG FlaShG/GizmosColor.cs
Last active Oct 9, 2019

Embed
What would you like to do?
Temprarily set a color to be used for Gizmos and Handles.
using UnityEngine;
using System;
/// <summary>
/// Temprarily set a color to be used for Gizmos.
/// <example>
/// <code>
/// using (new GizmosColor(Color.red))
/// {
/// Gizmos.DrawSphere(transform.position, 1f);
/// }
/// </code>
/// </example>
/// </summary>
public struct GizmosColor : IDisposable
{
private Color colorBefore;
public GizmosColor(Color color)
{
colorBefore = Gizmos.color;
Gizmos.color = color;
}
public void Dispose()
{
Gizmos.color = colorBefore;
}
}
using UnityEngine;
using UnityEditor;
using System;
/// <summary>
/// Temprarily set a color to be used for Handles.
/// <example>
/// <code>
/// using (new HandlesColor(Color.red))
/// {
/// Handles.Label(transform.position, gameObject.name);
/// }
/// </code>
/// </example>
/// </summary>
public struct HandlesColor : IDisposable
{
private Color colorBefore;
public HandlesColor(Color color)
{
colorBefore = Handles.color;
Handles.color = color;
}
public void Dispose()
{
Handles.color = colorBefore;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.