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! 



Tuesday, September 9, 2014

Draw Call and FPS

         Performance is the crucial thing while you are dealing with game development for hand held devices! Before going optimized and performance oriented game development, one should understand key terms for measuring device performance. The major unit(yes we can say Unit) for device performance is FPS and Draw Call


FPS:

         FPS is Frame Per Second, time taken by device CPU to complete one frame. Human eye can see about 30 framers per second. So for smoother game play generally it is set to 60 for all Android, iOS and other mobile platforms so that graphics and all visuals are visible in high quality. So as a game developer one should try to achieve 60 FPS for game.


Draw Call:

         Draw Call is another unit that is concerned with device GPU(Graphics Processing Unit) directly. They are generated each time the CPU has to send data to the GPU for processing. Draw call can be stated as no of calls that GPU need to made to render an image/texture or mesh. The higher draw call the higher GPU call is made which results in higher power consumption. Higher draw call might also reduce FPS but this is not compulsory.

Saturday, August 30, 2014

Best Practice for Game Development

Hello developers,
           Here i am sharing game development phases that one should go with, Especially for indie game developers and studios.




           If you are planing to being game developer then their are lots of factors you should keep in mind, as being a game developer is not as easy as playing a game. It is inverse it.

Key phases for game development,


1. Market Research


           Before planning for any kind of game development one should make some research on current game trends, game user audience, game platforms etc. This would help a lot for your game and make you more clear what should you choose for your game.

         For example: If their is currently trend of 2048 kind of game then you can either go for same game development or similar kind of game development, so that you can easily redirect 2048 game users to you game and make money. Or if you are planning to rock the game market then you can choose your own concept and make it on stage. Its up to you how you are going!

Area of Research:

1. Current market trends
2. Targeted audience and country
3. Targeted platforms
4. Game category and scope
5. Age group

2. Game Design

           Game design is the main factor after market research if you are planning to develop a game, and it is ignored by most of indie game developer but i recommend to spend much time on designing a game rather planning for other stuffs. The more effort you made on designing the game the less effort would required on developing and marketing your game.

           For example : If you are planning to do like Subway Surfer like endless runner game then you will probably gathers basic requirements for your game and start development but in between of actual development if you will find more entertaining game then Subway Surfer then probably you would change your game design and this will result in delay of your product as well might be costly to packet.

Topics covered in game design:

1. Game story/Game concept
2. Game category
3. Game play and HUD design
4. Power ups
5. Future update
6. Dealing with developer team
7. Game engine selection and limitations
8. Multiple platform support
9. Marketing scenario

3. Graphics Development

           Once game design phase is completed the product would come in development phase, here it will come in graphics and UI development phase.


           If game is 3d then it would come in animation/model development and this would start your actual product development.

           Graphics development is very important part of your game as graphics is the one who makes first impression when you game is released. If game is containing eye catching graphics then use would probably download and play your game at least once.

4. Game Programming

           This is where your product is got rigged. Yes game programming is the phase where product is actually got rigged and lead to playable game.

           Game programming phase is one of most expensive phase of game development. Previous three phase would be gathered and programming team starts on product development. The more effort on programming makes product more engaging. This is where programming team is adding Physics, Animations, Event system, Third party tools, VFX(particles and all) and Sounds.

           Once game is downloaded journey is not stooped here, it is started actually. User would only sticked to game he/she found something engaging or unique in game otherwise he/she will simply uninstall game and never recommend others to play it. If he/she will found something engaging or unique in game they game would be played and also recommended to others. That would result in inter user marketing and of course that makes your pocket heavy.

5. Game Marketing(App Store Optimization)



           Once your product has been developed, tested and released successfully this phase starts. This is where your actual journey starts! Yes it is, your game is containing pretty and eye catching graphics, is has been executed nicely on game programming phase but if there is no marketing there is not installs of your game.

           This is where most of indie developer/studio got punched,  their are lost of game stores/portals are available, their are millions of games/apps on the game market, hundreds of game are released per day.. Out of them where your game would be ? Area of thinking.. Like any newly released website for game also their would require lots of marketing to attract user to download and play the game.


