Vuforia: Delayed Initialization Explained


Vuforial is a widely used AR toolkit, and if you use it for some time, you will find “Delayed Initialization” for sure.

image

You would like to try it, right?

Go and do it, cry please, you will see below errors:

Vuforia cannot be started before it is initialized.Please disable Delayed Initialization in the Vuforia configuration or initialize Vuforia manually with the VuforiaRuntime-class.

image

You would Google this, frustrated, as you can hardly find good answers, and here is why this article comes into play. Continue reading “Vuforia: Delayed Initialization Explained”

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.

Continue reading “Using Firebase in Unity3D Tutorial 1: Basics and setup”

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

Continue reading “Unity3D: Get inspector property values programatically”

Step-by-Step guide for developing Android Plugin for Unity3D (II)


In previous blog, I have covered how to handshake Native Android code with Unity3D. The example shown therein is pretty simple: how to call a java function in C#!

In this blog, I am trying to step one more stride further: to create and use an Android View in Unity3D. The example shown here is an Android ImageView, however, this approach is generally applicable to all kinds of Android Views, ViewGroups and custom views.

imageAn Android ImageView

imageUse Android ImageView in Unity3D

Continue reading “Step-by-Step guide for developing Android Plugin for Unity3D (II)”

Backend server for Unity3D MMO games


There are many backend server systems that are commonly used in MMO games. Below are a few of them.

  1. You might try SmartFox, this link might be a good start for you. Below tutorials are also helpful for a quick start:

Specifically, you can connect to the smartfox server and get notified on connection:

private SmartFox client;
private string serverIP = "127.0.0.1";
private int serverPort = 9933;  
private string zone = "BasicExamples";

client = new SmartFox();           
client.ThreadSafeMode = false; //true for Unity3D
client.AddEventListener(SFSEvent.CONNECTION, (evt) =>
        {
            bool bSuccess = (bool)evt.Params[“success”];
            Console.WriteLine(client.IsConnected ?
                “Successfully connected to SmartFox Server” :
                “Failed to connect to SmartFox Server”);
        });           
client.Connect(serverIP, serverPort);            

To Login and get hooked when login succeeds:

var request = new LoginRequest("UserName", "Password", zone);  //[1]
client.Send(request);                                          //[2]

client.AddEventListener(SFSEvent.LOGIN, (evt) => {             //[3]
            Console.WriteLine("The User login success");       
});

client.Connect(serverIP, serverPort);   

 

2.  Photon is another popular backend server/service.

Photon Server provides you with turnkey frameworks for multiplayer games. Start from scratch or build your own custom logic on top of several demo applications included in source code with the free server SDKs. This lets you achieve great results fast and easy.

Code snippet for setup connection:

using UnityEngine;

public class RandomMatchmaker : MonoBehaviour
{
    void Start() {
        PhotonNetwork.ConnectUsingSettings("0.1");
    }

    void OnGUI(){
       GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
    }
} 

Code snippet for join room/lobby:

public override void OnJoinedLobby()
{
    PhotonNetwork.JoinRandomRoom();
}

Code snippet for setup logging:

PhotonNetwork.logLevel = PhotonLogLevel.Full;

Code snippet for error handling:

void OnPhotonRandomJoinFailed()
{
    Debug.Log("Can't join random room!");
    PhotonNetwork.CreateRoom(null);
}

A good tutorial on this topic can be found here.

3. Firebase might be the 3rd choice, though the performance is arguably unclear.

  • As an example, in roll20.net, you might find MMO game powered by Firbase.
  • Among others, FireSharp might be a very useful open source project for your quick start.

4. Others (OpenSpace, RedDwarf, ElectroServer, Player.IO, Red5, Mesmotronic Multiuser Server etc.)

See this great post for details.

Step-by-Step guide for developing Android Plugin for Unity3D (I)


This series of post outlines the development of Android plugins for Unity3D. I had been asked to develop Android plugins for Unity3D every few days or months, each time following similar paths which I think would be useful to those who will do the same job. And here is how.

Clone the source code in GitHub here !

Tools you need:

  • Android Studio
  • Unity3D
  • Android Devices for testing
  • Some patience to go through this post

Let’s get started.

The 1st example is extremely simple. We define a function DoSthInAndroid() that dump some information using Java Log.i() function, and get this function called in Unity3D. Though simple enough, it outlines all the required procedures, and are very useful to understand the entire workflow.

  • Start Android Studio, create an Android project (AndroidAddin) with an Empty Activity.
  • In Android Studio, create another library project (AndroidLib) by clicking the menu File > New > New Module

image

Continue reading “Step-by-Step guide for developing Android Plugin for Unity3D (I)”

Packaging Unity3D MonoBehaviour script into DLL


You might have dozens or even hundreds of MonoBehaviour based scripts in your typical Unity3D projects.

For some reasons, either you want to protect your source code from direct access by others, or you might want to put stable helper utility functions in a separate assembly, it is likely that you would like to package all these scripts into a .net assembly in the form of a DLL.

This post focuses on the detailed procedures to implement such functions.

  1. If you use Mac OSX,  create a new solution in Xamarin Studio (or MonoDevelop); if you are in Windows, use Visuals studio:

    s1

  2. Create a library project:

    s2

  3. Add references of UnityEngine.dll and/or UnityEditor.dll to the project, you can do so by browsing into the folder (typically, depending on your specific Unity3D installation directory):
    Mac:              /Applications/Unity/Unity.app/Contents/Frameworks/Managed/
    Windows:      C:\Program Files\Unity\Editor\Data\Managed
  4. Add or create the MonoBehaviour script to the library project. In this example, I just created a new script, which is pretty simple:

    s3
     
  5. Now, here comes the most important step, and most developers fail to be successful in packaging the scripts into DLL, simply due to missing of this step: change the .net version to .Net 3.5 in project settings.
    On OSX (Xamarin Studio): Click menu Project > [YourProject] Option, select Build > General on the left panel, and then select Mono/.Net 3.5, as shown below:

    s4

    On Windows (Visual Studio), select the project, press ALT + Enter, and in the popup dialog, change the .Net version to .Net 3.5.

  6. Build the assembly, and find the generated dll in the bin folder;
  7. Copy the dll into the Assets/ folder of our Unity Project:
    Note: You don’t have to put this dll into /Plugins folder
  8. Now expand the DLL assembly in Unity3D, you will find an icon for your script:

    s5

  9. Drag the MonoBehaviour to a game object, and run the app!

    s6.png

Yeal, you get what you want now! Happy clean coding!

Unity3D: using Visual Studio Code and hide meta and other unwanted files


Go to Visual Studio Code preference, click “Preference” > “User Settings” or “Project Settings”, add below code in the “Settings.Json” file:

vscode_hide2

// Place your settings in this file to overwrite the default settings
{
    "files.exclude": {
    "**/*.meta": true,
    "Temp": true,
    "Library": true,
    "ProjectSettings": true,
    "obj": true,
    ".vs": true,
    ".vscode": true,
    "Assembly-C*.*": true,
    "*.csproj":true,
    "*.orig":true,
    "*.user":true,
    "*.userprefs":true
    }
}

 

Now, the VS code will cleanly show the files that you need.