Example #1
0
    public void OnSearch()
    {
        webViewObject.SetVisibility(true);
        searchItemName = InputText.text;

        if (flag == 1)
        {
            flag = 0;


            //Change Scene
            SceneManager.LoadSceneAsync("WebView");
            CameraPanel.SetActive(true);
            SearchPanel.SetActive(false);
            SearchPanel2.SetActive(true);
            sampleWebView.SetActive(true);

            //PlayAnimation
            animSearchBox.Play("GoUp");

            //Reload
            Debug.Log("---------------------------------------------------" + Url + searchItemName.Replace(" ", "%20"));
            onWebViewLoad.LoadSampleWebView(searchItemName);
        }
        else if (flag != 1)
        {
            //Reload
            Debug.Log("---------------------------------------------------" + Url + searchItemName.Replace(" ", "%20"));
            onWebViewLoad.LoadSampleWebView(searchItemName);
        }
    }
Example #2
0
/*
 #if !UNITY_WEBPLAYER
 *  void OnGUI()
 *  {
 *      //Nav Buttons
 *      GUI.enabled = webViewObject.CanGoBack();
 *      if (GUI.Button(new Rect(10, 10, 80, 80), "BACK")) {
 *          webViewObject.GoBack();
 *      }
 *      GUI.enabled = true;
 *
 *      GUI.enabled = webViewObject.CanGoForward();
 *      if (GUI.Button(new Rect(100, 10, 80, 80), ">")) {
 *          webViewObject.GoForward();
 *      }
 *      GUI.enabled = true;
 *
 *      GUI.TextField(new Rect(200, 10, 300, 80), "" + webViewObject.Progress());
 *
 *      if (GUI.Button(new Rect(600, 10, 80, 80), "*")) {
 *          var g = GameObject.Find("WebViewObject");
 *          if (g != null) {
 *              Destroy(g);
 *          } else {
 *              StartCoroutine(Start());
 *          }
 *      }
 *      GUI.enabled = true;
 *
 *      if (GUI.Button(new Rect(700, 10, 80, 80), "c")) {
 *          Debug.Log(webViewObject.GetCookies(Url));
 *      }
 *      GUI.enabled = true;
 *  }
 #endif
 */



    // Update is called once per frame
    void Update()
    {
        if ((swipeUpPanel.GetComponent <PageSwiper>().currentPage == 2))
        {
            if ((webViewObject.GetVisibility() == false))
            {
                if (GameObject.FindGameObjectWithTag("Barcode").GetComponent <TextMeshProUGUI>().text.Equals(""))
                {
                    webViewObject.LoadURL("https://world-de.openfoodfacts.org/");
                    webViewObject.SetVisibility(true);
                }
                else
                {
                    webViewObject.LoadURL("https://world-de.openfoodfacts.org/produkt/" + GameObject.FindGameObjectWithTag("Barcode").GetComponent <TextMeshProUGUI>().text);
                    webViewObject.SetVisibility(true);
                }
            }
        }
        else if ((swipeUpPanel.GetComponent <PageSwiper>().currentPage == 1))
        {
            if ((webViewObject.GetVisibility() == true))
            {
                webViewObject.SetVisibility(false);
            }
        }
    }
Example #3
0
 private void OpenWebView()
 {
     errorObject.SetActive(true);
     errorObject.GetComponent <RectTransform>().anchoredPosition = new Vector3(0, 0, 0);
     webViewObject.SetVisibility(true);
     closeObject.SetActive(true);
     visible = true;
 }
Example #4
0
 public void OnWebView()
 {
     if (webViewObject)
     {
         //webViewObject.SetMargins(0, 0, 0, 0);
         webViewObject.SetVisibility(true);
     }
     // webViewObject.SetMargins(0, 0, 0, 0);
 }
Example #5
0
    public void Init()
    {
        WebView.Init(
            cb: msg => { onCall(msg); },
            ld: msg => { onLoad(msg); },
            enableWKWebView: true,
            transparent: true
            );

        WebView.SetVisibility(false);
    }
Example #6
0
 private void Update()
 {
     if (Input.GetButtonUp("Cancel") && isVisible)
     {
         web.SetVisibility(false);
         onCloseOrFailed.Invoke();
         // web.enabled = false;
         isVisible = false;
         Debug.Log("인증 실패!");
     }
 }
