Páginas

miércoles, 12 de marzo de 2014

Manual Nuntius Notifier

v1.0.1          Available in Unity Asset Store.

Nuntius Notifier is a controller that handles manipulate notifications. In can be used to notify the player about a achievement unlocked, or when a friend has logged, or any information that the game should notify.

It has the capacity of that if the game sends many notifications, the notifier stores them in a queue, and shows them in the order they were sent.

How to use?

Like NGUI components, you can create the aspect of your notification, and without any effort add to it the UINuntiusNotifier component. And presto! You will have a Notifier in its full power.

The UINuntiusNotifier component

Nuntius Notifier works so you don't worry, more than just notify the player, In the code, you will invoke to the Notify method and, you will send all messages that you desire; and Nuntius Notifier will handle manage each the messages that goes show on screen. When you add the component, you will see something like this:


Thus is the component that handles of manage all message that your game requires notify. Each property has its next task.

UINuntiusNotifier Component Properties

  1. Title: Receives a component of type UILabel. Whether the notification requires a title to prevent to the player of the type of message that is about to read. (It's a optional property.)
  2. Message: Receives a component of type UILabel. This is the notification body. Here is where appear the notified message. (It's a necessary property.)
  3. Texture: Receives a component of type UITexture. Whether the notification requires a pictures to illustrate with clarity the massage. (It's a optional property.)
  4. Location: Locates the notification in a place out screen (In Edit Mode), or in a place inside screen (In Play Mode) always that be visible, or else will be out screen.
  5. Direction: Sets the direction of visualization that correspond from out towards inside of the screen. If Location is BottomRight and Direction is BottomToTop, means that the notification it will show from bottom (out screen) towards top (inside screen).
  6. Offset: Sets a spacing between the screen border and the notification. If your message requires a spacing to that the player will pay more attention to the notification, then this property solves this problem. If the value is zero, means there is not spacing; and if is a negative number will be converted to a positive number.
  7. Hotkey: This is a optional method to close the current notification by pressing the hotkeys corresponding.

Nuntius Notifier receives all data of a notification and locates it in its respective parts when is necessary show it. Always that exist one notification in the queue, will show it on screen and the state will change to visible. Otherwise, when there is not any one notification in the queue, the state will change to not visible. See the following picture.


The blue frame is the screen, and the red rectangle is Nuntius Notifier, when it is sent a notification, is add at the queue, and checks the exist of a notification, if is true, the state changes to visible, locating the notification inside screen; otherwise not do it, or if is closed the notification, then the state changes to not visible, locating the notification out screen. And the operation is repeated if the queue is not empty, showing the next notification.

Like it said previously, Nuntius Notifier handles of manage each the messages that goes show on screen, that means, only necessary one Notifier to control all notifications, however, if you requires more Notifiers, you can do it. But remember which is which. Like everything else in Unity. Now see a description of the first example.

Basic Sample

In the 1st-Basic.unity sample, it can see how to works Nuntius Notifier, you note that the notification has a Title (1), a message body (2), a button to close (4), and two informative parts (3, 5), this is what each means:



Parts of a basic notification

  1. It's the title of the notification. This is the game-object that has the UILabel component to the Title property. In the sample, is sent by each notified message. (the icon, is a encoding of the NGUI emoticons system)
  2. The notification body. Here is where are show all messages to notify. This is the game-object that has the UILabel component to the Message property.
  3. This is a optional information. Indicates the message number, the messages amount, and how many messages remain to be read. The code, is something thus: GetComponent<UILabel>().text = "Posts: " + Notifier.Number + "/" + Notifier.Quantity + " (" + Notifier.Length + ")";
  4. This is another optional method to close the notification. Uses the next code, with OnClick event of the UIButton component: UINuntiusNotifier.Close();
  5. This is a optional information. Indicates with which hotkey can close the notification. the code, is something thus: GetComponent<UILabel>().text = "Push [b]" + Notifier.Hotkey.ToString() + "[/b] to close this post.";
Thus is like a notification can be created, and can have a versatile design. You can omit the title game-object, the button to close, and the two informative parts, but never the message body, as you will see now.

Texture & Offset Sample

In the 2nd-Textures&Offset.unity sample, it can see how is a notification with a picture and the Offset property, explained previously. You note that the notification now has a texture (1), and the message body (2). In this case, the notification is more simple, and its method to close is by a duration time.


The duration property that they have the Notify methods, allows that each message it keep by a time visible on screen. These are the following methods that you will use to notify:

Notify Methods

  • public void Notify(string message, float duration);
  • public void Notify(string title, string message, float duration);
  • public void Notify(string message, Texture texture, float duration);
  • public void Notify(string title, string message, Texture texture, float duration);
According the case of your notification will use the method required. If only you want send a message, then you will use the first option; or maybe if you want send a message with a title, the second option is best; or the third option with a message and a texture; or else, the fourth that has all properties.

Each the methods has the duration property, if send a number as 4f means the notification will be visible by four seconds. If is zero means the notification will keep visible until the player desires close it by a button to close or a hotkey. If by mistake you send a negative number, don't worry, because will be converted to a positive number.

Tweenings

Nuntius Notifier can use the tweenings that NGUI offers to animate the notifications. Are 6 basic tweenings can be added:
  • Alpha
  • Width
  • Height
  • Position
  • Rotation
  • Scale
You can make a combination with them to best effect. When it uses in play mode and not add to it any tween, Nuntius Notifier will add the Position tween by default; but if add any other tween, then will work these tweenings, and will not add the Position tween, even if you have done it manually.

You can modify the properties of the tweenings, but, if you change Play Style property to Loop or Ping-Pong, Nuntius Notifier will change it to Once. This is, because Nuntius Notifier not works loops.

If you add any other tweenings not supported, Nuntius Notifier removes them.

Localization

Nuntius Notifier also has capacity to use the NGUI Localization System. Only you have to send the keys in the properties Title of Message of the Notify method, like in the 4th-Localization.unity sample.

A Note

The Direction property works in a peculiar manner, prevents inadvertent errors, that can make not display on the screen.


The blue frame is the screen, the red rectangles are Nuntius Notifier, violet letters are the values of the Location property, and green letters are the values of the Direction property. According the Location and Direction selected will be the place where will locate the notification.

For example, if you select the TopRight (TR) location, then you will have two options where locate the notification, will be located in D figure, whether you selected the RightToLeft (R+L) direction or LeftToRight (L+R) direction; or will be located in E figure, whither you select the TopToBottom (T+B) direction or BottomToTop (B+T) direction.

If you select any location as Top (T), Bottom (B), Left (L) or Right (R), always will locate in the location indicated as the figures C, F, I, L, regardless the direction selected.

Enjoy enriching their games!

Available in Unity Asset Store.