Move some elements to core asm

This commit is contained in:
VladV 2022-01-10 11:12:44 +03:00
parent 063c18a189
commit d9b3c97f6d
7 changed files with 203 additions and 189 deletions

View File

@ -1,7 +1,6 @@
using TriInspector;
using TriInspector.Drawers;
using TriInspector.Elements;
using TriInspector.GroupDrawers;
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
@ -26,9 +25,9 @@ namespace TriInspector.Drawers
return stack;
}
var element = new TriBoxGroupDrawer.TriBoxGroupElement(new DeclareBoxGroupAttribute(""));
var element = new TriBoxGroupElement(new DeclareBoxGroupAttribute(""));
element.AddChild(new ObjectReferenceFoldoutDrawerElement(property));
element.AddChild(new InlineEditorDrawerElement(property));
element.AddChild(new InlineEditorElement(property));
return element;
}
@ -79,115 +78,5 @@ namespace TriInspector.Drawers
}
}
}
private class InlineEditorDrawerElement : TriElement
{
private readonly TriProperty _property;
private Editor _editor;
private Rect _editorPosition;
private bool _dirty;
public InlineEditorDrawerElement(TriProperty property)
{
_property = property;
_editorPosition = Rect.zero;
}
protected override void OnDetachFromPanel()
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
base.OnDetachFromPanel();
}
public override bool Update()
{
if (_editor == null || _editor.target != (Object) _property.Value)
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
_dirty = true;
}
if (_dirty)
{
_dirty = false;
return true;
}
return false;
}
public override float GetHeight(float width)
{
if (_property.IsExpanded && !_property.IsValueMixed)
{
return _editorPosition.height;
}
return 0f;
}
public override void OnGUI(Rect position)
{
if (Event.current.type == EventType.Repaint)
{
_editorPosition = position;
}
var lastEditorRect = Rect.zero;
if (TriEditor.IsEditorForObjectPushed((Object) _property.Value))
{
GUI.Label(position, "Recursive inline editors not supported");
lastEditorRect.height = EditorGUIUtility.singleLineHeight;
}
else
{
if (_editor == null)
{
_editor = Editor.CreateEditor((Object) _property.Value);
}
if (_editor != null && _property.IsExpanded && !_property.IsValueMixed)
{
Rect indentedEditorPosition;
using (TriGuiHelper.PushIndentLevel())
{
indentedEditorPosition = EditorGUI.IndentedRect(_editorPosition);
}
GUILayout.BeginArea(indentedEditorPosition);
GUILayout.BeginVertical();
_editor.OnInspectorGUI();
GUILayout.EndVertical();
lastEditorRect = GUILayoutUtility.GetLastRect();
GUILayout.EndArea();
}
else
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
}
}
if (Event.current.type == EventType.Repaint &&
!Mathf.Approximately(_editorPosition.height, lastEditorRect.height))
{
_editorPosition.height = lastEditorRect.height;
_dirty = true;
_property.PropertyTree.RequestRepaint();
}
}
}
}
}

View File

@ -1,9 +1,6 @@
using TriInspector;
using TriInspector.Elements;
using TriInspector.GroupDrawers;
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
[assembly: RegisterTriGroupDrawer(typeof(TriBoxGroupDrawer))]
@ -15,77 +12,5 @@ namespace TriInspector.GroupDrawers
{
return new TriBoxGroupElement(attribute);
}
public class TriBoxGroupElement : TriPropertyCollectionBaseElement
{
private const float HeaderWidth = 22;
private const float InsetTop = 4;
private const float InsetBottom = 4;
private const float InsetLeft = 4;
private const float InsetRight = 4;
private readonly GUIContent _headerLabel;
public TriBoxGroupElement(DeclareBoxGroupAttribute attribute)
{
_headerLabel = attribute.Title == null
? GUIContent.none
: new GUIContent(attribute.Title);
}
public override float GetHeight(float width)
{
var height = base.GetHeight(width) + InsetTop + InsetBottom;
if (_headerLabel != GUIContent.none)
{
height += HeaderWidth;
}
return height;
}
public override void OnGUI(Rect position)
{
var headerBgRect = new Rect(position)
{
height = _headerLabel != GUIContent.none ? HeaderWidth : 0,
};
var headerLabelRect = new Rect(headerBgRect)
{
xMin = headerBgRect.xMin + 6,
xMax = headerBgRect.xMax - 6,
yMin = headerBgRect.yMin + 2,
yMax = headerBgRect.yMax - 2,
};
var contentBgRect = new Rect(position)
{
yMin = headerBgRect.yMax,
};
var contentRect = new Rect(contentBgRect)
{
xMin = contentBgRect.xMin + InsetLeft,
xMax = contentBgRect.xMax - InsetRight,
yMin = contentBgRect.yMin + InsetTop,
yMax = contentBgRect.yMax - InsetBottom,
};
if (_headerLabel != GUIContent.none)
{
TriEditorGUI.DrawBox(headerBgRect, TriEditorStyles.HeaderBox);
EditorGUI.LabelField(headerLabelRect, _headerLabel);
TriEditorGUI.DrawBox(contentBgRect, TriEditorStyles.ContentBox);
}
else
{
TriEditorGUI.DrawBox(contentBgRect, TriEditorStyles.Box);
}
using (TriGuiHelper.PushLabelWidth(EditorGUIUtility.labelWidth - InsetLeft))
{
base.OnGUI(contentRect);
}
}
}
}
}

