Getting Started

Setting Eazy NetChecker up and using it is super easy and straightforward. It is also extremely flexible since it allows you to use either the editor to set it up, or do everything with code on runtime. Of course, using both is also possible. Everything will be explained for both ways.

Setup

Editor

The only initial setup needed for the editor, is to create the Eazy NetChecker GameObject. This can easily be done by either navigating to GameObject > Hellmade Games and selecting Eazy NetChecker. This will create a GameObject in your scene with the Eazy NetChecker component on it. You can always create an empty GameObject and add the Eazy NetChecker component yourself too.

Eazy NetChecker editor

Runtime

If you want to handle everything with code, there is no reason to add an Eazy NetChecker GameObject. It will automatically be created and initialized for you as soon as you reference it for the first time in your code.

Make sure to always include the namespace Hellmade.Net when using Eazy NetChecker from code. Just use this on the top of every script that uses Eazy NetChecker:

using Hellmade.Net;

Check Internet connection

Checking for internet connection can be done in a few ways. You can manually perform a check once, start a continuous check which will be performed on a specified interval, or perform a check on start up.

Before you perform any kind of check, you need to select which check method you want to use. For the standard check methods, just use the appropriate check method selection function:

EazyNetChecker.UseGoogle204Method();

You can also select a check method in the editor before runtime

If no check method is specifically selected, one of the standard check method will be choosen automatically, based on the platform running:

  • Windows (MicrosoftNCSI)

  • Linux/Android (Google204)

  • MacOS/iOS (AppleHotspot)

Manual Check

The simplest case would be to perform a single manual check:

private void Awake()
{
    EazyNetChecker.UseGoogle204Method();
    EazyNetChecker.OnCheckFinished += OnNetCheckFinished;
    EazyNetChecker.CheckConnection();
}

private void OnNetCheckFinished() 
{ 
    Debug.Log(EazyNetChecker.Status); 
}

This will start a process for checking the current internet connection status in the background. The check method will raise various events during its lifetime. In this example, we added a listener to the OnCheckFinished event, which will be raised as soon as a check is finished. Here the check is performed on awake, but of course you can perform an internet check whenever and wherever you need to.

Continuous Check

You can also start a continuous check, which will run on a specified interval, until you decide to stop it:

private void Awake()
{
    EazyNetChecker.UseGoogle204Method();
    EazyNetChecker.OnConnectionStatusChanged += OnNetStatusChanged;
    EazyNetChecker.StartConnectionCheck();
}

private void OnNetStatusChanged() 
{ 
    Debug.Log("Internet Connection Status changed to: " + EazyNetChecker.Status); 
}

The above example will perform a check every 20 seconds (default). It also listens to the OnConnectionStatusChanged event, which is raised everytime the status of the internet connection is changed (after a check is performed).

You can use whatever events you like, depending on your specific game logic. You can even not use an event, and implement your logic by checking the current detected internet connection status like the example below:

private void Awake()
{
    EazyNetChecker.UseGoogle204Method();
    EazyNetChecker.StartConnectionCheck();
}

private void Update() 
{ 
    if(EazyNetChecker.Status == NetStatus.Connected)
    {
        Debug.Log("Yeyyyy, I have internet!");
    }
    else
    {
        Debug.Log("No internet :(");
    }
}

Settings

The check interval (time between continuous checks), and the timeout time can also be changed. Eazy NetChecker can be configured using both the editor and the runtime API.

Editor

Configuring the settings through the editor is very straightforward. All of them can be found in the Settings section

Settings section

Runtime

All settings can be set before you perform a check:

private void Awake()
{
    EazyNetChecker.CheckInterval = 30f;
    EazyNetChecker.Timeout = 15f;
    EazyNetChecker.ShowDebug = true;
    
    EazyNetChecker.UseGoogle204Method();
    EazyNetChecker.StartConnectionCheck();
}

Last updated