πŸ“œMessage Popups

Package with message popups system so you can easy connect it to your game

Package with DOTween support
Package with PrimeTween support

What for

When player clicks on locked button or we want to send player tips it's good to make it with message popups. Message will be shown for N seconds (+-2s by default) and then automaticaly disappear.

Here is examples of default popups (you can change its visuals with prefabs), 3 types:

Tip (pool of 3 in action)
Error
Info

How to use

  1. Add MessagePopups.prefab under your scene UI canvas

  2. Reference to MessagePopups somewhere to call message popups later

  3. Use these methods in MessagePopups.cs to call popup:

public void Show(string text, MessageTypes messageType);
public void Show(string text, MessageTypes messageType, Vector2 atScreenPosition);

You also can use MessagePopup.cs directly. Add target type prefab to your UI and call by controller with Show method, but make sure to call Init() once before calling Setup(text) + Show(text)

Settings of base implementation

In inspector BaseMessage.prefab
  • Fit In Screen boolean used by MessagePopups manager to fit popup in user resolution even if target position out of screen (rect size delta of message will be used)

  • Fit Screen Padding is offset from screen border to fit in

  • Text is reference to default text (replace it with TMP if you need in MessagePopup.cs)

  • Animation is implementation of PopupAnimation abstract class. PopupDefaultAnimation is implemented in this package, you can add your own and setup correspond fields

How add more popups:

  1. Add new popup type in enum MessageTypes.cs

  2. Create prefab variant from BaseMessage.prefab or completely new and add MessagePopup script to it

  3. Setup visuals for it in prefab

  4. Optional if you need special animation for this type then make a class that derives from PopupAnimation and implement it's methods. See PopupDefaultAnimation implementation for reference how it can be. Your PopupAnimation implementation should support replacement in target screen position (I set rectTransform.position of message with argument value and recalculate animation offsets)

Last updated