#Custom inspector title bar
1 messages · Page 1 of 1 (latest)
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?
What is this doing?
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
drawing over
yeah, drawing over
And you want to...?
that's probably why OnHeaderGUI is not documented
to avoid confusion
that's why i hesitated to use this
i assume he wants to draw over and prevent the component from being collapsed
yes, exactly. the same way it works for the Audio Listener component
And you said that OnheaderGUI doesn't receive input events?
it receives inputs
but not outside the actual editor area
so when you click on the title bar, you can't receive it in the OnHeaderGUI method
A bit janky but you could force expand it if it is collapsed
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
damn thats some trickery right there haha
it's not a pretty solution, and there's things to improve, but seems to do the trick
i shared it above
it's a class that uses reflection to get internal Unity stuff
@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.