UI Toolbox ロゴUI Toolbox
サポート

このページは翻訳です。サポートと動画チュートリアルは主に英語で提供しており、英語版のページが正式な内容です。 英語版

通知 (NotificationArea)

NotificationArea は親を埋め、1 つの隅にトーストの吹き出しを積み重ねます。

NotificationArea の 3 つのトースト: info、success、warning。それぞれ閉じるボタンと残り時間のバーを持つNotificationArea の 3 つのトースト: info、success、warning。それぞれ閉じるボタンと残り時間のバーを持つ

ビデオチュートリアル: Notifications。すべてのビデオ: Video tutorials。

各ワークスペースは、最初の使用時に作られるものを 1 つ持ちます。

workspace.Notifications.Show("Layout saved", Severity.Success);

var bubble =
    workspace.Notifications.Show("Connection lost", Severity.Error,
        durationMs: 0);
bubble.Title = "Network";
bubble.AddAction("Retry", Reconnect);
bubble.Clicked += _ => OpenLog();

ワークスペースの外では、自分でエリアを追加します。

<UIToolbox.NotificationArea
    name="toasts"
    corner="BottomRight"
    max-visible="3"
    stack-duplicates="true" />

UI Builder では、エリアは名前付きの破線の枠を表示するので、見つけられます。この枠は Play モードやビルドでは表示されません。

メンバー 説明
NotificationArea.Show(message, severity, durationMs) 吹き出しを追加して返します。メッセージはリッチテキストです。
NotificationArea.Show(bubble) 自分で作った吹き出しを追加します。
NotificationArea.ShowBanner(title, message, severity, durationMs) Banner の吹き出し (小さな行の上に大きなタイトル、2500 ms) を追加して返します。下の「バナーを表示する」を参照してください。
NotificationArea.ShowTask(task, loading, success, error) Task の読み込み中の吹き出しを追加して返します。下の「タスクを表示する」を参照してください。
NotificationArea.Corner (corner) TopRight (既定)、TopLeft、BottomRight、BottomLeft、TopCenter、BottomCenter、Center (親の中央。バナー用)。
NotificationArea.MaxVisible (max-visible) 同時に表示する吹き出しの最大数 (5)。それを超えると、新しい吹き出しはキューで待ちます。
NotificationArea.Queue (queue) MaxVisible を超える吹き出しをキューに保ちます (true)。待っている吹き出しは、表示中の吹き出しが去ると表示され、そのときタイマーが始まります。false は、場所を空けるために最も古い吹き出しを消します。
NotificationArea.StackDuplicates (stack-duplicates) 同じメッセージを、数付きの 1 つの吹き出しにまとめます (false)。Show は、同じメッセージ、タイトル、重大度を持つ吹き出しの Count に加え、カウントダウンをやり直し、その吹き出しを返します。
NotificationArea.ShowProgress (show-progress) 各吹き出しにカウントダウンのバーを表示します (true)。
NotificationArea.SlideBubbles (slide-bubbles) 吹き出しが来る、去る、高さが変わるとき、吹き出しが新しい場所へスライドします (true)。false ではジャンプします。
NotificationArea.EnterAnimation (enter-animation)、ExitAnimation (exit-animation) 吹き出しの入場と退場の仕方: Preset (既定、吹き出しの Preset の見た目)、SlideFromEdge、Fade、Zoom、Rise。下の「吹き出しの入場と退場を変える」を参照。
NotificationArea.EnterEasing (enter-easing)、ExitEasing (exit-easing) USS のイージング名 (NotificationEasing): Default (テーマのイージング)、Linear、Ease、EaseInOutBack など。
NotificationArea.EnterDurationMs (enter-duration)、ExitDurationMs (exit-duration) 入場または退場のミリ秒。0 (既定) はプリセットの時間のままです。
NotificationArea.EnterCurve (enter-curve)、ExitCurve (exit-curve) USS のトランジションの代わりに入場または退場を動かす、0 から 1 の AnimationCurve。1 を超えるカーブは行き過ぎます。null (既定) は USS のトランジションを使います。
NotificationArea.QueuedCount キューで待っている吹き出し。
NotificationArea.DismissAll() キューの吹き出しも含め、すべての吹き出しを消します。
NotificationBubble.Title (title) メッセージの上の太字の行。空 (既定) なら行を表示しません。
NotificationBubble.Description (description) メッセージ (リッチテキスト)。
NotificationBubble.Icon テキストの前の画像で、Background (テクスチャ、スプライト、ベクター画像)。null (既定) なら画像を表示しません。
NotificationBubble.IconAnimation (icon-animation)、IconAnimationClip (icon-animation-clip) 吹き出しが表示されている間、アイコンの中で再生される SpriteSheet (ピックアップで回るコインなど) と、再生するクリップ。Icon を覆います。なし (既定) なら、静止したアイコンのままです。
NotificationBubble.Severity (severity) Info (既定)、Success、Warning、Error。
NotificationBubble.Preset (preset) 見た目と登場の仕方: Toast (既定)、Banner、Achievement、KillFeed。下の「バナーを表示する」と「実績やキルフィードを表示する」を参照してください。
NotificationBubble.EnterAnimation、ExitAnimation、EnterEasing、ExitEasing、EnterDurationMs、ExitDurationMs、EnterCurve、ExitCurve エリアと同じメンバーで、1 つの吹き出しだけエリアの設定を上書きします。Inherit (アニメーション)、Default (イージング)、0 (時間)、空のカーブ (既定) はエリアの値を使います。
NotificationBubble.DurationMs (duration) 吹き出しが自分を消すまでの、ゲーム時間のミリ秒 (5000)。Time.timeScale が 0 の間、カウントダウンは止まります。0 以下なら、ユーザーが閉じるまで残ります。
NotificationBubble.RemainingMs 吹き出しが自分を消すまでのミリ秒。
NotificationBubble.Loading (loading) テキストの前にスピナーを表示します (false)。読み込み中の吹き出しは、自分を消しません。
NotificationBubble.Count 吹き出しが表す同じメッセージの数 (1)。1 より大きいと、"x3" のように表示します。
NotificationBubble.ShowProgress この吹き出しにカウントダウンのバーを表示します。null (既定) はエリアの ShowProgress を使います。
NotificationBubble.Closable (closable) 閉じるボタンを表示します (true)。
NotificationBubble.AddAction(text, callback) ボタンを追加します。クリックするとコールバックを実行し、そのあと吹き出しを消します。
NotificationBubble.Detail (detail) メッセージの下の追加のテキスト (リッチテキスト)。ポインターが吹き出しの上にある間、表示されます。詳細を持つ吹き出しは、それまでメッセージの下に "..." を表示します。
NotificationBubble.Expanded コードから詳細を表示します。ポインターは、入ったときにこれを設定し、出たときにクリアします。
NotificationBubble.Dismiss() 退場のアニメーションを再生してから、吹き出しを外します。
NotificationBubble.Clicked ボタンの外でのクリック、および吹き出しにフォーカスがあるときの Submit で発生します。
NotificationBubble.Dismissed 吹き出しが階層を離れたあとに発生します。

