# 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.

{% hint style="warning" %}
Do not create or have more than one Eazy NetChecker in the same scene. Eazy NetChecker retains its life over different scenes, so you only need to create it once, in your first scene.
{% endhint %}

![Eazy NetChecker editor](https://3856756291-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFXevXwVadIl1QHW1RH%2F-LFqW9eDdfDXd2rWTF-k%2F-LFqWhKDWCXbskr8Ljzd%2Fimage.png?alt=media\&token=f4aca1f3-f580-4214-8342-8b12d187cae4)

#### 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.

{% hint style="info" %}
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;`**
{% endhint %}

## 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](https://hellmadegames.gitbook.io/eazy-netchecker/check-methods) you want to use. For the standard check methods, just use the appropriate check method selection function:

```csharp
EazyNetChecker.UseGoogle204Method();
```

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

![](https://3856756291-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFXevXwVadIl1QHW1RH%2F-LFqW9eDdfDXd2rWTF-k%2F-LFqWu-5ya-YPgFtHHlE%2Fimage.png?alt=media\&token=5b4e0863-c160-4f10-bafe-3fd12dc9bbd0)

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:

```csharp
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](https://hellmadegames.gitbook.io/eazy-netchecker/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:

```csharp
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:

```csharp
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](https://3856756291-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LFXevXwVadIl1QHW1RH%2F-LFqW9eDdfDXd2rWTF-k%2F-LFqXAffN4utK-GlJSSp%2Fimage.png?alt=media\&token=d1b9ff02-1c55-4281-bab0-a9116135070a)

#### Runtime

All settings can be set before you perform a check:

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