Páginas

viernes, 25 de abril de 2014

Directory Finder Widget

v2.1          Available in Unity Asset Store.

Directory Finder Widget is a widget created to NGUI and Unity UI. This is a file explorer which searches folders and files.

You can use to find certain files such as text, xml, audio, video, etc., and save the file path to load the same next time.

For NGUI: Next-Gen UI

How to use?

Exist one prefab to use, the DirectoryFinderWidget_NGUI prefab. This prefab is the widget that you will use.

Using the prefab

The prefabs are a shortcut to use the widget a very fast way, or to find out how the widget is done and make your own widget with an appearance different and/or with other disposition.

DirectoryFinderWidget

The DirectoryFinderWidget_NGUI prefab is the window or dialog that you will use in the scene. Has as component the following script.


The NGUIDirectoryFinderController script is a controller of the widget, in this version are not the necessary component properties, now set by script, don’t worry it's very simple. Left me explain you.

You have access to properties end events by ListenerFinder class. Between the properties you can set a initial location using the initialPath property:

ListenerFinder.initialPath = Application.dataPath;

Also if it wants looking for the files, you can set the findFiles property:

ListenerFinder.findFiles = true;

To show the path on the interface, you can set showPath property:

ListenerFinder.showPath = true;

Between the events you have at your disposal the following methods listeners:

// The listener of the back button event.
public void OnBack (string previousPath, string pathToLookFor) {
   // previousPath : the previous path prior to the event.
   // pathToLookFor : the new path after to the event.
}

// The listener of the open button event.
public void OnOpen (string previousPath, string pathToLookFor) {
   // previousPath : the previous path prior to the event.
   // pathToLookFor : the new path after to the event.
}

// The listener of the choose button event.
public void OnChoose (string name, string path) {
   // name : the selected item name.
   // path : the selected item path.
}

// The listener of the drive selection.
public void OnSelectedItemDrive (string name, string path) {
   // name : the selected drive item name.
   // path : the selected drive item path.
}

// The listener of the item (file or folder) selection.
public void OnSelectionItem (string name, string path) {
   // name : the selected item name.
   // path : the selected item path.
}

However, to that this methods work it's necessary assign them in the following properties to execute them, you can locate them in the Start method:

public void Start () {
   // The listeners of the buttons
   ListenerFinder.OnBack = new ListenerFinder.ListenerBackButton(OnBack);
   ListenerFinder.OnOpen = new ListenerFinder.ListenerOpenButton(OnOpen);
   ListenerFinder.OnChoose = new ListenerFinder.ListenerChooseButton(OnChoose);

   // The listeners of the item selection
   ListenerFinder.OnSelectionItemDrive = new ListenerFinder.ListenerSelectedItemDrive(OnSelectedItemDrive);
   ListenerFinder.OnSelectedItem = new ListenerFinder.ListenerSelectedItem(OnSelectedItem);
}

How to change the appearance?

If you know to use NGUI, you probably know how to do. But, is important know the structure of the elements that can be changed and avoiding an unwanted mess.

The Hierarchy

All the elements be found inside the Window[Panel] game object, thus it is easer for usability, and to change the appearance and the elements disposition, without break the hierarchy. In the first place we go to see the labels that you can change.

Labels

  • Title[Label]: Inside the Header game object is the Title[Label] label, this corresponds to the name or title of the window or dialog that currently is "Directory Finder Widget for NGUI". You can change the text of the label.
  • Info[Label]: This is the information message detailing the cause of dialogue for the player. You can change the text of the label.
  • Label inside Drives UI: This label is located inside the Drives[Panel]/Drives UI/Label hierarchy, it specifies the name of the Drives[Popup List] which shows the drives found in the player's machine. You only can change the label that is inside Drives UI, and not the Label that is inside Drives[Popup List].
  • BackButton, OpenButton and ChooseButton: Last, you can change the text of the label elements inside each this buttons.
Note: It is not advisable change the text of the labels ItemSelected[Label] and Path[Label] that is inside Footer. Neither the ItemName[Label] label that is inside ItemF0.

Now we go to see what can we to change for using other atlas.

Sprites

  • Background[Sprite]: You can change the color and the sprite with your own NGUI's atlas. This sprite corresponds to dialog background and delimits the widget dimensions. If you need change the widget size, you do it about this game object, because all elements are anchored to him.
  • Border[Sprite]: To this appearance is the widget frame and you can change it, and too you can remove it, if your UI style is different.
  • Shadow[Sprite]: You can change the appearance or remove it.
  • Header: This sprite corresponds to the base of the widget title. You can change the appearance.
  • Footer: This sprite corresponds to the path data, that if you not need it, you can hide it, only hide it.
  • BackButton, OpenButton, ChooseButton and Drives[Popup List]: You can change the colors and the appearance of this interface.
  • Background and Foreground inside Scroll Bar[Panel]: You can change the appearance with your own NGUI's atlas.
  • ItemF0 inside Scroll View[Panel]: You can change the colors.
  • Checkmark and Hover inside ItemF0: You can change the colors and the appearance.
  • FileIcon[Sprite] and FolderIcon[Sprite] inside ItemF0: You can change the colors and the appearance with other icons.
  • All labels: You can change the font and the colors, what allow NGUI.

