Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PromoController : MonoBehaviour {
  6.     public string url;
  7.     public float timeOut = 5f;
  8.  
  9.     public GameObject loadingOverlay;
  10.  
  11.     private UniWebView webView;
  12.     private bool isLoading;
  13.  
  14.     public void ShowMoreGames () {
  15.         if (!isLoading) {
  16.             Debug.Log ("----------------------------------------> REQUEST");
  17.             isLoading = true;
  18.             Invoke ("WebViewCancelLoad",timeOut);
  19.  
  20.             GameObject webViewGO = new GameObject("webview");
  21.             webView = webViewGO.AddComponent<UniWebView> ();
  22.             webView.OnLoadComplete += (UniWebView webView, bool success, string errorMessage) => {
  23.                 Debug.Log ("----------------------------------------> COMPLETE");
  24.                 isLoading = false;
  25.                 CancelInvoke ();
  26.  
  27.                 if (success) {
  28.                     Debug.Log ("----------------------------------------> SUCCESS");
  29.                     webView.Show (true,UniWebViewTransitionEdge.None,.5f,() => {
  30.                         loadingOverlay.SetActive (false);
  31.                     });
  32.                 } else {
  33.                     Debug.Log ("----------------------------------------> FAILURE");
  34.                     loadingOverlay.SetActive (false);
  35.                 }
  36.             };
  37.             webView.toolBarShow = true;
  38.             webView.url = url;
  39.             webView.Load();
  40.  
  41.             loadingOverlay.SetActive (true);
  42.         }
  43.     }
  44.  
  45.     private void WebViewCancelLoad () {
  46.         isLoading = false;
  47.  
  48.         Debug.Log ("----------------------------------------> STOP");
  49.         webView.Stop ();
  50.  
  51.         loadingOverlay.SetActive (false);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement