#Custom inspector title bar

1 messages · Page 1 of 1 (latest)

hearty tinsel
#

this is the example I had

#
using UnityEditor;
using UnityEngine;

public class ReplaceHeaderTitlebar : MonoBehaviour
{

}

[CustomEditor(typeof(ReplaceHeaderTitlebar))]
[CanEditMultipleObjects]
public class ReplaceHeaderTitlebarEditor : Editor
{
    public override void OnInspectorGUI()
    {
        DrawHeader();
        base.OnInspectorGUI();
    }

    protected override void OnHeaderGUI()
    {
        Rect titlebarRect = new Rect
        {
            x = 0,
            y = -22,
            width = EditorGUIUtility.currentViewWidth,
            height = 20
        };

        EditorGUI.InspectorTitlebar(titlebarRect, true, target, false);
    }
}
#

but I was just testing it out better, and I don't know how to prevent mouse clicks on the original title bar

#

because mouse events are only detected inside the editor area, and not on the title bar

#

@toxic jacinth any idea for how to solve this?

#

maybe it's possible with UITK?

toxic jacinth
#

is it drawing over the normal header? Or is it completely replacing it?

#

I don't override the OnheaderGUI very often so I don't remember what it does for components

hearty tinsel
#

drawing over

raw dragon
#

yeah, drawing over

toxic jacinth
#

And you want to...?

hearty tinsel
#

that's probably why OnHeaderGUI is not documented
to avoid confusion

raw dragon
#

that's why i hesitated to use this

hearty tinsel
raw dragon
#

yes, exactly. the same way it works for the Audio Listener component

toxic jacinth
#

And you said that OnheaderGUI doesn't receive input events?

hearty tinsel
hearty tinsel
#

but not outside the actual editor area

#

so when you click on the title bar, you can't receive it in the OnHeaderGUI method

toxic jacinth
#

A bit janky but you could force expand it if it is collapsed

hearty tinsel
#

ah that might work!

#
using System;
using System.Reflection;
using UnityEditor;

public class InspectorWindowAccessor
{
    public static Type AccessedType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
    private static MethodInfo MI_RefreshInspectors = AccessedType.Method("RefreshInspectors");

    public static void RefreshInspectors()
    {
        MI_RefreshInspectors.Invoke(null, null);
    }
}
#
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

[CustomEditor(typeof(ReplaceHeaderTitlebar))]
[CanEditMultipleObjects]
public class ReplaceHeaderTitlebarEditor : Editor
{
    private void OnEnable()
    {
        EditorApplication.update += EditorUpdate;
    }

    private void OnDisable()
    {
        EditorApplication.update -= EditorUpdate;
    }

    private void EditorUpdate()
    {
        if (!InternalEditorUtility.GetIsInspectorExpanded(target))
        {
            Debug.Log($"FORCING EXPAND");

            InternalEditorUtility.SetIsInspectorExpanded(target, true);
            InspectorWindowAccessor.RefreshInspectors();
        }
    }

    public override void OnInspectorGUI()
    {
        DrawHeader();
        base.OnInspectorGUI();
    }

    protected override void OnHeaderGUI()
    {
        Rect titlebarRect = GUILayoutUtility.GetLastRect();
        titlebarRect.height = 20;
        titlebarRect.y = -22;

        EditorGUI.InspectorTitlebar(titlebarRect, true, target, false);
    }
}
#

@raw dragon that should work

#

there's a slight thing
you won't get the blue text when you click on the title bar

#

which then, instead of doing the EditorGUI.InspectorTitlebar(titlebarRect, true, target, false);

#

you could probably just draw a colored rect over the default foldout triangle

raw dragon
#

damn thats some trickery right there haha

hearty tinsel
#

it's not a pretty solution, and there's things to improve, but seems to do the trick

raw dragon
#

I don't seem to have the InspectorWindowAccessor class?

#

I'm on Unity 2021

hearty tinsel
#

i shared it above

raw dragon
#

oh

#

gotcha

hearty tinsel
#

it's a class that uses reflection to get internal Unity stuff

toxic jacinth
#

@raw dragon tbh I wouldn't do this. It doesn't add much visually, but adds a lot of complexity and points of failure to your code. Even the SRPs don't bother with it.

hearty tinsel
#

yeah I mean, this isn't one of those things that I would do unless it's a must

#

i don't really like "overriding" default Unity stuff unless it adds a major benefit

#

like improving my workflow, saving a lot of time in mundane tasks, etc