Fix incorrect TextArea attribute rendering

This commit is contained in:
VladV 2022-07-15 15:29:20 +03:00
parent a17cfcf39d
commit eb5a95c9d8
5 changed files with 20 additions and 83 deletions

View File

@ -26,6 +26,14 @@ using UnityEngine;
namespace TriInspector.Drawers
{
public class StringDrawer : BuiltinDrawerBase<string>
{
protected override string OnValueGUI(Rect position, GUIContent label, string value)
{
return EditorGUI.TextField(position, label, value);
}
}
public class BooleanDrawer : BuiltinDrawerBase<bool>
{
protected override bool OnValueGUI(Rect position, GUIContent label, bool value)

View File

@ -1,80 +0,0 @@
using TriInspector;
using TriInspector.Drawers;
using UnityEditor;
using UnityEngine;
[assembly: RegisterTriValueDrawer(typeof(StringDrawer), TriDrawerOrder.Fallback)]
namespace TriInspector.Drawers
{
public class StringDrawer : TriValueDrawer<string>
{
public override TriElement CreateElement(TriValue<string> value, TriElement next)
{
if (value.Property.TryGetSerializedProperty(out var serializedProperty))
{
return new StringSerializedPropertyDrawerElement(value.Property, serializedProperty);
}
return new StringDrawerElement(value);
}
private class StringDrawerElement : TriElement
{
private TriValue<string> _propertyValue;
public StringDrawerElement(TriValue<string> propertyValue)
{
_propertyValue = propertyValue;
}
public override float GetHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override void OnGUI(Rect position)
{
var value = _propertyValue.SmartValue;
EditorGUI.BeginChangeCheck();
value = EditorGUI.TextField(position, _propertyValue.Property.DisplayNameContent, value);
if (EditorGUI.EndChangeCheck())
{
_propertyValue.SmartValue = value;
}
}
}
private class StringSerializedPropertyDrawerElement : TriElement
{
private readonly TriProperty _property;
private readonly SerializedProperty _serializedProperty;
public StringSerializedPropertyDrawerElement(TriProperty property, SerializedProperty serializedProperty)
{
_property = property;
_serializedProperty = serializedProperty;
}
public override float GetHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
}
public override void OnGUI(Rect position)
{
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(position, _serializedProperty, _property.DisplayNameContent);
if (EditorGUI.EndChangeCheck())
{
_property.NotifyValueChanged();
}
}
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6e5a2105103347338b704022e9a860d4
timeCreated: 1639316821

View File

@ -0,0 +1,9 @@
using UnityEngine;
public class Styling_TextArea : ScriptableObject
{
public string simpleText;
[TextArea(10, 15)]
public string textArea;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 902c15a04330446fb0a38fb0d5282470
timeCreated: 1657887155