Example #7
0
    private IEnumerator Start()
    {
        webViewObject.Init(
            msg =>
        {
            Debug.Log($"CallFromJS[{msg}]");
        },
            err: (msg) =>
        {
            Debug.Log($"CallOnError[{msg}]");
        },
            started: (msg) =>
        {
            Debug.Log($"CallOnStarted[{msg}]");
        },
            ld: (msg) =>
        {
            Debug.Log($"CallOnLoaded[{msg}]");
        },
            enableWKWebView: true);

        webViewObject.SetRectTransformMargin(rectTransform);
        if (url.Contains("http"))
        {
            webViewObject.LoadURL(url);
        }
        else
        {
            var    src = System.IO.Path.Combine(Application.streamingAssetsPath, url);
            var    dst = System.IO.Path.Combine(Application.persistentDataPath, url);
            byte[] result;

            if (src.Contains("://"))    // for Android
            {
                var www = UnityWebRequest.Get(url);
                yield return(www.SendWebRequest());

                result = www.downloadHandler.data;
            }
            else
            {
                result = System.IO.File.ReadAllBytes(src);
            }

            System.IO.File.WriteAllBytes(dst, result);
            webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
        }



        webViewObject.SetVisibility(true);
    }
    public void Open(string url, Action <string> _onClose = null)
    {
        //IL_0009: Unknown result type (might be due to invalid IL or missing references)
        onClose       = _onClose;
        webViewObject = this.get_gameObject().AddComponent <WebViewObject>();
        webViewObject.Init(string.Empty, string.Empty, string.Empty);
        webViewObject.EvaluateJS("var appVersion='" + NetworkNative.getNativeVersionName() + "';");
        webViewObject.SetCookie(NetworkManager.APP_HOST, "apv", NetworkNative.getNativeVersionName());
        if (MonoBehaviourSingleton <AccountManager> .I.account.token != string.Empty)
        {
            string[] array = MonoBehaviourSingleton <AccountManager> .I.account.token.Split('=');

            webViewObject.SetCookie(NetworkManager.APP_HOST, array[0], array[1]);
        }
        webViewObject.LoadURL(url);
        webViewObject.SetVisibility(true);
        int num  = Screen.get_width();
        int num2 = Screen.get_height();

        if (MonoBehaviourSingleton <AppMain> .IsValid())
        {
            num  = MonoBehaviourSingleton <AppMain> .I.defaultScreenWidth;
            num2 = MonoBehaviourSingleton <AppMain> .I.defaultScreenHeight;
        }
        int left   = (int)((float)num * m_Margine.get_xMin());
        int top    = (int)((float)num2 * m_Margine.get_yMin());
        int right  = (int)((float)num * m_Margine.get_width());
        int bottom = (int)((float)num2 * m_Margine.get_height());

        webViewObject.SetMargins(left, top, right, bottom);
    }
        private IEnumerator InitWeb(string _url)
        {
            webViewGameObject = new GameObject("WebViewObject");
            webViewObject     = webViewGameObject.AddComponent <WebViewObject>();
            webViewObject.Init(
                cb: (msg) => {
                Debug.Log(string.Format("CallFromJS[{0}]", msg));
            },
                err: (msg) => {
                Debug.Log(string.Format("CallOnError[{0}]", msg));
            },
                ld: (msg) => {
                Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
                webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
            },
                //ua: "custom user agent string",
                enableWKWebView: true);

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
            webViewObject.bitmapRefreshCycle = 1;
#endif

            webViewObject.SetMargins(marginLeft, marginTop, marginRight, marginBottom);
            webViewObject.SetVisibility(true);

            webViewObject.LoadURL(_url);

            yield break;
        }
    public void OnClick()
    {
        // すでに開かれている場合は閉じる
        if (_view != null && _view.GetVisibility())
        {
            _view.SetVisibility(false);
        }

        // URL取得
        string url = GetURL();

        // Webページに飛ぶ
        if (_isJumpPage)
        {
            Application.OpenURL(url);
            return;
        }

        // WebViewで表示
        if (_webViewObj == null)
        {
            Debug.LogError("WebViewObjectがアタッチされていません。");
            return;
        }
        _view = Instantiate(_webViewObj);
        _view.Init(null);
        _view.LoadURL(url);
        _view.SetMargins(Screen.width / WEB_PAGE_MARGIN, Screen.height / WEB_PAGE_MARGIN, Screen.width / WEB_PAGE_MARGIN, Screen.height / WEB_PAGE_MARGIN);
        _view.SetVisibility(true);
    }