For Unity UI 4.6 or higher

How to use?

Exist one prefab to use, the DirectoryFinderWidget_Unity prefab. This prefab is the widget that you will use.

Using the prefab

The prefabs are a shortcut to use the widget a very fast way, or to find out how the widget is done and make your own widget with an appearance different and/or with other disposition.

DirectoryFinderWidget

The DirectoryFinderWidget_Unity prefab is the window or dialog that you will use in the scene. Has as component the following script.


The DFWDirectoryFinderController script is a controller of the widget, in this version are not the necessary component properties, now set by script, don’t worry it's very simple. Left me explain you.

You have access to properties end events by ListenerFinder class. Between the properties you can set a initial location using the initialPath property:

ListenerFinder.initialPath = Application.dataPath;

Also if it wants looking for the files, you can set the findFiles property:

ListenerFinder.findFiles = true;

To show the path on the interface, you can set showPath property:

ListenerFinder.showPath = true;

Between the events you have at your disposal the following methods listeners:

// The listener of the back button event.
public void OnBack (string previousPath, string pathToLookFor) {
   // previousPath : the previous path prior to the event.
   // pathToLookFor : the new path after to the event.
}

// The listener of the open button event.
public void OnOpen (string previousPath, string pathToLookFor) {
   // previousPath : the previous path prior to the event.
   // pathToLookFor : the new path after to the event.
}

// The listener of the choose button event.
public void OnChoose (string name, string path) {
   // name : the selected item name.
   // path : the selected item path.
}

// The listener of the drive selection.
public void OnSelectedItemDrive (string name, string path) {
   // name : the selected drive item name.
   // path : the selected drive item path.
}

// The listener of the item (file or folder) selection.
public void OnSelectionItem (string name, string path) {
   // name : the selected item name.
   // path : the selected item path.
}

However, to that this methods work it's necessary assign them in the following properties to execute them, you can locate them in the Start method:

public void Start () {
   // The listeners of the buttons
   ListenerFinder.OnBack = new ListenerFinder.ListenerBackButton(OnBack);
   ListenerFinder.OnOpen = new ListenerFinder.ListenerOpenButton(OnOpen);
   ListenerFinder.OnChoose = new ListenerFinder.ListenerChooseButton(OnChoose);

   // The listeners of the item selection
   ListenerFinder.OnSelectionItemDrive = new ListenerFinder.ListenerSelectedItemDrive(OnSelectedItemDrive);
   ListenerFinder.OnSelectedItem = new ListenerFinder.ListenerSelectedItem(OnSelectedItem);
}

How to change the appearance?

If you know to use Unity UI, you probably know how to do. But, is important know the structure of the elements that can be changed and avoiding an unwanted mess. 

The Hierarchy

All the elements be found inside the DirectoryFinderWidget_Unity game object, thus it is easier for usability, and to change the appearance and the elements disposition, without break the hierarchy. In the first place we go to see the labels that you can change.

Labels

  • Title: Inside the Header game object is the Title text, this corresponds to the name or title of the window or dialog that currently is “Directory Finder Widget for Unity UI 4.6”. You can change the text of the label.
  • Info: This is the information message detailing the cause of dialogue for the player. You can change the text of the label.
  • DriveLabel: This label specifies the name of the DrivesSelectionList which shows the drives found in the player’s machine. You only can change this DriveLabel text, and none Text object that is inside DrivesSelectionList.
  • BackButton, OpenButton and ChooseButton: For last, you can change the text of the elements inside each this buttons.
Note: It is not advisable change the text of the objects ItemSelected and Path (this is inside Footer). Neither the ItemName text that is inside Container/ItemF0, as also the Text that is inside DriveSelectionList/ScrollRect/Item0.

Now we go to see what can we to change for using other sprites.

Sprites

  • DirectoryFinderWidget_Unity: You can change the appearance with your own sprites of your project. This sprite corresponds to the dialog background and delimits the widget dimensions. If you need change the widget size, you do it about this game object, because all elements are anchored to him.
  • Border: To this appearance is the widget frame and you can change it, and too you can remove it, if your UI style is different.
  • Shadow: You can change the appearance or remove it.
  • Header: This sprite corresponds to the base of the widget title. You can change the appearance.
  • Footer: This sprite corresponds to the path data, that if you not need it, you can hide it, ¡only hide it!
  • BackButton, OpenButton, ChooseButton and DrivesSelectionList/Button: You can change the appearance of this interfaces.
  • All Scrollbars inside Container/Scrollbar and DriveSelectionList/ScrollRect/Scrollbar: You can change the appearance of the interface.
  • Container: You can change the appearance with your own sprites
  • ItemF0 inside Container and Item0 inside DriveSelectionList/ScrollRect: You can change the appearance.
  • Checkmark inside ItemF0: You can change the appearance.
  • FileIcon and FolderIcon inside ItemF0: You can change the appearance with other icons.
  • ScrollRect inside DriveSelectionList: You can change the appearance.
  • All labels: You can change the font, the colors, until add a effect.
Note Important: Please do not modify any of the events assigned to all the elements that use them.

Thank you for read the manual. Have fun!

Available in Unity Asset Store.

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.