2021-12-07 10:20:36 -05:00
|
|
|
|
using TriInspector.Utilities;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Elements
|
|
|
|
|
{
|
|
|
|
|
internal class TriFoldoutElement : TriPropertyCollectionBaseElement
|
|
|
|
|
{
|
|
|
|
|
private readonly TriProperty _property;
|
|
|
|
|
|
|
|
|
|
public TriFoldoutElement(TriProperty property)
|
|
|
|
|
{
|
|
|
|
|
_property = property;
|
|
|
|
|
|
|
|
|
|
DeclareGroups(property.ValueType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Update()
|
|
|
|
|
{
|
|
|
|
|
var dirty = false;
|
|
|
|
|
|
|
|
|
|
if (_property.IsExpanded)
|
|
|
|
|
{
|
|
|
|
|
dirty |= GenerateChildren();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dirty |= ClearChildren();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dirty |= base.Update();
|
|
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override float GetHeight(float width)
|
|
|
|
|
{
|
|
|
|
|
var height = EditorGUIUtility.singleLineHeight;
|
|
|
|
|
|
|
|
|
|
if (!_property.IsExpanded)
|
|
|
|
|
{
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
height += base.GetHeight(width);
|
|
|
|
|
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnGUI(Rect position)
|
|
|
|
|
{
|
|
|
|
|
var headerRect = new Rect(position)
|
|
|
|
|
{
|
|
|
|
|
height = EditorGUIUtility.singleLineHeight,
|
|
|
|
|
};
|
|
|
|
|
var contentRect = new Rect(position)
|
|
|
|
|
{
|
|
|
|
|
yMin = position.yMin + headerRect.height,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TriEditorGUI.Foldout(headerRect, _property);
|
|
|
|
|
|
|
|
|
|
if (!_property.IsExpanded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 02:39:14 -05:00
|
|
|
|
using (TriGuiHelper.PushIndentLevel())
|
|
|
|
|
{
|
|
|
|
|
base.OnGUI(contentRect);
|
|
|
|
|
}
|
2021-12-07 10:20:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool GenerateChildren()
|
|
|
|
|
{
|
|
|
|
|
if (ChildrenCount != 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var childProperty in _property.ChildrenProperties)
|
|
|
|
|
{
|
|
|
|
|
AddProperty(childProperty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ClearChildren()
|
|
|
|
|
{
|
|
|
|
|
if (ChildrenCount == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoveAllChildren();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|