Unity・3DCG技術ブログ

TAもどきによるUnity・3DCGに関する記事をアップします。

【Unity】EditorWindowにWarningを表示するサンプル

概要

f:id:serialtv:20200725003100p:plain

コード

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

public class ExampleWindow : EditorWindow
{
    [MenuItem("Window/ExampleWindow")]
    static void Init()
    {
        GetWindow<ExampleWindow>();
    }

    void OnEnable()
    {
        var button1 = new Button(() => ShowWarning());
        rootVisualElement.Add(button1);
    }

    void ShowWarning()
    {
        var content = new GUIContent(string.Empty, EditorGUIUtility.FindTexture("console.warnicon"));
        content.text = "Message";
        ShowNotification(content, fadeoutWait: 5);
    }
}