RSS

Tag Archives: Unity 3d

Using Firebase in Unity3D Tutorial 1: Basics and setup


Firebase is a platform that helps you quickly develop high-quality apps,  It is made up of a collection of features that is very handy for Unity3D, Android, iOS app developers.

In this series of tutorials, I am going to cover how to harness Firebase features to streamline your app development process. Each tutorial is designed to be compact, and follows the SRP (Single Responsibility Principle), so that you can use these take-aways quickly in your own development.

Read the rest of this entry »

 
1 Comment

Posted by on January 21, 2017 in Programming, Unity 3d

 

Tags: , , , , , , , ,

Unity3D: Get inspector property values programatically


Recently, I found an interesting question in Unity3D. How to get some field value shown in Unity3D inspector programmatically? Largely this is an undocumented area, and it took me some research to get this done.

In what follows, I am getting the value for Input Manage Axes, as shown below:

image

Read the rest of this entry »

 
1 Comment

Posted by on October 25, 2016 in Programming, Unity 3d

 

Tags: , , , , , , , , , , ,

Using SmartFox with C# (III) : Frequently used functions


If you haven’t read below posts, you might wish to have a quick go through:

Using SmartFox with C# (I) : Installations and 1st handshaking
Using SmartFox with C# (II) : Login and join room

If you are comfortable with above implementations, you might be interested in below frequently called functions. Assuming below variable is instantiated successfully:

private SmartFox client;

To Send a message:

client.Send(new PublicMessageRequest(someMessage));
client.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
private void OnPublicMessage(BaseEvent evt) {
     User sender = (User) evt.Params[“sender”];
     string message = (string) evt.Params[“message”];   
}

To create a room:

var settings = new RoomSettings(“New Room Name”);
settings.maxUsers = 100;
Settings.groupId = “ChatGroup”;
client.Send(new CreateRoomRequest(settings));
client.addEventListener(SFSEvent.ROOM_ADD, OnRoomAdded);

For a zone, to join/remove a room:

client.Send(new Sfs2X.Requests.JoinRoomRequest(roomId));
client.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
private void OnRoomJoin(BaseEvent evt) {
     Room room = (Room) evt.Params[“room”];           
     //room.Name,  room.UserList
}

For user to enter/leave a room

client.Send(new Sfs2X.Requests.LeaveRoomRequest());
client.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
private void OnUserExitRoom(BaseEvent evt) { User user = (User) evt.Params[“user”]; }

For more information, have a read on SFSEvent class and Sfs2X.Requests namespace will be vey helpful.

 
2 Comments

Posted by on September 14, 2015 in Dotnet/C#, Programming, Unity 3d

 

Tags: , , , , ,

Unity3D: Progressbar using new UI system


Before Unity 4.6 new UI system came out, to create a progress bar, the typical process involve writing the OnGUI() function as follows:

public Texture2D emptyProgressBar; // Set this in inspector.
public Texture2D fullProgressBar;  // Set this in inspector.

void OnGUI() 
{
    GUI.DrawTexture(Rect(0, 0, 100, 50), emptyProgressBar);
    GUI.DrawTexture(Rect(0, 0, progress, 50), fullProgressBar);
    GUI.skin.label.alignment = TextAnchor.MiddleCenter;
    GUI.Label(Rect(0, 0, 100, 50), string.Format("{0:N0}%", 
progress * 100f)); }

UnityProgressBar

This is OK, however not recommended in the new GUI system in Unity 4.6+: you don’t want to mix the GUI with the new and legacy system, right?

Here is the process to create a progress bar using the new UI system:

Read the rest of this entry »

 
4 Comments

Posted by on August 6, 2015 in Programming, Unity 3d

 

Tags: , , , , , , , , , ,

Unity3D: using ReorderableList in Custom Editor


ReorderableList is not a widely used class in Unity3D, but good use of it can make your custom editor more professional.

ReorderableList[5]

Read the rest of this entry »

 
2 Comments

Posted by on July 21, 2015 in Programming, Unity 3d

 

Tags: , , , , , , ,

Unity: Detect GUI Window Created/Closed Event


On StackOverflow, someone asks how to detect the GUI Window Created/Closed Event, which Unity3D does not ship an off-the-shelf solution.

Below is my solution to this problem: to use property setter to handle this. Here is the sample code:

enter image description here

Read the rest of this entry »

 
Leave a comment

Posted by on June 11, 2015 in Programming, Unity 3d

 

Tags: , , , , , , , , , , , ,

Unity3D: How to create a link button, with fun


How to create a link style button in Unity3D? Here the considerations include:

  1. The link button should look like a label, instead of a button
  2. The link button should work like a button, with clickable responses such as navigating to a URL;
  3. When the mouse hovers, the mouse cursor should look like a hand cursor, instead of the arrow cursor.

image

 

Read the rest of this entry »

 
1 Comment

Posted by on January 21, 2015 in Programming, Unity 3d

 

Tags: , , , , , , , , , , ,

Unity3D: how to implement Tabbed UI


Unity3D does not ship with the tabbed UI, however, we can cheat to implement this!

The key ideas include:

  • To use Toggle control
  • To make Toggle control look like a tab control

UnityTabDemo

The following code illustrates how this is done:

Read the rest of this entry »

 
3 Comments

Posted by on December 27, 2014 in Programming, Unity 3d

 

Tags: , , , , , , , , , ,

iTween onComplete event handler example


iTween is a handy library to implement tween/ease type animations. One of the useful callback it provides is the onComplete event. Below is an example code of how to use it:

iTween.MoveTo(lotus_leaf, iTween.Hash(
                      “y”, 80f,
                      “onComplete“, “OnShadeHidden”)
             );

void OnShadeHidden()
{
        Debug.Log(“The shade is hidden”);
        lotus_leaf.SetActive(false);
}

where lotus_leaf is the game object to be tweened in y position, and OnShadeHidden() is the callback function or event handler.

However if you run this code, you will see the callback OnShadeHidden is NOT fired when the tween is completed! The reason is that iTween needs another parameter: onCompleteTarget, to specify which object handles the onComplete event, so the right way to get it done will be like this:

iTween.MoveTo(lotus_leaf, iTween.Hash(
                      “y”, 80f,
                      “onComplete“, “OnShadeHidden”,
                      “onCompleteTarget“, gameObject)
             );

Run the code, the onComplete event handler will be properly addressed. Happy coding!

 
2 Comments

Posted by on December 14, 2014 in Unity 3d

 

Tags: , , , , , , , , ,