Last active
August 19, 2021 18:52
-
-
Save FlaShG/319e254995d48a986e87dfbc4c1d771c to your computer and use it in GitHub Desktop.
Temprarily set a color to be used for Gizmos and Handles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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