表示中の吹き出しを更新する

Show が返す吹き出しを保持して、そのプロパティを設定します。吹き出しはその場で変わり、カウントダウンがやり直されます。

var bubble = workspace.Notifications.Show("3 files left");
// Later
bubble.Description = "2 files left";
bubble.Severity = Severity.Warning;

タスクを表示する

ShowTask は、タスクの実行中、読み込み中の吹き出しを表示します。タスクが終わると、同じ吹き出しが成功またはエラーに変わり、そのあと自分を消します。

workspace.Notifications.ShowTask(SaveAsync(), "Saving...", "Saved",
    "Cannot save");

// The success message from the result of the task
workspace.Notifications.ShowTask(LoadAsync(), "Loading...",
    (int count) => $"{count} items loaded", "Cannot load");

吹き出しを自分で制御するには、Loading を設定し、作業が終わったらクリアします。

var bubble =
    workspace.Notifications.Show(
        new NotificationBubble { Description = "Connecting...",
            Loading = true });
// Later
bubble.Description = "Connected";
bubble.Severity = Severity.Success;
bubble.Loading = false;

クリックでウィンドウを開く

Clicked は、吹き出しのクリックで発生します。閉じるボタンやアクションのボタンでは発生しません。OpenWindow はウィンドウを開き、すでに開いていればフォーカスします。

var bubble = workspace.Notifications.Show("New message: click to open");
// Keyboard and gamepad users can move to the bubble and press Submit
bubble.focusable = true;
bubble.Clicked += clicked =>
{
    workspace.OpenWindow("chat");
    clicked.Dismiss();
};

ゲームでピックアップを表示する

各ピックアップに、アイコンと数を与えます。stack-duplicates では、同じメッセージのピックアップが、表示中の吹き出しにその数を加えるので、木材を 10 個拾うと "Wood x10" の 1 行になります。

<tb:NotificationArea
    name="feed"
    corner="BottomLeft"
    stack-duplicates="true"
    show-progress="false"
    queue="false" />
