obsidian/笔记文件/2.笔记/EditorWindow.ShowNotification.md
2025-03-26 00:02:56 +08:00

1.2 KiB

#unity/日常积累

public void ShowNotification (GUIContent notification);

参数

notification

通知消息的内容。

fadeoutWait

显示通知的持续时间。以秒为测量单位。

描述

显示通知消息。

在窗口上显示通知消息。与消息框或日志消息不同,通知会在一段时间后自动消失。 调用 RemoveNotification 可立即删除通知。

!Pasted image 20240131124512.png

在编辑器窗口中显示通知。

using UnityEngine;
using UnityEditor;

public class ShowRemove : EditorWindow
{
    string notification = "This is a Notification";

    [MenuItem("Example/Notification Usage")]
    static void Initialize()
    {
        ShowRemove.GetWindow(typeof(ShowRemove));
    }

    void OnGUI()
    {
        if (GUILayout.Button("Show Notification"))
        {
            this.ShowNotification(new GUIContent(notification));
        }

        if (GUILayout.Button("Remove Notification"))
        {
            this.RemoveNotification();
        }
    }
}