Tri-Inspector/Editor/Elements/TriInlineGenericElement.cs

47 lines
1.2 KiB
C#
Raw Normal View History

using System;
using TriInspector.Utilities;
2021-12-07 10:20:36 -05:00
using UnityEditor;
using UnityEngine;
namespace TriInspector.Elements
{
internal class TriInlineGenericElement : TriPropertyCollectionBaseElement
{
private readonly Props _props;
2021-12-07 10:20:36 -05:00
private readonly TriProperty _property;
[Serializable]
public struct Props
{
public bool drawPrefixLabel;
public float labelWidth;
}
public TriInlineGenericElement(TriProperty property, Props props = default)
2021-12-07 10:20:36 -05:00
{
_property = property;
_props = props;
2021-12-07 10:20:36 -05:00
DeclareGroups(property.ValueType);
foreach (var childProperty in property.ChildrenProperties)
{
AddProperty(childProperty);
}
}
public override void OnGUI(Rect position)
{
if (_props.drawPrefixLabel)
2021-12-07 10:20:36 -05:00
{
var controlId = GUIUtility.GetControlID(FocusType.Passive);
position = EditorGUI.PrefixLabel(position, controlId, _property.DisplayNameContent);
}
using (TriGuiHelper.PushLabelWidth(_props.labelWidth))
2022-01-10 02:39:14 -05:00
{
base.OnGUI(position);
}
2021-12-07 10:20:36 -05:00
}
}
}