feed.Show(new NotificationBubble
{
    Description = "Wood",
    Count = amount,
    Icon = Background.FromTexture2D(woodIcon),
    Severity = Severity.Success,
    DurationMs = 2500,
    Closable = false,
});

バナーを表示する

バナーは、"Wave 3" や "Quest complete" のような、画面の中央の大きなメッセージです。corner="Center" と max-visible="1" のエリアを使うと、バナーが 1 つずつ順に来ます。

<tb:NotificationArea name="banners" corner="Center" max-visible="1" />
var banners = root.Q<NotificationArea>("banners");
banners.ShowBanner("WAVE 3", "Hold the gate", Severity.Warning);
// waits until "WAVE 3" leaves
banners.ShowBanner("QUEST COMPLETE", "The lost caravan");

実績やキルフィードを表示する

Preset は、吹き出しにゲームのメッセージの見た目と登場の仕方を与えます。どの吹き出しにも設定できます。

// Achievement: a gold edge, a larger icon, and the card rises into place
workspace.Notifications.Show(new NotificationBubble
{
    Preset = NotificationPreset.Achievement,
    Title = "ACHIEVEMENT",
    Description = "Pathfinder: find 10 hidden places.",
    Icon = Background.FromTexture2D(trophyIcon),
    DurationMs = 6000,
});

// Kill feed: one small line with no close button, from the right edge
killFeed.Show(new NotificationBubble
{
    Preset = NotificationPreset.KillFeed,
    Description = "<b>Mira</b>  [Bow]  Raider",
    DurationMs = 3000,
});

吹き出しの入場と退場を変える

入場と退場は、エリアか 1 つの吹き出しに設定します。入場と退場は別々に設定します。何も設定しないと、各プリセット (Toast、Banner、Achievement、KillFeed) は自分の見た目のままです。

var area = workspace.Notifications;
area.EnterAnimation = NotificationAnimation.SlideFromEdge;
area.EnterEasing = NotificationEasing.EaseOutBack;
area.EnterDurationMs = 350;
area.ExitAnimation = NotificationAnimation.Fade;

// A curve drives one bubble instead of the easing
var bubble = new NotificationBubble
{
    Description = "Quest complete",
    EnterAnimation = NotificationAnimation.Zoom,
    EnterCurve = NotificationCurves.Overshoot(),
};
area.Show(bubble);

ヒント

スタイル

ルールは Assets/UIToolbox/Runtime/Resources/UIToolbox/Styles/Controls.uss にあります。

クラス 要素
tb-notification-area オーバーレイ。修飾子: --top-right、--top-left、--bottom-right、--bottom-left、--top-center、--bottom-center、--center。
tb-notification 1 つの吹き出し。修飾子: --info、--success、--warning、--error。
tb-notification--banner、tb-notification--achievement、tb-notification--killfeed Preset のクラス。バナーは幅が広く中央にあり、重大度の色の枠を持ち、縮んで入ります。実績は金の縁を持ち、せり上がって所定の位置に来ます。キルフィードの行は小さく、閉じるボタンがなく、右からスライドして入ります。テーマはこれらを再スタイルできます。
tb-notification__body、__title、__message、__actions、__action、__close 吹き出しの各部分。
tb-notification__detail、tb-notification__more 詳細テキスト (控えめ、小さく、非表示) と "..." の印。
tb-notification__icon Icon の画像 (32 x 32 ピクセル)。
tb-notification__count "x3" のような、同じメッセージの数。Badge なので tb-badge も持ちます。tb-notification__count のルールが吹き出しの見た目を保ちます。
tb-notification__spinner 読み込み中の吹き出しのスピナー (ProgressRing)。
tb-notification__progress カウントダウンのバー。
tb-notification--loading 状態クラス: 吹き出しがスピナーを表示します。
tb-notification--expanded 状態クラス: 詳細を表示し、印を隠します。
tb-notification--hidden 状態クラス: 入場のアニメーションの開始点で、退場のアニメーションの終点。
tb-notification--anim-in、tb-notification--anim-out 入場と退場のアニメーションのトランジションクラス。
tb-notification--motion、tb-notification--motion-slide、--motion-fade、--motion-zoom、--motion-rise 入場または退場のスタイルが再生される間の状態クラス。tb-notification--hidden と合わせて、入場の開始位置と退場の終了位置を決めます。
tb-notification--slide トランジションクラス: その前の吹き出しが来る、去る、高さが変わるとき、吹き出しが新しい場所へスライドします。