2021-12-07 10:20:36 -05:00
|
|
|
|
using System;
|
|
|
|
|
using TriInspector.Elements;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TriInspector
|
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
public abstract class TriPropertyTree
|
2021-12-07 10:20:36 -05:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
private TriPropertyElement _rootPropertyElement;
|
2021-12-07 10:20:36 -05:00
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
public TriPropertyDefinition RootPropertyDefinition { get; protected set; }
|
|
|
|
|
public TriProperty RootProperty { get; protected set; }
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
|
|
|
|
public Type TargetObjectType { get; protected set; }
|
|
|
|
|
public int TargetsCount { get; protected set; }
|
|
|
|
|
public bool TargetIsPersistent { get; protected set; }
|
|
|
|
|
|
2022-05-29 07:07:15 -04:00
|
|
|
|
public bool ValidationRequired { get; private set; } = true;
|
|
|
|
|
public bool RepaintRequired { get; private set; } = true;
|
2021-12-07 10:20:36 -05:00
|
|
|
|
|
2022-05-29 07:41:40 -04:00
|
|
|
|
public int RepaintFrame { get; private set; } = 0;
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
public virtual void Dispose()
|
2021-12-07 10:20:36 -05:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
if (_rootPropertyElement != null && _rootPropertyElement.IsAttached)
|
2022-01-08 12:45:11 -05:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_rootPropertyElement.DetachInternal();
|
2022-01-08 12:45:11 -05:00
|
|
|
|
}
|
2021-12-07 10:20:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 03:18:13 -04:00
|
|
|
|
public virtual void Update(bool forceUpdate = false)
|
2021-12-07 10:20:36 -05:00
|
|
|
|
{
|
2022-05-29 07:41:40 -04:00
|
|
|
|
RepaintFrame++;
|
2021-12-07 10:20:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 03:18:13 -04:00
|
|
|
|
public virtual bool ApplyChanges()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
public void RunValidation()
|
2022-01-15 11:25:12 -05:00
|
|
|
|
{
|
2022-05-21 04:49:12 -04:00
|
|
|
|
ValidationRequired = false;
|
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
RootProperty.RunValidation();
|
2022-01-20 05:05:35 -05:00
|
|
|
|
|
2022-01-19 05:16:26 -05:00
|
|
|
|
RequestRepaint();
|
2022-01-15 11:25:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 10:59:35 -04:00
|
|
|
|
public void Draw(float? viewWidth = null)
|
2021-12-07 10:20:36 -05:00
|
|
|
|
{
|
2022-05-21 04:49:12 -04:00
|
|
|
|
RepaintRequired = false;
|
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
if (_rootPropertyElement == null)
|
2022-05-29 07:04:20 -04:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_rootPropertyElement = new TriPropertyElement(RootProperty, new TriPropertyElement.Props
|
|
|
|
|
{
|
|
|
|
|
forceInline = RootProperty.MemberInfo == null,
|
|
|
|
|
});
|
|
|
|
|
_rootPropertyElement.AttachInternal();
|
2022-05-29 07:04:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 03:35:33 -04:00
|
|
|
|
_rootPropertyElement.Update();
|
2022-07-03 10:59:35 -04:00
|
|
|
|
var width = viewWidth ?? EditorGUIUtility.currentViewWidth;
|
2022-06-01 03:35:33 -04:00
|
|
|
|
var height = _rootPropertyElement.GetHeight(width);
|
2021-12-07 10:20:36 -05:00
|
|
|
|
var rect = GUILayoutUtility.GetRect(width, height);
|
2022-06-01 03:35:33 -04:00
|
|
|
|
rect.xMin += 3;
|
|
|
|
|
_rootPropertyElement.OnGUI(rect);
|
2021-12-07 10:20:36 -05:00
|
|
|
|
}
|
2022-01-08 12:45:11 -05:00
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
public void EnumerateValidationResults(Action<TriProperty, TriValidationResult> call)
|
2022-05-18 02:20:51 -04:00
|
|
|
|
{
|
2022-06-01 03:35:33 -04:00
|
|
|
|
RootProperty.EnumerateValidationResults(call);
|
2022-05-11 04:54:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
public virtual void RequestRepaint()
|
2022-01-08 12:45:11 -05:00
|
|
|
|
{
|
|
|
|
|
RepaintRequired = true;
|
|
|
|
|
}
|
2022-01-15 11:25:12 -05:00
|
|
|
|
|
|
|
|
|
public void RequestValidation()
|
|
|
|
|
{
|
|
|
|
|
ValidationRequired = true;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
|
|
|
|
RequestRepaint();
|
2022-01-15 11:25:12 -05:00
|
|
|
|
}
|
2022-01-08 12:45:11 -05:00
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
public abstract void ForceCreateUndoGroup();
|
2022-05-17 06:33:23 -04:00
|
|
|
|
}
|
2021-12-07 10:20:36 -05:00
|
|
|
|
}
|