Skip to content

An extension of UnityEngine's Ping to provide address resolution, timeout, async/await and a meaningful return object. Samples contain a use case of checking internet connectivity with it.

License

Notifications You must be signed in to change notification settings

AntonZhernosek/UnityPing

Repository files navigation

UnityPing

Dotnet Ping has issues around working in builds and improperly resolving addresses. UnityEngine's Ping works well in builds, but it's primitive and needs wrappers to function properly. This extension wraps around Unity Engine's Ping, allowing it to resolve addresses, timeout, support async/await and return a meaningful UnityPingReply object from a ping attempt. All logged exceptions and Debug.Logs in the code are UnityEditor only.

Example Usage

public class ExampleClass : MonoBehaviour 
{
    private async Task PingSomething(string address, int pingTimeout, CancellationToken ct)
    {
        UnityPingReply pingReply = await UnityPing.SendPingAsync(address, pingTimeout, ct);

        if (pingReply.IsSuccessful)
        {
            Debug.Log(pingReply.RoundtripTime);
            // Do stuff
        }
        else
        {
            Debug.Log(pingReply.Error);
            // Do other stuff
        }
    }
}

Samples

Samples contains a small scene and a script that can be used to check if a player is connected to the internet via UnityPing. PingChecker is a small object that will test internet connectivity by using UnityPing and can print the results to console unity_inspector

About

An extension of UnityEngine's Ping to provide address resolution, timeout, async/await and a meaningful return object. Samples contain a use case of checking internet connectivity with it.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages