Notifications

Important

If you want to display more than one notification at the same time, then notification container should have layout group component like EasyLayout. Start positions of notifications are determined with Group Position.

Options

  • Hide Button Button

    Button to close notification.

  • Text Text (obsolete)

    GameObject to display the notification text. Replaced with NotifyInfo.

  • Hide Delay float

    Delay before notification automatically hidden.

  • Unscaled Time bool

    Delay with unscaled time.

  • Slide Up On Hide bool

    Start slide up animations after hide current notification. Turn it off if its managed with HideAnimation.

  • Notify Info NotifyInfoBase

    Component to display the notification message.

  • Close Button Button

    Button to close notification.

  • Buttons Container RectTransform

    Buttons container. If container not specified will be used parent of the button template.

Show() Method Parameters

All parameters are optional.
message also can be specified with SetMessage()
to use formatted strings.
  • message string

    Notification message.
    Can be changed with SetMessage() method.
  • customHideDelay float?

    Time before notification hidden or hideAnimation start running.
    Can be changed with HideDelay field.
  • container Transform?

    Notifications container. Should have Layout Group component
    to display multiple notifications.
    Can be changed with SetContainer() method.
  • showAnimation Func<TNotification, IEnumerator>

    Show animation.
    Can be changed with ShowAnimation field.
  • hideAnimation Func<TNotification, IEnumerator>

    Hide animation.
    Can be changed with HideAnimation field.
  • slideUpOnHide bool?

    Obsolete.
    Use EasyLayout.MovementAnimation instead.
  • sequenceType NotifySequence

    Add notification to sequence and display in order according to the specified sequenceType.

  • sequenceDelay float

    Time between previous notification was hidden and this will be displayed.
    Can be changed with SequenceDelay field.
  • clearSequence bool

    Clear notifications sequence.

  • newUnscaledTime bool?

    Animations will use unscaled time.

  • content RectTransform

    Notification content.
    Can be changed with SetContent().
  • onReturn Action

    Action called when instance return to the cache.
    Can be changed with OnReturn field.
  • onHide Action<TNotification>

    Action called when instance return to the cache.
    Can be changed with OnNotificationHide field.

ShowAsync() Method Parameters

All parameters are optional.
message also can be specified with SetMessage()
to use formatted strings.
Returns index of the clicked button or -1 if notification was hidden after delay or on hide button click.
  • message string

    Notification message.
    Can be changed with SetMessage() method.
  • customHideDelay float?

    Time before notification hidden or hideAnimation start running.
    Can be changed with HideDelay field.
  • container Transform?

    Notifications container. Should have Layout Group component
    to display multiple notifications.
    Can be changed with SetContainer() method.
  • showAnimation Func<TNotification, IEnumerator>

    Show animation.
    Can be changed with ShowAnimation field.
  • hideAnimation Func<TNotification, IEnumerator>

    Hide animation.
    Can be changed with HideAnimation field.
  • slideUpOnHide bool?

    Start slide up animations after hide current notification.
    Can be changed with SlideUpOnHide field.
  • sequenceType NotifySequence

    Add notification to sequence and display in order according to the specified sequenceType.

  • sequenceDelay float

    Time between previous notification was hidden and this will be displayed.
    Can be changed with SequenceDelay field.
  • clearSequence bool

    Clear notifications sequence.

  • newUnscaledTime bool?

    Animations will use unscaled time.

  • content RectTransform

    Notification content.
    Can be changed with SetContent().
  • closeOnButtonClick bool

    Close notification on button click.

Minimal code

// get notification instance by template name (name of existing GameObject with NotificationBase component).
var notification = notificatetionTemplate.Clone();
// show notification
notification.Show();

Advanced

var notification = notificatetionTemplate.Clone();
// show notification
notification.Show(
   // Show notification with following text
   message: "Simple Notification.",
   // Hide it after 4.5 seconds
   customHideDelay = 4.5f,
   // Run specified animation on hide
   hideAnimation = NotificationBase.AnimationCollapseVertical,
   // without SlideUpOnHide
   slideUpOnHide = false
);

Notification with Buttons

Nofications can have buttons with custom actions. Buttons callback receive notification instance and button index, return true to close notification; otherwise false.

[SerializeField]
protected Notify NotificationTemplate;

/// <summary>
/// Show notification.
/// </summary>
public void ShowNotify()
{
   var actions = new NotificationButton[]
   {
      new NotificationButton("Close", NotificationClose),
      new NotificationButton("Log", NotificationClick),
   };

   var instance = NotificationTemplate.Clone();
   instance.Show("Notification with buttons. Hide after 5 seconds.", customHideDelay: 5f);
   instance.SetButtons(actions);
}

bool NotificationClose(NotificationBase notification, int index)
{
   Debug.Log("close notification");
   return true;
}

bool NotificationClick(NotificationBase notification, int index)
{
   Debug.Log("click notification button");
   return false;
}

Async Notification with Buttons

[SerializeField]
protected Notify NotificationTemplate;

/// <summary>
/// Show notification.
/// </summary>
async public void ShowNotify()
{
   var actions = new NotificationButton[]
   {
      new NotificationButton("Close"),
      new NotificationButton("Log"),
   };

   var instance = NotificationTemplate.Clone();
   instance.SetButtons(actions);
   var button_index = await instance.ShowAsync("Notification with buttons. Hide after 5 seconds.",
      customHideDelay: 5f, closeOnButtonClick: false);

   while (button_index == 1)
   {
      Debug.Log("click notification button");
      button_index = await instance;
   }

   if (button_index == 0)
   {
      Debug.Log("close notification");
      instance.Hide();
   }
   else
   {
      Debug.Log("hide button");
      instance.Hide();
   }
}

Default Hide Animations

Note

Hide Animation is coroutine that accepts NotificationBase instance and play hide animation for this instance. You can specify any custom coroutine.

  • AnimationRotateHorizontal

    Rotate notification on X axis.

  • AnimationRotateVertical

    Rotate notification on Y axis.

  • AnimationCollapseHorizontal

    Resize width of the notification.

  • AnimationCollapseVertical

    Resize height of the notification.

  • AnimationSlideRight

    Slide notification on right.

  • AnimationSlideLeft

    Slide notification on left.

  • AnimationSlideUp

    Slide notification on up.

  • AnimationSlideDown

    Slide notification on down.

Default Show Animations

Note

Show Animation is coroutine that accepts NotificationBase instance and play show animation for this instance. You can specify any custom coroutine.

  • ShowAnimationRotateHorizontal

    Rotate notification on X axis.

  • ShowAnimationRotateVertical

    Rotate notification on Y axis.

  • ShowAnimationCollapseHorizontal

    Resize width of the notification.

  • ShowAnimationCollapseVertical

    Resize height of the notification.

  • ShowAnimationSlideRight

    Slide notification from right.

  • ShowAnimationSlideLeft

    Slide notification from left.

  • ShowAnimationSlideUp

    Slide notification from top.

  • ShowAnimationSlideDown

    Slide notification from bottom.

Configurable Hide Animations

  • HideAnimationRotateBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Rotate in horizontal or vertical direction.

    • float timeLength

      Length of animations in seconds.

  • HideAnimationCollapseBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Resize in horizontal or vertical direction.

    • float speed

      Resize speed in points per second.

  • HideAnimationSlideBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Slide in horizontal or vertical direction.

    • float direction

      Slide direction, -1f for left/down, +1f for right/up.

    • float speed

      Slide speed in points per second.

    • bool animateReplacement

      Animate other notifications.

NotificationTemplate.Clone().Show(
   "Notification message.",
   customHideDelay: 3f,
   hideAnimation: x => NotificationBase.HideAnimationSlideBase(x, true, -1f, 200f, true)
);

Configurable Show Animations

  • ShowAnimationRotateBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Rotate in horizontal or vertical direction.

    • float timeLength

      Length of animations in seconds.

  • ShowAnimationCollapseBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Resize in horizontal or vertical direction.

    • float speed

      Resize speed in points per second.

  • ShowAnimationSlideBase

    Arguments:

    • NotificationBase notification

      Notification instance.

    • bool isHorizontal

      Slide in horizontal or vertical direction.

    • float direction

      Slide direction, -1f for left/down, +1f for right/up.

    • float speed

      Slide speed in points per second.

    • bool animateReplacement

      Animate other notifications.

NotificationTemplate.Clone().Show(
   "Notification message.",
   customHideDelay: 3f,
   showAnimation: x => NotificationBase.ShowAnimationSlideBase(x, true, -1f, 200f, true)
);

Custom Notifications

You can create derived class with own methods.

public class MyNotify : NotificationCustom<MyNotify>
{
   // ...
}