Marketing Agenda and Type

1. Social media marketing
2. Google AdMob or other advertiser platform 
3. Video marketing
4. Inter game or Inter user marketing
5.  Content based marketing

Tuesday, August 26, 2014

Getter and Setter in C# Unity3d

C# Unity has support for Getter and Setter properties which is very important in terms of Object Oriented Programming, Here is a simple example of Getter and Setter properties which shows its usefulness,
Without getter and setter properties:
  1. public int getX()
  2. {
    1. return x;
  3. }
  4. public void setX(int newX)
  5. {
  6. if(newX < 0)
  7. x = 0;
  8. else
  9. x = newX;
  10. }
To change the value of x you have to write like
  1. setX(getX()+4);
With getter and setter properties:
  1. public int X
  2. {
  3. get { return x; }
  4. set
  5. {
  6. if(value < 0)
  7. x = 0;
  8. else
  9. x = value;
  10. }
  11. }
Now in this case you can easily change value of x with 
  1. X += 4;
Getter and Setter is very usefull properties of C# programming language and can be utilize interestingly in Game Development also in Unity3d.

To know some basic but important key points about C# programming language go HERE,


Some basic use of these properties listed below,

1. Flexible way to get and set values conditionaly.
2. Works great with Unity3d Transform and other Vector properties.
3. Use mainly in Score/Health calculation/computaion etc.

Monday, July 28, 2014

Resolution Manager Script Unity3d

Hello developers,
As a mobile app/game developers it is not quite easy to make app/game UI same on different resolution devices,
In previous post you can see common resolutions with aspect ratios, also most used resolution devices among with that,
Below is the Unity3d Monobehaviour version of that discussion which is quite easy to get and use,

using UnityEngine;
using System.Collections;

public class ResolutionManager : MonoBehaviour 
{
public int bgWidthToLaod = 800;

float xWidth;
float yHeight;

void Awake()
{
xWidth = Screen.width;
yHeight = Screen.height;

float aspectRatio = xWidth / yHeight;

if(aspectRatio >= 1.30f && aspectRatio <= 1.35f)
{
// 2048 * 1536
aspectRatio = 1.33f;
bgWidthToLaod = 2048;
}
else if(aspectRatio >= 1.45f && aspectRatio <= 1.55f)
{
// 960 * 640
aspectRatio = 1.5f;
bgWidthToLaod = 960;
}
else if(aspectRatio >= 1.58f && aspectRatio <= 1.70f)
{
// 1280 * 768
aspectRatio = 1.67f;
bgWidthToLaod = 1280;
}
else if(aspectRatio >= 1.75f && aspectRatio <= 1.80f)
{
// 1136 * 640
aspectRatio = 1.78f;
bgWidthToLaod = 1136;
}
else
{
aspectRatio = 1.67f;
bgWidthToLaod = 1280;
}
}
}

Tuesday, July 22, 2014

Unity3d Important Methods and its Priority Order

Some Unity3d important methods and its usage with priority order,

[1] Awake : 

        Called just after object got initialized, also for prefab. It is called before Start function call. If gameobject is disabled Awake is not called, but if any function of this script or function of script attached to same object is invoked, object would be initialized and Awake is called. This is where most of developers got confused with Awake method invocation.
Priority : 1


[2] OnEnable : 

        This is called when Monobehaviour is enabled. It is also called before Start call. If object is not active this will not be invoked.
Priority : 2


[3] Start :

        Start is called before any frame update started if object is enabled.
Priority : 3

[4] FixedUndate :

        Fixed update is called more frequently then Update call if frame rate is low. If frame rate is high then it might called less frequently then Update call. Fixed update is called on reliable basis then Update function that's why you do not need to multiply movement calculation with Time.deltaTime. All physics related calculation should be placed inside FixedUpdate to make it behave correctly.
Priority : 4


[5] Update : 

        Update is called once per frame. This is main function in Unity3d Monobehaviour. If frame rate is set to be high then all input related code should be placed here to avoid input issues.
Priority : 5


