3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity3Dで、ラベルの色も変えつつ、EditorStyles.numberFiledみたいな見た目にする。

Last updated at Posted at 2013-08-07

EditorWindowから継承した自作のエディタクラスにおいて、
EditorGUILayout.LabelFieldを表示して、スタイルはEditorStyles.numberFieldを指定していたけれども、
文字色を変えたくなったので無理矢理変えてみた。

そのときのコードが以下。

Editor/MyStyle.cs
using UnityEngine;
using UnityEditor;

public class MyStyle : EditorWindow {
	// メニューの表示
	[MenuItem("Window/MyStyleTest")]
	static void CreateWindow(){  // メソッド名はなんでもOKっぽい。
		MyStyle window = (MyStyle)EditorWindow.GetWindow(typeof(MyStyle)); 
		window.title = "MyStyle Test"; 
		window.maxSize = new Vector2(200f, 300f); // サイズは適当
		window.minSize = new Vector2(80f, 150f);
	}

	// エディタウィンドウの描画
	public void OnGUI(){ 
		GUIStyle myStyle = new GUIStyle();
		// myStyleにEditorStyles.numberFieldから必要な値をコピーする。		
		GUIStyle style = EditorStyles.numberField;
		myStyle.border = style.border;
		myStyle.contentOffset = style.contentOffset;			
		myStyle.normal.background = style.normal.background;
		myStyle.padding = style.padding;
		// 文字色を変更
		myStyle.normal.textColor = Color.green;
		EditorGUILayout.LabelField("Label", "Test", myStyle);
	}
}

これを、Assets/Editorフォルダにいれると、メニューにWindow->MyStyleTestが追加される。
メニューを選択すると、自作エディタウィンドウが表示される。

スクリーンショット 0025-08-07 21.38.41.png

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?