Skip to content

Instantly share code, notes, and snippets.

@Suzeep
Last active November 4, 2016 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suzeep/bd527d84a8a01aef2aaa103fde574e5a to your computer and use it in GitHub Desktop.
Save Suzeep/bd527d84a8a01aef2aaa103fde574e5a to your computer and use it in GitHub Desktop.
AdvancedInspectorでMultilineAttributeを指定したstringの配列・リストが属性反映されてないので無理やり反映させた。StringEditor.csを以下のように編集。
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
namespace AdvancedInspector
{
public class StringEditor : FieldEditor
{
public override Type[] EditedTypes
{
get { return new Type[] { typeof(string) }; }
}
public override void Draw(InspectorField field, GUIStyle style)
{
GUILayout.BeginHorizontal();
float width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 0;
TextFieldAttribute text = field.GetAttribute<TextFieldAttribute>();
MultilineAttribute multiline = field.GetAttribute<MultilineAttribute>();
TextAreaAttribute area = field.GetAttribute<TextAreaAttribute>();
object value = GetValue(field);
EditorGUI.BeginChangeCheck();
GUIUtility.GetControlID(field.Path.GetHashCode(), FocusType.Passive);
string result = "";
// 追加した処理
#if true
bool isArrayMultiline = false;
if( field.Parent != null )
{ // ParentのAttributesに指定した属性が保持されてるようなのでチェック
var attrs = field.Parent.Attributes;
for( int i=0; i < attrs.Length; ++i ){
if( attrs[i].GetType() == typeof(UnityEngine.MultilineAttribute) ){
isArrayMultiline = true;
}
}
}
// ArrayかListのMultilineの場合はテキストエリアの描画処理をさせる
if( isArrayMultiline )
{
if (style != null)
result = EditorGUILayout.TextArea((string)value, style);
else
result = EditorGUILayout.TextArea((string)value);
}
else if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
#else
if ((text == null && multiline == null && area == null) || (text != null && text.Type == TextFieldType.Standard))
#endif
{
if (style != null)
result = EditorGUILayout.TextField((string)value, style);
else
result = EditorGUILayout.TextField((string)value);
}
else if (multiline != null || area != null || text.Type == TextFieldType.Area)
{
if (style != null)
result = EditorGUILayout.TextArea((string)value, style);
else
result = EditorGUILayout.TextArea((string)value);
}
else if (text.Type == TextFieldType.Password)
{
if (style != null)
result = EditorGUILayout.PasswordField((string)value, style);
else
result = EditorGUILayout.PasswordField((string)value);
}
else if (text.Type == TextFieldType.Tag)
{
if (style != null)
result = EditorGUILayout.TagField((string)value, style);
else
result = EditorGUILayout.TagField((string)value);
}
else if (text.Type == TextFieldType.File)
{
if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
result = EditorUtility.OpenFilePanel(text.Title, text.Path, text.Extension);
if (field.Mixed)
GUILayout.Label("---");
else
GUILayout.Label((string)value);
}
else if (text.Type == TextFieldType.Folder)
{
if (GUILayout.Button("...", GUILayout.Height(BUTTON_HEIGHT), GUILayout.Width(BUTTON_HEIGHT * 2)))
result = EditorUtility.OpenFolderPanel(text.Title, "", "");
if (field.Mixed)
GUILayout.Label("---");
else
GUILayout.Label((string)value);
}
if (EditorGUI.EndChangeCheck())
field.SetValue(result);
EditorGUIUtility.labelWidth = width;
GUILayout.EndHorizontal();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment