Posted on

Web View – Cross Platform Native Plugins: Essential Kit

Download

Documentation: https://assetstore.essentialkit.voxelbusters.com/

0:00 Welcome to Web View Cross Platform Native Plugins: Essential Kit
0:23 Overview
1:20 Setup
1:57 Usage

The Web View service makes it so you can display a web page through a window in your game. This can be used in several different ways such as having a web login screen or display your terms and conditions.

IG_Webview.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VoxelBusters.CoreLibrary;
using VoxelBusters.EssentialKit;

public class IG_Webview : MonoBehaviour
{
    public static IG_Webview instance;

    WebView CurrentWebView;

    private void OnEnable()
    {
        // register for events
        WebView.OnShow += OnWebViewShow;
        WebView.OnHide += OnWebViewHide; 
        WebView.OnLoadStart += OnWebViewLoadStart; 
        WebView.OnLoadFinish += OnWebViewLoadFinish; 
    }

    

    private void OnDisable()
    {
        // register for events
        WebView.OnShow -= OnWebViewShow;
        WebView.OnHide -= OnWebViewHide; 
        WebView.OnLoadStart -= OnWebViewLoadStart; 
        WebView.OnLoadFinish -= OnWebViewLoadFinish; 
    }
    // Start is called before the first frame update
    void Start()
    {
        instance = this;
    }

    //IG_Webview.instance.NewWebView(webpageURL);
    public void NewWebView(string URL)
    {
        CurrentWebView = WebView.CreateInstance();
        CurrentWebView.SetFullScreen();
        CurrentWebView.LoadURL(URLString.URLWithPath(URL));
        CurrentWebView.Show();
    }

    //IG_Webview.instance.HideCurrentWebview();
    public void HideCurrentWebview()
    {
        CurrentWebView.Hide();
    }


    private void OnWebViewShow(WebView result)
    {
        Debug.Log("Webview is being displayed : " + result);
    }

    private void OnWebViewHide(WebView result)
    {
        Debug.Log("Webview is hidden : " + result);
        
    }

    private void OnWebViewLoadStart(WebView result)
    {
        Debug.Log("Webview is being displayed : " + result);
    }

    private void OnWebViewLoadFinish(WebView result, Error error)
    {
        Debug.Log("Webview is being displayed : " + result);
    }

    
}
Posted on

Network – Cross Platform Native Plugins: Essential Kit

Download

Documentation: https://assetstore.essentialkit.voxelbusters.com/

0:00 Welcome to Network and Web View CPNP2
0:16 Overview
0:36 Setup
1:08 Usage

For this lesson on how to use the Cross Platform Native Plugins in Unity, I will show you how to use the Network and Web View services. The Networking service makes it so you can check to see if the user’s device has a connection to the internet. You are then able to block the user from accessing parts of your game if they don’t have a network connection.

IG_NetworkServices.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VoxelBusters.EssentialKit;

public class IG_NetworkServices : MonoBehaviour
{
    public static IG_NetworkServices instance;

    public bool isInternetActive;
    public bool isHostReachable;
    public bool isNotifierActive;

    private void OnEnable()
    {
        // register for events
        NetworkServices.OnHostReachabilityChange += OnHostReachabilityChange;
        NetworkServices.OnInternetConnectivityChange += OnInternetConnectivityChange;
        NetworkServices.StopNotifier();
    }

    private void OnDisable()
    {
        // unregister from events
        NetworkServices.OnHostReachabilityChange -= OnHostReachabilityChange;
        NetworkServices.OnInternetConnectivityChange -= OnInternetConnectivityChange;
    }

    // Start is called before the first frame update
    void Start()
    {
        instance = this;
    }

    private void OnInternetConnectivityChange(NetworkServicesInternetConnectivityStatusChangeResult result)
    {
        Debug.Log("Received internet connectivity changed event.");
        Debug.Log("Internet connectivity status: " + result.IsConnected);
        isInternetActive = NetworkServices.IsInternetActive;
    }

    private void OnHostReachabilityChange(NetworkServicesHostReachabilityStatusChangeResult result)
    {
        Debug.Log("Received host reachability changed event.");
        Debug.Log("Host reachability status: " + result.IsReachable);
        isHostReachable = NetworkServices.IsHostReachable;
    }

    //IG_NetworkServices.instance.CheckNetwork();
    public void CheckNetwork()
    {
        NetworkServices.StartNotifier();
    }

    //IG_NetworkServices.instance.StopStatus();
    public void StopStatus()
    {
        NetworkServices.StopNotifier();
    }
}
Posted on

Address Book – Cross Platform Native Plugins: Essential Kit

Download

Documentation: https://assetstore.essentialkit.voxelbusters.com/

0:00 Welcome to Address Book CPNP2
0:18 Overview
0:34 Setup
1:05 Usage

The Address Book allows the user to access their contacts inside your game. This can be helpful in sharing your game.

IG_AddressBookService.cs

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VoxelBusters.CoreLibrary;
using VoxelBusters.EssentialKit;

public class IG_AddressBookService : MonoBehaviour
{
    public static IG_AddressBookService instance;

    AddressBookContactsAccessStatus status;

    public IAddressBookContact[] allContacts; //IG_AddressBookService.instance.allContacts[index];

    // Start is called before the first frame update
    void Start()
    {
        instance = this;
    }

    //IG_AddressBookService.instance.ReadContacts();
    public void ReadContacts()
    {
        status = AddressBook.GetContactsAccessStatus();
        if (status == AddressBookContactsAccessStatus.NotDetermined)
        {
            AddressBook.RequestContactsAccess(callback: OnRequestContactsAccessFinish);
        }
        if(status == AddressBookContactsAccessStatus.Authorized)
        {
            AddressBook.ReadContacts(OnReadContactsFinish);
        }
    }

    private void OnRequestContactsAccessFinish(AddressBookRequestContactsAccessResult result, Error error)
    {
        Debug.Log("Request for contacts access finished.");
        Debug.Log("Address book contacts access status: " + result.AccessStatus);
        if (result.AccessStatus == AddressBookContactsAccessStatus.Authorized)
        {
            AddressBook.ReadContacts(OnReadContactsFinish);
        }
    }

    private void OnReadContactsFinish(AddressBookReadContactsResult result, Error error)
    {
        if (error == null)
        {
            allContacts = result.Contacts;

            var contacts = result.Contacts;
            Debug.Log("Request to read contacts finished successfully.");
            Debug.Log("Total contacts fetched: " + contacts.Length);
            Debug.Log("Below are the contact details (capped to first 10 results only):");
            for (int iter = 0; iter < contacts.Length && iter < 10; iter++)
            {
                Debug.Log(string.Format("[{0}]: {1}", iter, contacts[iter]));
            }
        }
        else
        {
            Debug.Log("Request to read contacts failed with error. Error: " + error);
        }
    }
}