View File

@ -0,0 +1,116 @@
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
namespace TriInspector.Elements
{
public class InlineEditorElement : TriElement
{
private readonly TriProperty _property;
private Editor _editor;
private Rect _editorPosition;
private bool _dirty;
public InlineEditorElement(TriProperty property)
{
_property = property;
_editorPosition = Rect.zero;
}
protected override void OnDetachFromPanel()
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
base.OnDetachFromPanel();
}
public override bool Update()
{
if (_editor == null || _editor.target != (Object) _property.Value)
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
_dirty = true;
}
if (_dirty)
{
_dirty = false;
return true;
}
return false;
}
public override float GetHeight(float width)
{
if (_property.IsExpanded && !_property.IsValueMixed)
{
return _editorPosition.height;
}
return 0f;
}
public override void OnGUI(Rect position)
{
if (Event.current.type == EventType.Repaint)
{
_editorPosition = position;
}
var lastEditorRect = Rect.zero;
if (TriEditor.IsEditorForObjectPushed((Object) _property.Value))
{
GUI.Label(position, "Recursive inline editors not supported");
lastEditorRect.height = EditorGUIUtility.singleLineHeight;
}
else
{
if (_editor == null)
{
_editor = Editor.CreateEditor((Object) _property.Value);
}
if (_editor != null && _property.IsExpanded && !_property.IsValueMixed)
{
Rect indentedEditorPosition;
using (TriGuiHelper.PushIndentLevel())
{
indentedEditorPosition = EditorGUI.IndentedRect(_editorPosition);
}
GUILayout.BeginArea(indentedEditorPosition);
GUILayout.BeginVertical();
_editor.OnInspectorGUI();
GUILayout.EndVertical();
lastEditorRect = GUILayoutUtility.GetLastRect();
GUILayout.EndArea();
}
else
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
}
}
if (Event.current.type == EventType.Repaint &&
!Mathf.Approximately(_editorPosition.height, lastEditorRect.height))
{
_editorPosition.height = lastEditorRect.height;
_dirty = true;
_property.PropertyTree.RequestRepaint();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e5abb7004e824b6d87bae69c80c8df1d
timeCreated: 1641802293

View File

@ -0,0 +1,78 @@
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
namespace TriInspector.Elements
{
public class TriBoxGroupElement : TriPropertyCollectionBaseElement
{
private const float HeaderWidth = 22;
private const float InsetTop = 4;
private const float InsetBottom = 4;
private const float InsetLeft = 4;
private const float InsetRight = 4;
private readonly GUIContent _headerLabel;
public TriBoxGroupElement(DeclareBoxGroupAttribute attribute)
{
_headerLabel = attribute.Title == null
? GUIContent.none
: new GUIContent(attribute.Title);
}
public override float GetHeight(float width)
{
var height = base.GetHeight(width) + InsetTop + InsetBottom;
if (_headerLabel != GUIContent.none)
{
height += HeaderWidth;
}
return height;
}
public override void OnGUI(Rect position)
{
var headerBgRect = new Rect(position)
{
height = _headerLabel != GUIContent.none ? HeaderWidth : 0,
};
var headerLabelRect = new Rect(headerBgRect)
{
xMin = headerBgRect.xMin + 6,
xMax = headerBgRect.xMax - 6,
yMin = headerBgRect.yMin + 2,
yMax = headerBgRect.yMax - 2,
};
var contentBgRect = new Rect(position)
{
yMin = headerBgRect.yMax,
};
var contentRect = new Rect(contentBgRect)
{
xMin = contentBgRect.xMin + InsetLeft,
xMax = contentBgRect.xMax - InsetRight,
yMin = contentBgRect.yMin + InsetTop,
yMax = contentBgRect.yMax - InsetBottom,
};
if (_headerLabel != GUIContent.none)
{
TriEditorGUI.DrawBox(headerBgRect, TriEditorStyles.HeaderBox);
EditorGUI.LabelField(headerLabelRect, _headerLabel);
TriEditorGUI.DrawBox(contentBgRect, TriEditorStyles.ContentBox);
}
else
{
TriEditorGUI.DrawBox(contentBgRect, TriEditorStyles.Box);
}
using (TriGuiHelper.PushLabelWidth(EditorGUIUtility.labelWidth - InsetLeft))
{
base.OnGUI(contentRect);
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c7a787b7a5e844a2a12192a9d52984b0
timeCreated: 1641802243

View File

@ -75,7 +75,7 @@ namespace TriInspector
}
}
public static bool IsEditorForObjectPushed(Object targetObject)
internal static bool IsEditorForObjectPushed(Object targetObject)
{
foreach (var editor in EditorStack)
{