Skip to content

Instantly share code, notes, and snippets.

@FlaShG
Last active August 19, 2021 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlaShG/319e254995d48a986e87dfbc4c1d771c to your computer and use it in GitHub Desktop.
Save FlaShG/319e254995d48a986e87dfbc4c1d771c to your computer and use it in GitHub Desktop.
Temprarily set a color to be used for Gizmos and Handles.
using UnityEngine;
using System;
/// <summary>
/// Temporarily 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>
/// Temporarily 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