[Unityエディター拡張] テキスト入力

ヨメレバCSS
オリジナルCSS

テキストを入力するフィールドを作成します。

テキスト入力

TextFieldを使用して、テキストを入力するフィールドを作成します。

EditorGUILayoutSample obj = target as EditorGUILayoutSample;
obj.name = EditorGUILayout.TextField ("name", obj.name);

とすると、

2_2_textfield

というフィールドが作成されます。

戻り値で入力されている値が返ってくるので、それをtargetに設定します。

テキスト入力(複数行)

TextFieldは一行でしたが、TextAreaを使用すると複数行のフィールドが作成されます。

EditorGUILayoutSample obj = target as EditorGUILayoutSample;
obj.address = EditorGUILayout.TextArea (obj.address);

とすると、

2_2_textarea1

となります。

これだけだと一行だけですが、

2_2_textarea2

というように複数行の入力ができます。

第二引数にGUILayout.Heightを渡すことで、

obj.address = EditorGUILayout.TextArea (obj.address, GUILayout.Height (50));

2_2_textarea3

というように初期のテキストエリアの高さが変更できます。

パスワード入力

パスワード用に、入力した文字が表示されないフィールドが必要な場合はPasswordFieldを使用します。

EditorGUILayoutSample obj = target as EditorGUILayoutSample;
obj.password = EditorGUILayout.PasswordField ("password", obj.password);

これは入力した文字が「*」で表示されるフィールドになります。

2_2_password

スポンサーリンク
GoogleAdSence レクタングル(大)

シェアする

スポンサーリンク
GoogleAdSence レクタングル(大)