[6] LateUpdate :

        LateUpdate is also called once per frame. The only difference between Update and LateUpdate is that its been called once Update has completed its execution. This will be very usefull in case where there is a need of task to be executed if and only if another task got completed. 
Example : Camera movement, score calculation, input management.
Priority : 6


[7] OnDisable : 

        This is called when Monobehaviour becomes inactive/disabled.
Priority : 7


[8] OnGUI :

        This function is called multiple time per frame, might call double then the Update call depending upon current frame rate. All input related code should be place in this function. Main use of this function is two draw various UI elements. Thought it is not advisable to use this function as of performance issues.

Sunday, July 20, 2014

Resoultions and Aspect Ratio

As a mobile game/app developer it is headache to port game/app to various mobile/hand held devices having different resolutions. Here is the list of resolutions for all major mobile and hand held devices which would help you while developing cross platforms mobile applications and games,

Resolutions* (AR*)

2048 * 1536 --> 1.33
1024 * 768 --> 1.33
1136 * 640 --> 1.78
960 * 640 --> 1.50
854 * 480 --> 1.78
800 * 480 --> 1.67
800 * 400 --> 1.50
2560 * 1536 --> 1.67
2560 * 1600 --> 1.60
1920 * 1080 --> 1.78
1920 * 1200 --> 1.60
1920 * 1152 --> 1.67
1824 * 1200 --> 1.52
1536 * 1152 --> 1.33
1280 * 720 --> 1.78
1280 * 800 --> 1.60
1280 * 768 --> 1.67
1024 * 600 --> 1.71
1024 * 800 --> 1.28
960 * 600 --> 1.60

* Resolutions are in Pixels
* AR - Aspect Ration

Most used aspect ratios,

1.33 - iPad, iPad 2, iPad Retina
1.50 - iPhone 4, iPhone 4s
1.67 - Most of Android devices
1.78 - iPhone 5, iPhone 5s, iPhone 5c, Android Tab Series

Monobehaviour script for resolutions and aspect ration is here.

Sunday, July 13, 2014

Facts About Unity3d Coroutines

         Here are some of important facts of Unity3d Coroutines which might help you,

1. You can only stop Coroutines that are invoked using StartCoroutine with string as a argument.


Example:


StartCoroutine("MethodName") can be stop using StopCoroutine("MethodName"),
Coroutines those are invoked as StartCoroutine(MethodName()) will not be cancelled by StopCoroutine("MethodName").

2. You can invoke other class Coroutine even after it is  marked as Private.

Example:


Class1.cs


using UnityEngine;
using System.Collections;

public class Class1 : MonoBehaviour {


// Use this for initialization

void Start () {
}

// Update is called once per frame
void Update () {
}

private void DemoCoroutine(){

print("Coroutine Invoked!");
}
}


Class2.cs


using UnityEngine;
using System.Collections;

public class Class2 : MonoBehaviour {


        // Reference Assigned in Inspector

public Class1 Class1Instance;

// Use this for initialization

void Start () {
        // You can even use singleton calss to invoke Coroutine defined in different class
Class1Instance.StartCoroutine("DemoCoroutine");
}

// Update is called once per frame
void Update () {
}
}


More about Unity3d Coroutine,

Friday, July 4, 2014

Shaders and It's Best Usage

Here is the basic details of Unity3d's inbuilt shaders and best usage of it,


Particles - Mobile/Particles/Alpha Blended
Particles - Mobile/Particles/Addictive
Transparent Background - Mobile/Particles/Alpha Blended
Line Renderer - Particles/VertexLit Blended

Tuesday, July 1, 2014

Facts about Resources folder in Unity3d

Some facts about Resource folder in Unity3d,

    The Resources folder is a special folder which allows you to access assets by file path and name in your scripts, rather than by referencing them in Unity Inspector.
  • All the assets of Resources will be included in build generated(even if it is not used in anyway).
  • Resources folder would not exist when build is generated, It exists in editor only.
  • Multiple resources folder can be used, Unity will examine assets from all the Resource folders. So it is not recommended to use same named asset in two different Resources folder.
  • All the assets found in Resources folder will be stored in resources.assets file, when build is generated.
  • It can be used to load Textures, Materials, AudioClips etc.
  • Prefab can also be instantiated directly form Resource folder as shown below,
