Wednesday, April 22, 2015

Check for Network Connection Unity3d

Two type of devices are their when concerning about Network Connection,

  • Hand Held Devices - iPhone, iPad, Android, Windows Phone, Tablets etc.
  • Non Hand Held Devices - PC, Mac, Linux etc

There are various aspects need to keep in mind when checking for network connection in unity3d development environment.

Unity provides various classes to do so, some of those are listed below with best suitable example for that, hope this might get some relief..

Application.internetReachability can be use to check current reachable type, this can be use on all kind of device including hand held devices, this returns a member of an enum NetworkRechability, Bare in mind that this only checks all possible network connection on device but not guaranteed that device is connected to the internet. 

This can be use to distinguish whether device is connected via high speed wifi/local area network or using packetdata/career data network


Below are all network reachability options that NetworkReachability enum have,
  • ReachableViaCareerDataNetwork
  • ReachableViaLocalAreaNetwork
  • NotReachable


Usage Example:

using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour

{
public static bool IsInternetConnection()
{
bool isConnectedToInternet = false;
if(Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork ||
   Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
isConnectedToInternet = true;
}
return isConnectedToInternet;
}
}


To check for Internet Connection,

IEnumerator CheckForConnection() 
{
      Ping png = new Ping("139.130.4.5");
      float startTime = Time.time;      
      while (Time.time < startTime + 5.0f)       
     {         
            yield return new WaitForSeconds(0.1f);      
     }
      if(png .isDone)      

     {
           print("Connected!");  
     }     
     else    
     {    
            print("Not Connected!");
     }
}

Friday, February 20, 2015

Create Windows Installer for Unity3d


Here easy steps are shown to create Windows Installer(formerly knows as Microsoft Installer) for your Unity game,


Tool to Use:

Inno Setup

You can easily download free installer from here,

Prerequisites:

1. Needed working windows build of your game which includes *_Data and *.exe files
2. Inno Setup


Steps:

1. Install Inno Setup with default settings


2. Launch Inno Setup

3. Create a new script file using the Script Wizard and press OK
The first time you open Inno Setup it will ask to create Script using Inno' powerful script wizard,
You just need to create New Script using it,

4. Click Next





5. Fill all the necessary information and click Next




















Most options of setup wizard are optional, so you can leave whichever don't suits you,

 6. click Next

7. Brows and add Application main executable file, also add parent folder to Other application files,  this is as in unity there exists one more file with main executable file named *.Data



















8. On adding parent folder it will ask for conformations, select Yes in it











9. Now select options whichever suits you and click Next




















10. If you have application documentation then browse and add in next option otherwise leave those as it is and click on Next




















11. Inno Setup also supports multiple language, you can specify it in next option, specify all languages you want to include in your setup and click Next



















12. Select the folder where you want to store the setup file and click Next



















13. In last it will ask to add Inno Preprocessor, this is for internal use only, just check Yes and click Next



















14. Finish



















15. It will prompt for compilation, click Yes












16. Also ask for saving script you have created, click Yes












17. Now you can see script compilation process, just wait for a moment and your Unity game is ready to install

















Just install and ...have fun! 



Popular Posts