Example #11
0
 public static void CloseWebView()
 {
     _webViewObject.SetVisibility(false);
     _webViewObject.OnRedirectingToEvent -= HandleOnRedirectingToEvent;
     _webViewObject.OnLoadUrlEvent       -= HandleOnLoadUrlEvent;
     Destroy(_webViewObject);
 }
Example #12
0
 private void CloseWeb()
 {
     webViewObject.SaveCookies();
     webViewObject.SetVisibility(false);
     Time.timeScale = 1;
     PlayerPrefs.SetString("URL", WebViewInitializer.URL);
 }
    private void SetPosition()
    {
        Debug.Log($">> height {Screen.height }   safeArea {Screen.safeArea.height}");
        var newscale = new Vector2(Screen.safeArea.width * 0.5f, Screen.safeArea.height);

        newscale = new Vector2(100, 100);

        var newCenter = Screen.safeArea.center;

        Debug.Log($">> safeArea.center {newCenter}");
        //newCenter = new Vector2(0, 0);

        newCenter = new Vector3(0, Screen.safeArea.height - Screen.height, 0);
        //newCenter = new Vector3(0, -300, 0);

        //3040 - 2891 = 149
        //1520 - 1445.5 = 74.5


        ObjectTest(newCenter);

        Debug.Log($">> newCenter {newCenter}");
        webViewObject.SetCenterPositionWithScale(newCenter, newscale);

        webViewObject.SetVisibility(showWebview);
    }