Example,
GameObject gameObj = Instantiate(Resouces.Load("ObjectName", GameObject));
OR
GameObject gameObj = Instantiate(Resouces.Load<GameObject>("ObjectName"));
OR
GameObject gameObj = Instantiate(Resouces.Load("ObjectName", typeof(GameObject)));

Note : Only forward shash('/') is allowed to use to indicate path of assets in Resources, backward shash('\') would not work.


Sunday, June 29, 2014

Texture Fadein Fadeout using Coroutine - Unity3d

Code for making fadein, fadeout in Unity3d C#,


Fadein,

IEnumerator FadeIn(GameObject gameObj)
 {
  for (float f = 0f; f <= 1; f += 0.01f)
  {
   Color c = gameObj.renderer.material.color;
   c.a = f;
   gameObj.renderer.material.color = c;
   yield return new WaitForSeconds(.01f);
  }

  yield return null;
 }

Fadeout, 

IEnumerator FadeOut(GameObject gameObj)
 {
  for (float f = 1f; f >= 0; f -= 0.01f)
  {
   Color c = gameObj.renderer.material.color;
   c.a = f;
   gameObj.renderer.material.color = c;
   yield return new WaitForSeconds(.01f);
  }

  yield return null;
 }

Pre Requisites: Object you are passing  as argument must have shader which has color property in it.

FadeInFadeOut using NGUI UISprite and Coroutine,


 public UIAtlas RunTimeAtlas;

IEnumerator ColorFadeInFadeOut() 
{
UISprite newSprite = NGUITools.AddWidget<UISprite>(GameObject.Find("Story"));
newSprite.depth = 6;
newSprite.gameObject.name = "FadeInFadeOut";
newSprite.atlas = RunTimeAtlas;
newSprite.spriteName = "White120";
newSprite.SetDimensions (Screen.width * 3, Screen.height * 3);
TweenAlpha ta1 = newSprite.gameObject.AddComponent<TweenAlpha> ();
ta1.from = 0.0f;
ta1.to = 1.0f;
yield return new WaitForSeconds(1.10f);
TweenAlpha ta2 = newSprite.gameObject.AddComponent<TweenAlpha> ();
ta2.from = 1.0f;
ta2.to = 0.0f;
yield return new WaitForSeconds(1.0f);
NGUITools.Destroy(newSprite.gameObject);
}

Pre Requisites: Atlas reference must be assigned to RunTimeAtlas in Unity Inspector having white texture in it. Texture of other color can also be used for fade in and fade out effect.

Monday, June 23, 2014

Camera and Texture settings to make 2d game in Unity

Here are some basic Camera and Texture setting for 2d game development in Unity3d,


(1). Choose 'Point' as the filter mode for your textures.
(This is essential for making your textures sharp).

(2). Choose 'Advanced' as your 'Texture Type' and disable 'Generate Mip Maps'.
(This is also important for 2d game, it reduces texture size as well).

(3). Choose 'RGBA 32 bit' as your 'Texture Format'.
(Choose lesser until your texture quality remains, this is also for texture memory size).

(4). Set your Camera Projection to 'Orthographic'.
(To make game for 2d view only).

(5). Set your 'Orthographic Size' to your screen height / 2.
(This makes 1 unit in Unity equals 1 pixel on your textures).

(6). Create a Quad by following Menu -> GameObject -> Create Other -> Quad in Unity.

(7). Scale your Quad to same size as your texture.
(A 256*256 texture needs a 256*256 quad).

Note : Textures you are using must be POT(Power Of Two) textures.

Code snippets to set Camera size,


using UnityEngine;


public class 2dCameraScale: MonoBehaviour 
{
    void Awake () 
    {
        Camera.main.orthographicSize = Screen.height / 2;
    }
}

Post Note : The topic is posted for Unity3d v. 4.2.1 or older mainly, in newer versions their are lots of 2d related stuffs are added. Though you can use above settings for newer version also. ;)

Popular Posts