Possible to change size of EditorWindow notification?

Is it possible to change the size, position and duration of an EditorWindow notification? The default settings shows a big message in the center of window and stays tool long before eventually disappears.

3246873--249816--upload_2017-10-8_19-40-30.png

Any ways to control that? Or are there better ways to show some confirmation message? My ideal is something smaller at the corner of window.

You can create a EditorGUILayout.HelpBox with your message and then wrap it inside a FadeGroup. You can then animate the float you pass into the fade group from 0 to 1 which will perform a fold/unfold animation. inorder for the animation to go smoothly you’ll want to use one of the BaseAnimValue classes. Of course can then use the EditorGUILayout functions to resize and reposition where the notification shows up.

Note: This is not supported in PropertyDrawers and (I think) DecoratorDrawers, primarily cause EditorGUILayout can’t be used in them. You can manually draw them, but you’ll not have access to a Repaint function thus you can’t do any nifty animation.

heres an example of how you can use it

Example Code

using UnityEditor;
using UnityEditor.AnimatedValues;

public class MyCustomClassEditorWindow : EditorWindow
{
    private AnimFloat anim_notification;
    private string s_notification;
    private float f_notificationDuration = 3f; // lasts for 3 seconds
    private MessageType m_messageType = MessageType.Info;

    private void OnEnable()
    {
        anim_notification= new AnimFloat(0);

        // by default it animates over 1 second. if you set speed to 2 then its over half a second
        anim_notification.speed = 1;

        // tells this AnimFloat to repaint the window every frame its changes
        // this is so the window redraws every frame instead of every 10 frames (only while animating)
        anim_notification.valueChanged.AddListener(Repaint);
    }

    private void OnGUI ()
    {
        if(GUILayout.Button("Show Notification"))
        {
            s_notification = "This is a test notification";
            m_messageType = MessageType.Info;
            anim_notification.target = 1+f_notificationDuration * anim_notification.Speed;
        }

        if(anim_notification.isAnimating)
        {
            EditorGUILayout.BeginFadeGroup(anim_notification.value);
                EditorGUILayout.HelpBox(s_notification, m_messageType);
            EditorGUILayout.EndFadeGroup();
        }
        else
        {
            if (anim_notification.target != 0)
            {
                anim_notification.value = 1;
                anim_notification.target = 0;
            }

            if(anim_notification.value>0)
            {
                EditorGUILayout.HelpBox(s_notification, m_messageType);
            }
        }
    }
}
1 Like

Excellent. This is even more beautiful than I imagined. Thank you very much.