ソースコード
using System;
using UnityEditor;
public sealed class LabelWidthScope : IDisposable
{
private readonly float m_oldLabelWidth;
public LabelWidthScope( int labelWidth )
{
m_oldLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = labelWidth;
}
public void Dispose()
{
EditorGUIUtility.labelWidth = m_oldLabelWidth;
}
}
使用例
using UnityEditor;
public sealed class Example : EditorWindow
{
[MenuItem( "Tools/Hoge" )]
private static void Open()
{
GetWindow<Example>();
}
private void OnGUI()
{
EditorGUILayout.TextField( "Name", "ピカチュウ" );
using ( new LabelWidthScope( 32 ) )
{
EditorGUILayout.TextField( "Name", "カイリュー" );
}
}
}
![f:id:baba_s:20200825220621p:plain](https://cdn-ak.f.st-hatena.com/images/fotolife/b/baba_s/20200825/20200825220621.png)