Makes InspectorElement creation lazy to avoid tree generation on validation

This commit is contained in:
VladV 2022-05-29 14:04:20 +03:00
parent acdcb60456
commit 2b389d9323

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using TriInspector.Elements;
using UnityEditor;
using UnityEngine;
@ -8,7 +9,7 @@ namespace TriInspector
{
public abstract class TriPropertyTree : ITriPropertyParent
{
private TriInspectorElement _inspectorElement;
[CanBeNull] private TriInspectorElement _inspectorElement;
public IReadOnlyList<TriProperty> Properties { get; protected set; }
@ -21,22 +22,17 @@ namespace TriInspector
public void Initialize()
{
_inspectorElement = new TriInspectorElement(TargetObjectType, Properties);
_inspectorElement.AttachInternal();
Update();
RunValidation();
}
public virtual void Dispose()
{
if (!_inspectorElement.IsAttached)
if (_inspectorElement != null && _inspectorElement.IsAttached)
{
return;
}
_inspectorElement.DetachInternal();
}
}
public virtual void Update()
{
@ -62,6 +58,12 @@ namespace TriInspector
{
RepaintRequired = false;
if (_inspectorElement == null)
{
_inspectorElement = new TriInspectorElement(TargetObjectType, Properties);
_inspectorElement.AttachInternal();
}
_inspectorElement.Update();
var width = EditorGUIUtility.currentViewWidth;
var height = _inspectorElement.GetHeight(width);