diff --git a/Editor.Extras/Drawers/InlineEditorDrawer.cs b/Editor.Extras/Drawers/InlineEditorDrawer.cs index d1a2cdb..170fce8 100644 --- a/Editor.Extras/Drawers/InlineEditorDrawer.cs +++ b/Editor.Extras/Drawers/InlineEditorDrawer.cs @@ -30,7 +30,12 @@ public override TriElement CreateElement(TriProperty property, TriElement next) titleMode = TriBoxGroupElement.TitleMode.Hidden, }); element.AddChild(new ObjectReferenceFoldoutDrawerElement(property)); - element.AddChild(new InlineEditorElement(property)); + element.AddChild(new InlineEditorElement(property, new InlineEditorElement.Props + { + mode = Attribute.Mode, + previewHeight = Attribute.PreviewHeight, + previewWidth = Attribute.PreviewWidth, + })); return element; } diff --git a/Editor/Elements/InlineEditorElement.cs b/Editor/Elements/InlineEditorElement.cs index 018688d..c8fea15 100644 --- a/Editor/Elements/InlineEditorElement.cs +++ b/Editor/Elements/InlineEditorElement.cs @@ -1,5 +1,4 @@ -using TriInspector.Utilities; -using TriInspectorUnityInternalBridge; +using TriInspectorUnityInternalBridge; using UnityEditor; using UnityEngine; @@ -8,13 +7,27 @@ namespace TriInspector.Elements public class InlineEditorElement : TriElement { private readonly TriProperty _property; + private readonly Props _props; private Editor _editor; private Rect _editorPosition; private bool _dirty; - public InlineEditorElement(TriProperty property) + [System.Serializable] + public struct Props + { + public InlineEditorModes mode; + public float previewWidth; + public float previewHeight; + + public bool DrawGUI => (mode & InlineEditorModes.GUIOnly) != 0; + public bool DrawHeader => (mode & InlineEditorModes.Header) != 0; + public bool DrawPreview => (mode & InlineEditorModes.Preview) != 0; + } + + public InlineEditorElement(TriProperty property, Props props = default) { _property = property; + _props = props; _editorPosition = Rect.zero; } @@ -82,9 +95,55 @@ public override void OnGUI(Rect position) if (_editor != null && shouldDrawEditor) { GUILayout.BeginArea(_editorPosition); - GUILayout.BeginVertical(); - _editor.OnInspectorGUI(); - GUILayout.EndVertical(); + GUILayout.BeginHorizontal(); + + if (_props.DrawHeader || _props.DrawGUI) + { + GUILayout.BeginVertical(); + + if (_props.DrawHeader) + { + GUILayout.BeginVertical(); + _editor.DrawHeader(); + GUILayout.EndVertical(); + } + + if (_props.DrawGUI) + { + GUILayout.BeginVertical(); + _editor.OnInspectorGUI(); + GUILayout.EndVertical(); + } + + GUILayout.EndVertical(); + } + + if (_props.DrawPreview && _editor.HasPreviewGUI()) + { + GUILayout.BeginVertical(); + + var horizontal = _props.DrawHeader || _props.DrawGUI; + + var previewOpts = horizontal + ? new[] {GUILayout.Width(_props.previewWidth), GUILayout.ExpandHeight(true),} + : new[] {GUILayout.ExpandWidth(true), GUILayout.Height(_props.previewHeight),}; + + var previewRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, previewOpts); + + previewRect.width = Mathf.Max(previewRect.width, 10); + previewRect.height = Mathf.Max(previewRect.height, 10); + + var guiEnabled = GUI.enabled; + GUI.enabled = true; + + _editor.DrawPreview(previewRect); + + GUI.enabled = guiEnabled; + + GUILayout.EndVertical(); + } + + GUILayout.EndHorizontal(); lastEditorRect = GUILayoutUtility.GetLastRect(); GUILayout.EndArea(); } diff --git a/Runtime/Attributes/InlineEditorAttribute.cs b/Runtime/Attributes/InlineEditorAttribute.cs index 44adc07..f0dbda0 100644 --- a/Runtime/Attributes/InlineEditorAttribute.cs +++ b/Runtime/Attributes/InlineEditorAttribute.cs @@ -8,5 +8,18 @@ namespace TriInspector [Conditional("UNITY_EDITOR")] public class InlineEditorAttribute : Attribute { + public InlineEditorModes Mode { get; set; } = InlineEditorModes.GUIOnly; + + public float PreviewWidth { get; set; } = 100; + public float PreviewHeight { get; set; } = 50; + + public InlineEditorAttribute() + { + } + + public InlineEditorAttribute(InlineEditorModes mode) + { + Mode = mode; + } } } \ No newline at end of file diff --git a/Runtime/InlineEditorModes.cs b/Runtime/InlineEditorModes.cs new file mode 100644 index 0000000..dac6acb --- /dev/null +++ b/Runtime/InlineEditorModes.cs @@ -0,0 +1,16 @@ +using System; + +namespace TriInspector +{ + [Flags] + public enum InlineEditorModes + { + GUIOnly = 1 << 0, + Header = 1 << 1, + Preview = 1 << 2, + + GUIAndPreview = GUIOnly | Preview, + GUIAndHeader = GUIOnly | Header, + FullEditor = GUIOnly | Header | Preview, + } +} \ No newline at end of file diff --git a/Runtime/InlineEditorModes.cs.meta b/Runtime/InlineEditorModes.cs.meta new file mode 100644 index 0000000..0b5dce3 --- /dev/null +++ b/Runtime/InlineEditorModes.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f798a09b97da4ed09b5b962c0dbdba0e +timeCreated: 1712392526 \ No newline at end of file