// Update is called once per frame
    void RunJS()
    {
        Debug.Log("Running JS");

        string removeHeader = "var list = document.getElementsByClassName(\"uk-navbar-container\");for (const elem of list){elem.style.display = \"none\";} ";

        string removeCookiesAcceptance = "var list = document.getElementsByClassName(\"cpnb-warningBox-show-fade-in cpnb-outer cpnb-div-position-bottom\");for (const elem of list){  elem.style.display = \"none\";}";

        string removeFooter = "var list = document.getElementsByClassName(\"uk-section-secondary\");for (const elem of list){  elem.style.display = \"none\";}";

        myUniwebview.EvaluateJavaScript(removeHeader, (payload) => {
            if (payload.resultCode.Equals("0"))
            {
                print(payload.data);
            }
        });

        myUniwebview.EvaluateJavaScript(removeCookiesAcceptance, (payload) => {
            if (payload.resultCode.Equals("0"))
            {
                print(payload.data);
            }
        });

        myUniwebview.EvaluateJavaScript(removeFooter, (payload) => {
            if (payload.resultCode.Equals("0"))
            {
                print(payload.data);
            }
        });
    }
Exemple #2
0
    /// <summary>
    /// 给地图生成点
    /// </summary>
    public void SpawnPointToMap()
    {
        LinkList pointLinkList = LoadTrackData.Instance.pointLinkList;
        ListNode node          = new ListNode();
        int      length        = pointLinkList.Length();

        for (int i = 1; i <= length; i++)
        {
            node = pointLinkList.GetNode(i);
            string longitude = node.longitude;
            string latitude  = node.latitude;
            string path      = node.path;
#if   UNITY_ANDROID
            path = "/sdcard/DCIM/Camera/" + path;
#elif UNITY_IOS || UNITY_IPHONE
            path = "/" + Application.persistentDataPath + "/" + path;
#endif
            string count    = node.count;
            string id       = node.id;
            string jsString = @"PointOverlap(" + longitude + "," + latitude + "," + "\"" + path + "\"" + "," + count + "," + id + ");";
            Debug.Log(jsString);

            webView.EvaluateJavaScript(jsString, CompletionHandler);
        }
    }
Exemple #3
0
        public IEnumerator waitThenStartAdVideoWithJavascriptCall()
        {
            //if (AdGem.verboseLogging) { Debug.Log("Adgem - waitThenStartAdVideoWithJavascriptCall()"); }

            yield return(new WaitForSeconds(0.05f));

            waitingForPlaySuccessConfirmation = true;

            if (AdGem.verboseLogging)
            {
                Debug.Log("Adgem - JAVASCRIPT CALL: " + "init(" + initParams + "," + AdGemPlugin.appSessionId + ");");
            }

            //webView.EvaluateJavaScript("init_debug();", (payload) =>
            webView.EvaluateJavaScript("init(" + initParams + ",'" + AdGemPlugin.appSessionId + "');", (payload) =>
            {
                if (payload.resultCode.Equals("0"))
                {
                    if (AdGem.verboseLogging)
                    {
                        Debug.Log("Starting webview ad video!");
                    }
                }
                else
                {
                    Debug.Log("Something went wrong starting the ad video: " + payload.data);
                }
            });

            //Make sure the play success message is received
            float waitTime = 0f;

            while (waitingForPlaySuccessConfirmation && waitTime < 5.5f)
            {
                Debug.Log("Adgem - waiting for confirmation...");

                if (waitTime > 5f)
                {
                    waitingForPlaySuccessConfirmation = false;
                    if (webView != null)
                    {
                        Debug.Log("Adgem - closing webview because did not get confirmation **********------------*********");
                        webView.Stop();
                        webView.CleanCache();
                        webView.Hide(false);
                        AdGem.videoIsPlaying = false;
                        if (AdGem.videoFailedToLoad != null)
                        {
                            AdGem.videoFailedToLoad();
                        }
                    }
                }

                yield return(new WaitForSeconds(0.1f));

                waitTime += 0.1f;
            }
        }
Exemple #4
0
    // Update is called once per frame
    void RunJS()
    {
        Debug.Log("Running JS");

        string custom_javascript = javascript_code;

        myUniwebview.EvaluateJavaScript(custom_javascript, (payload) => {
            if (payload.resultCode.Equals("0"))
            {
                print(payload.data);
            }
        });
    }
Exemple #5
0
    private void InitUniWebView()
    {
        if (uniWebView)
        {
            uniWebView.ReferenceRectTransform = webExporlerTrans;
            uniWebView.Load("http://172.29.106.254:3000/");
            uniWebView.Show();
            uniWebView.OnPageFinished += (view, statusCode, url) =>
            {
                // Page load finished
            };
            uniWebView.OnShouldClose += (view) =>
            {
                uniWebView = null;
                return(true);
            };
            uniWebView.OnPageFinished += (view, statusCode, url) =>
            {
                uniWebView.EvaluateJavaScript("testJs();", (payload) =>
                {
                    if (payload.resultCode.Equals("0"))
                    {
                        Debug.Log("Game Started!");
                    }
                    else
                    {
                        Debug.Log("Something goes wrong: " + payload.data);
                    }
                });
            };
            uniWebView.OnMessageReceived += (view, message) =>
            {
                if (message.Path.Equals("game-over"))
                {
                    var score = message.Args["score"];
                    Debug.Log("Your final score is: " + score);

                    // Restart the game after 3 second
                    Invoke("UniWebViewRestart", 3.0f);
                }
                if (message.Path.Equals("close"))
                {
                    Destroy(uniWebView);
                    uniWebView = null;
                }
            };
        }
    }
        private static void CallJsFunction(string InJsFunctionName)
        {
            string jsFunction = $"{InJsFunctionName}()";

            Log.Info($"[WebViewBridge] Call Js Function : {jsFunction}", ColorName.Olive);

            _webView.EvaluateJavaScript(jsFunction, InPayload =>
            {
                if (InPayload.resultCode == "0")
                {
                    Log.Info(
                        $"[WebViewBridge] {jsFunction} Callback : data = {(string.IsNullOrEmpty(InPayload.data) ? "null" : InPayload.data)}",
                        ColorName.Olive);
                }
                else
                {
                    Log.Error(
                        $"[WebViewBridge] {jsFunction} Callback error : resultCode = {InPayload.resultCode}, data = {(string.IsNullOrEmpty(InPayload.data) ? "null" : InPayload.data)}");
                }
            });
        }
Exemple #7
0
    /// <summary>
    /// 页面加载完毕回调事件
    /// </summary>
    private void WebView_OnPageFinished(UniWebView webView, int statusCode, string url)
    {
        Debug.Log("加载完毕" + statusCode + "***");
        try
        {
            TrackUIManager.Instance.LoadComplete();

            String   location = UnityHelper.GetBDGPSLocation();
            JsonData zb       = JsonMapper.ToObject(location);
            string   x        = zb["longitude"].ToString();
            string   y        = zb["latitude"].ToString();

            string jsString = @"PanTo(" + x + "," + y + ");";
            Debug.Log(jsString);

            webView.EvaluateJavaScript(jsString, CompletionHandler);
        }
        catch (System.Exception ex)
        {
        }


        SpawnPointToMap();
    }