ソースコード
using System;
using UnityEngine;
public sealed class GUIColorScope : IDisposable
{
private readonly Color m_oldColor;
public GUIColorScope( Color color )
{
m_oldColor = GUI.color;
GUI.color = color;
}
public void Dispose()
{
GUI.color = m_oldColor;
}
}
使用例
using UnityEditor;
using UnityEngine;
public class Example : EditorWindow
{
[MenuItem( "Tools/Hoge" )]
private static void Hoge()
{
GetWindow<Example>();
}
private void OnGUI()
{
GUILayout.Label( "ピカチュウ" );
using ( new GUIColorScope( Color.red ) )
{
GUILayout.Label( "カイリュー" );
}
GUILayout.Label( "ヤドラン" );
using ( new GUIColorScope( Color.green ) )
{
GUILayout.Label( "ピジョン" );
}
GUILayout.Label( "コダック" );
}
}