This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ResizableTextAreaPropertyDrawer.cs
2020-07-09 11:41:01 -07:00

35 lines
1.2 KiB
C#

using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(ResizableTextAreaAttribute))]
public class ResizableTextAreaPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
EditorDrawUtility.DrawHeader(property);
if (property.propertyType == SerializedPropertyType.String)
{
EditorGUILayout.LabelField(property.displayName);
EditorGUI.BeginChangeCheck();
string textAreaValue = EditorGUILayout.TextArea(property.stringValue, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3f));
if (EditorGUI.EndChangeCheck())
{
property.stringValue = textAreaValue;
}
}
else
{
string warning = PropertyUtility.GetAttribute<ResizableTextAreaAttribute>(property).GetType().Name + " can only be used on string fields";
EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property));
EditorDrawUtility.DrawPropertyField(property);
}
}
}
}