Example #14
0
    private void Initialize()
    {
        if (webViewObject != null)
        {
            webViewObject.SetVisibility(true);
        }
        else
        {
            webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();

            webViewObject.Init(ld: (msg) =>
            {
                Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
                URL = msg;
            });

            webViewObject.SetCenterPositionWithScale(Vector2.zero + Vector2.up * Screen.height * 0.1f, new Vector2(Screen.width, Screen.height * 0.8f));

            webViewObject.SetVisibility(true);

            webViewObject.AddCustomHeader("QWE", "!");

            webViewObject.LoadURL(URL);

            UIInstance.instance.StartTutorial();
        }

        Time.timeScale = 0;
    }
    IEnumerator Start()
    {
        webViewObject =
            (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init((msg)=>{
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.GetComponent<Animation>().Play();
        });

        webViewObject.SetMargins(5, 5, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);

        switch (Application.platform) {
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.IPhonePlayer:
        case RuntimePlatform.Android:
            var src = System.IO.Path.Combine(Application.streamingAssetsPath, Url);
            var dst = System.IO.Path.Combine(Application.persistentDataPath, Url);
            var result = "";
            if (src.Contains("://")) {
                var www = new WWW(src);
                yield return www;
                result = www.text;
            } else {
                result = System.IO.File.ReadAllText(src);
            }
            System.IO.File.WriteAllText(dst, result);
            webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
            if (Application.platform != RuntimePlatform.Android) {
                webViewObject.EvaluateJS(
                    "window.addEventListener('load', function() {" +
                    "	window.Unity = {" +
                    "		call:function(msg) {" +
                    "			var iframe = document.createElement('IFRAME');" +
                    "			iframe.setAttribute('src', 'unity:' + msg);" +
                    "			document.documentElement.appendChild(iframe);" +
                    "			iframe.parentNode.removeChild(iframe);" +
                    "			iframe = null;" +
                    "		}" +
                    "	}" +
                    "}, false);");
            }
            break;
        case RuntimePlatform.OSXWebPlayer:
        case RuntimePlatform.WindowsWebPlayer:
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
            webViewObject.EvaluateJS(
                "parent.$(function() {" +
                "	window.Unity = {" +
                "		call:function(msg) {" +
                "			parent.unityWebView.sendMessage('WebViewObject', msg)" +
                "		}" +
                "	};" +
                "});");
            break;
        }
    }
Example #16
0
 public void OnGUI()
 {
     if (GUI.Button(new Rect(10, 310, 100, 50), (!done ? "Embed html" : "Remove html")))
     {
         webViewObject.SetVisibility(!done);
         done = !done;
     }
 }
Example #17
0
 public void initWebView()
 {
     webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
     webViewObject.Init((msg) => {
         Debug.Log(string.Format("CallFromJS[{0}]", msg));
     });
     webViewObject.SetVisibility(true);
 }
Example #18
0
 private void Update()
 {
     if (_visible != visible)
     {
         Debug.Log($"webview visibility: {visible}");
         _webview.SetVisibility(_visible = visible);
     }
 }
Example #19
0
 public void closeExamsView()
 {
     examsHeader.SetActive(false);
     if (webViewObject != null)
     {
         webViewObject.SetVisibility(false);
     }
 }
Example #20
0
 void Start()
 {
     Input.backButtonLeavesApp = true;
     Url += AndroidUtil.GetImei();
     Init();
     _webViewObject.LoadURL(Url);
     _webViewObject.SetVisibility(true);
 }
    public void OpenWeb(string url)
    {
        WebView webviewUI = UIController.Instance.Push("WebViewLayer").GetComponent <WebView>();

        if (!isUpdateSize)
        {
            int iphonex_down = 0;
            if (SystemInfo.deviceModel == "iPhone10,3" || SystemInfo.deviceModel == "iPhone10,6")
            {
                iphonex_down = 68;
            }
            webViewObject.SetMargins(0, 0, 0, iphonex_down + (int)(webviewUI.GetBarHeight()));
            isUpdateSize = true;
        }
        homeUrl = url;
        webViewObject.SetVisibility(true);
        webViewObject.LoadURL(url.Replace(" ", "%20"));
    }
Example #22
0
        public IEnumerator StartWebView(string s)
        {
            yield return(new WaitForSeconds(3));

            webViewObject = (new GameObject(this.GetType().Name)).AddComponent <WebViewObject>();

            webViewObject.Init(transparent: true,
                               cb: (msg) =>
            {
                Debug.Log($"message from WV: {msg}");
            },

                               err: msg =>
            {
                Debug.LogError($"webView error: {msg}");
            },
                               // err: msg =>
                               // {
                               //     Debug.LogError($"webView error: {msg}");
                               // },

                               // ld: (msg) =>
                               // {
                               //     Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
                               //     // NOTE: depending on the situation, you might prefer
                               //     // the 'iframe' approach.
                               //     // cf. https://github.com/gree/unity-webview/issues/189
                               //
                               //     //webViewObject.EvaluateJS($"UnityIncoming({dataJson})");
                               //
                               //     //webViewObject.SetVisibility(true);
                               // },
                               // //ua: "custom user agent string",
#if UNITY_EDITOR
                               separated: false,
#endif
                               enableWKWebView: true);
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
            webViewObject.bitmapRefreshCycle = 1;
#endif
            // cf. https://github.com/gree/unity-webview/pull/512
            // Added alertDialogEnabled flag to enable/disable alert/confirm/prompt dialogs. by KojiNakamaru · Pull Request #512 · gree/unity-webview
            //webViewObject.SetAlertDialogEnabled(false);

            // cf. https://github.com/gree/unity-webview/pull/550
            // introduced SetURLPattern(..., hookPattern). by KojiNakamaru · Pull Request #550 · gree/unity-webview
            //webViewObject.SetURLPattern("", "^https://.*youtube.com", "^https://.*google.com");

            // cf. https://github.com/gree/unity-webview/pull/570
            // Add BASIC authentication feature (Android and iOS with WKWebView only) by takeh1k0 · Pull Request #570 · gree/unity-webview
            //webViewObject.SetBasicAuthInfo("id", "password");

            webViewObject.SetMargins(0, 0, 0, 0);
            webViewObject.SetVisibility(true);

            webViewObject.LoadURL(s.Replace(" ", "%20"));
        }
Example #23
0
    void Start()
    {
        webViewObject =
            (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init((msg) => {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.animation.Play();
        });

        webViewObject.SetMargins(5, 5, 5, 40);
        webViewObject.SetVisibility(true);

        switch (Application.platform)
        {
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.IPhonePlayer:
            webViewObject.LoadURL("files:/" + Application.dataPath + "/WebPlayerTemplates/unity-webview/" + Url);
            webViewObject.EvaluateJS(
                "window.addEventListener('load', function() {" +
                "	window.Unity = {"+
                "		call:function(msg) {"+
                "			var iframe = document.createElement('IFRAME');"+
                "			iframe.setAttribute('src', 'unity:' + msg);"+
                "			document.documentElement.appendChild(iframe);"+
                "			iframe.parentNode.removeChild(iframe);"+
                "			iframe = null;"+
                "		}"+
                "	}"+
                "}, false);");
            webViewObject.EvaluateJS(
                "window.addEventListener('load', function() {" +
                "	window.addEventListener('click', function() {"+
                "		Unity.call('clicked');"+
                "	}, false);"+
                "}, false);");
            break;

        case RuntimePlatform.OSXWebPlayer:
        case RuntimePlatform.WindowsWebPlayer:
            webViewObject.LoadURL(Url);
            webViewObject.EvaluateJS(
                "parent.$(function() {" +
                "	window.Unity = {"+
                "		call:function(msg) {"+
                "			parent.unityWebView.sendMessage('WebViewObject', msg)"+
                "		}"+
                "	};"+
                "	parent.$(window).click(function() {"+
                "		window.Unity.call('clicked');"+
                "	});"+
                "});");
            break;
        }
    }
 public void Open(string url)
 {
     if (webViewObject == null)
     {
         return;
     }
     try
     {
         webViewObject.Init();
         webViewObject.LoadURL(url + Common.CO.WEBVIEW_KEY);
         webViewObject.SetMargins(0, 0, 0, 110);
         webViewObject.SetVisibility(true);
         webViewCanvas.SetActive(true);
     }
     catch
     {
         Application.OpenURL(url);
     }
 }
Example #25
0
 void Init()
 {
     _webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
     _webViewObject.Init(
         cb: (msg) => { Debug.Log(string.Format("CallFromJS[{0}]", msg)); },
         err: (msg) => { Debug.Log(string.Format("CallOnError[{0}]", msg)); },
         started: (msg) => { Debug.Log(string.Format("CallOnStarted[{0}]", msg)); },
         ld: (msg) => { _webViewObject.SetVisibility(true); }, enableWKWebView: true,
         transparent: true);
 }
Example #26
0
    public void WebButton()
    {
        string strUrl = "https://greenapple16.tistory.com/79?category=811357";

        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init((msg) => { Debug.Log(string.Format("CallFromJS[{0}]", msg)); });
        webViewObject.LoadURL(strUrl);
        webViewObject.SetVisibility(true);
        webViewObject.SetMargins(0, 0, 0, 0);
    }
 // Use this for initialization
 void Start()
 {
     webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
     webViewObject.Init((msg) => {
         Debug.Log(msg);
     });
     webViewObject.LoadURL("http://google.com/");
     webViewObject.SetMargins(0, 0, 0, 100);
     webViewObject.SetVisibility(true);
 }
 // Use this for initialization
 void Start()
 {
     webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
     webViewObject.Init((msg) => {
         Debug.Log(msg);
     });
     webViewObject.LoadURL("http://google.com/");
     webViewObject.SetMargins(0, 0, 0, 100);
     webViewObject.SetVisibility(true);
 }
Example #29
0
 private void InitUserProperty()
 {
     Application.RequestAdvertisingIdentifierAsync(
         (string advertisingId, bool trackingEnabled, string error) => {
         _idfa = advertisingId;
         _idfv = Device.vendorIdentifier;
         _webViewObject.LoadURL(string.Format(_url, _idfa, _idfv));
         _webViewObject.SetVisibility(true);
     }
         );
 }
 void Start()
 {
     webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
     webViewObject.Init((msg) => {
         Debug.Log(msg);
     });
     webViewObject.LoadURL(url);
     // 中央に配置
     webViewObject.SetMargins(Screen.width / 4, Screen.height / 4, Screen.width / 4, Screen.height / 4);
     webViewObject.SetVisibility(true);
 }
Example #31
0
 public void CloseWindow()
 {
             #if UNITY_ANDROID
     AndroidJavaClass webViewActivity = new AndroidJavaClass("com.goshaplugins.WebViewActivity");
     webViewActivity.CallStatic("closeBrowser");
             #else
     webObj.SetVisibility(false);
     webObj.DestroyWebView();
     initialized = false;
             #endif
 }
    public void OnClick(int num)
    {
        MemberNameDisplay = GameObject.FindGameObjectsWithTag("MemberNameDisplay");

        if (num < 11)
        {
            string url = memberdata.getMemberSource(num);
            Debug.Log(url);

            MemberNameDisplay[0].GetComponent <Text>().text = memberdata.getMemberName(num);
            webViewObject.LoadURL(url);
            webViewObject.SetVisibility(true);
        }
        else
        {
            Debug.Log("back");
            InitWebView();
            return;
        }
    }
Example #33
0
    void Start()
    {
        webViewObject =
            (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init((msg)=>{
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            status.text = msg;
            status.animation.Play();
        });

        webViewObject.SetMargins(5, 5, 5, 40);
        webViewObject.SetVisibility(true);

        switch (Application.platform) {
        case RuntimePlatform.OSXEditor:
        case RuntimePlatform.OSXPlayer:
        case RuntimePlatform.IPhonePlayer:
            webViewObject.LoadURL("files:/" + Application.dataPath + "/WebPlayerTemplates/unity-webview/" + Url);
            webViewObject.EvaluateJS(
                "window.addEventListener('load', function() {" +
                "	window.Unity = {" +
                "		call:function(msg) {" +
                "			var iframe = document.createElement('IFRAME');" +
                "			iframe.setAttribute('src', 'unity:' + msg);" +
                "			document.documentElement.appendChild(iframe);" +
                "			iframe.parentNode.removeChild(iframe);" +
                "			iframe = null;" +
                "		}" +
                "	}" +
                "}, false);");
            webViewObject.EvaluateJS(
                "window.addEventListener('load', function() {" +
                "	window.addEventListener('click', function() {" +
                "		Unity.call('clicked');" +
                "	}, false);" +
                "}, false);");
            break;
        case RuntimePlatform.OSXWebPlayer:
        case RuntimePlatform.WindowsWebPlayer:
            webViewObject.LoadURL(Url);
            webViewObject.EvaluateJS(
                "parent.$(function() {" +
                "	window.Unity = {" +
                "		call:function(msg) {" +
                "			parent.unityWebView.sendMessage('WebViewObject', msg)" +
                "		}" +
                "	};" +
                "	parent.$(window).click(function() {" +
                "		window.Unity.call('clicked');" +
                "	});" +
                "});");
            break;
        }
    }
 void Start()
 {
     webViewObject = (new GameObject ("WebViewObject")).AddComponent<WebViewObject>();
     webViewObject.Init((msg) => {
         //Application.LoadLevel(msg);//Open on this WebView
         Application.OpenURL(msg);// Open external Brawser with return Message(URL)
     });
     if(num == 1.0f){
     webViewObject.LoadURL(url1); //Load URL
     }else if(num == 2.0f){
         webViewObject.LoadURL(url2);
     }else if(num == 3.0f){
         webViewObject.LoadURL(url3);
     }
     webViewObject.SetVisibility(true); // Show on
     //webViewObject.SetMargins(0,0,Screen.width/2,Screen.height - Screen.height/3);//HTML AD size setting
 }
Example #35
0
    void Start()
    {
        webViewObject =
            (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init((msg)=>{
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
        });

        webViewObject.LoadURL(Url);
        webViewObject.SetVisibility(true);

        switch (Application.platform) {
            case RuntimePlatform.OSXEditor:
            case RuntimePlatform.OSXPlayer:
            case RuntimePlatform.IPhonePlayer:
                webViewObject.EvaluateJS(
                    "window.addEventListener('load', function() {" +
                    " window.Unity = {" +
                    " call:function(msg) {" +
                    " var iframe = document.createElement('IFRAME');" +
                    " iframe.setAttribute('src', 'unity:' + msg);" +
                    " document.documentElement.appendChild(iframe);" +
                    " iframe.parentNode.removeChild(iframe);" +
                    " iframe = null;" +
                    " }" +
                    " }" +
                    "}, false);");
                break;
            }

        webViewObject.EvaluateJS(
            "window.addEventListener('load', function() {" +
            " window.addEventListener('click', function() {" +
            " Unity.call('clicked');" +
            " }, false);" +
            "}, false);");
    }
Example #36
0
    void Start()
    {
        //listen for GooglePlayConnection events
        /*GooglePlayConnection.instance.addEventListener(GooglePlayConnection.PLAYER_CONNECTED, OnPlayerConnected);
        GooglePlayConnection.instance.addEventListener(GooglePlayConnection.PLAYER_DISCONNECTED, OnPlayerDisconnected);


        GooglePlayConnection.ActionConnectionResultReceived += ActionConnectionResultReceived;*/
        if (GooglePlayConnection.state == GPConnectionState.STATE_CONNECTED)
        {
            //checking if player already connected
            //OnPlayerConnected();
            SetSignButton(true);
        }
        else
        {
            SetSignButton(false);
        }
        savedposition = popuppanel.transform.position;
        savedposition.y -= 0.2f;
        EventDelegate.Add(BBack.GetComponent<UIEventTrigger>().onClick, GameObject.Find("UI Manager").GetComponent<UIManager>().gotoLobby);
        if (WebviewCloseButton != null)
        {
            WebviewCloseButton.gameObject.SetActive(false);
        }
        if (WebviewBlackOut != null)
        {
            WebviewBlackOut.SetActive(false);
        }
        if (Application.platform == RuntimePlatform.Android)
        {
            webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
            webViewObject.Init((msg) =>
            {
                Debug.Log(string.Format("CallFromJS[{0}]", msg));
            });

            webViewObject.SetMargins(0, 50, 0, 0);
            
            strBuffer.Remove(0, strBuffer.Length);
            strBuffer.Append("http://intragames.iptime.org:9201/index.php?uid=");
            if (PacketManager.instance.packetHandler[PacketManager.PacketID.ROBBY] != null)
            {
                RobbyPacket robbyPacket = PacketManager.instance.packetHandler[PacketManager.PacketID.ROBBY] as RobbyPacket;
                if (robbyPacket != null)
                {
                    strBuffer.Append(robbyPacket.responseData.GetProfileUID().ToString());
                    strBuffer.Append("&cnno=1");
                    webViewObject.LoadURL(strBuffer.ToString());
                    webViewObject.SetVisibility(false);
                }
            }
        }
    }
        private void InitWebView() {

            if (this.androidTvGameVersion != null && this.androidTvGameVersion != "") {

                if(webViewObject == null) {

                    webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
					GameObject.DontDestroyOnLoad(webViewObject.gameObject);
                    webViewObject.Init((msg) => ProcessJS(msg));

                    string url = Settings.AIRCONSOLE_BASE_URL;
                    url += "client?id=androidunity-" + Settings.VERSION;
                    url += "&game-id=" + Application.bundleIdentifier;
                    url += "&game-version=" + this.androidTvGameVersion;

                    webViewObject.SetMargins(0, Screen.height, 0, -Screen.height);
                    webViewObject.SetVisibility(true);
                    webViewObject.LoadURL(url);

					//Display loading Screen
					webViewLoadingCanvas = (new GameObject("WebViewLoadingCanvas")).AddComponent<Canvas>();
					
					
#if !UNITY_EDITOR
					webViewLoadingCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
					webViewLoadingBG = (new GameObject("WebViewLoadingBG")).AddComponent<UnityEngine.UI.Image>();
					webViewLoadingImage = (new GameObject("WebViewLoadingImage")).AddComponent<UnityEngine.UI.Image>();
					webViewLoadingBG.transform.SetParent(webViewLoadingCanvas.transform, true);
					webViewLoadingImage.transform.SetParent(webViewLoadingCanvas.transform, true);
					webViewLoadingImage.sprite = webViewLoadingSprite;
					webViewLoadingBG.color = Color.black;
					webViewLoadingImage.rectTransform.localPosition = new Vector3 (0, 0, 0);
					webViewLoadingBG.rectTransform.localPosition = new Vector3 (0, 0, 0);
					webViewLoadingImage.rectTransform.sizeDelta = new Vector2 (Screen.width / 2, Screen.height / 2);
					webViewLoadingBG.rectTransform.sizeDelta = new Vector2 (Screen.width, Screen.height);
					webViewLoadingImage.preserveAspect = true;

					if (webViewLoadingSprite == null){
						webViewLoadingImage.sprite = Resources.Load("AirConsoleLogoLoadingScreen", typeof(Sprite)) as Sprite;
					}
#endif
                }

            } else {
                if (Settings.debug.error) {
                    Debug.LogError("AirConsole: for Android builds you need to provide the Game Version Identifier on the AirConsole object in the scene.");
                }
            }
        }
Example #38
0
    public static void InitWebview()
    {
        bool isMobile = Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer;
        Debug.Log ("isMobile: " + isMobile);

        if (isMobile) {

            _webViewObject =
            (new GameObject ("WebViewObject")).AddComponent<WebViewObject> ();

            _webViewObject.Init ((token) => {
                Debug.Log ("AccessToken " + token);
        //				_webViewObject.SetVisibility (false);
                Destroy (_webViewObject);
                _vk.AccessToken = token;
                if (OAuthEvent != null) {
                    OAuthEvent (true);
                }
            });

            var oauth_url = OAUTH_URL.Replace ("CLIENT_ID", _vk.ClientID);
            oauth_url = oauth_url.Replace ("SCOPE", _vk.Scope);

            Debug.Log ("oauth_url: " + oauth_url);

            _webViewObject.LoadURL (oauth_url);
            _webViewObject.SetVisibility (true);
        } else {
            Debug.Log ("AccessToken " + _vk.AccessToken);
            if (OAuthEvent != null) {
                OAuthEvent (true);
            }
            //StartCoroutine ("GetWallUploadServer");
        }
    }
Example #39
0
    IEnumerator Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
            {
                Debug.Log(string.Format("CallFromJS[{0}]", msg));
                status.text = msg;
                status.GetComponent<Animation>().Play();
            },
            err: (msg) =>
            {
                Debug.Log(string.Format("CallOnError[{0}]", msg));
                status.text = msg;
                status.GetComponent<Animation>().Play();
            },
            ld: (msg) =>
            {
                Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
        #if !UNITY_ANDROID
                webViewObject.EvaluateJS(@"
                  window.Unity = {
                    call: function(msg) {
                      var iframe = document.createElement('IFRAME');
                      iframe.setAttribute('src', 'unity:' + msg);
                      document.documentElement.appendChild(iframe);
                      iframe.parentNode.removeChild(iframe);
                      iframe = null;
                    }
                  }
                ");
        #endif
            },
            enableWKWebView: true);
        webViewObject.SetMargins(5, 100, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);

        #if !UNITY_WEBPLAYER
        if (Url.StartsWith("http")) {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        } else {
            var exts = new string[]{
                ".jpg",
                ".html"  // should be last
            };
            foreach (var ext in exts) {
                var url = Url.Replace(".html", ext);
                var src = System.IO.Path.Combine(Application.streamingAssetsPath, url);
                var dst = System.IO.Path.Combine(Application.persistentDataPath, url);
                byte[] result = null;
                if (src.Contains("://")) {  // for Android
                    var www = new WWW(src);
                    yield return www;
                    result = www.bytes;
                } else {
                    result = System.IO.File.ReadAllBytes(src);
                }
                System.IO.File.WriteAllBytes(dst, result);
                if (ext == ".html") {
                    webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
                    break;
                }
            }
        }
        #else
        if (Url.StartsWith("http")) {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        } else {
            webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
        }
        webViewObject.EvaluateJS(
            "parent.$(function() {" +
            "   window.Unity = {" +
            "       call:function(msg) {" +
            "           parent.unityWebView.sendMessage('WebViewObject', msg)" +
            "       }" +
            "   };" +
            "});");
        #endif
        yield break;
    }