예제 #1
0
 public void FixedUpdate()
 {
     if (mapLoaded)
     {
         if (_untilNextTimerUpdate <= 0)
         {
             _webView.EvaluatingJavaScript(JS_UPDATE_TIMER_NAME +
                                           '(' + SpatialClient2.single.getTimer().ToString() + ')');
             _untilNextTimerUpdate = UPDATE_TIMER_INTERVAL;
         }
         else
         {
             _untilNextTimerUpdate--;
         }
     }
 }
예제 #2
0
    /// <summary>
    /// Unity Call WebView
    /// </summary>
    private void UnityCallWebView()
    {
        //调用webView中的名为pupop的函数
        string javaScript = "pupop();";

        m_UniWebView.EvaluatingJavaScript(javaScript);
    }
예제 #3
0
        public void CloseMolpay()
        {
            mpMainUI.EvaluatingJavaScript("closemolpay()");

            if (isClosingReceipt)
            {
                isClosingReceipt = false;
                Finish();
            }
        }
    public void RunScript(InputField input)
    {
        if (_webView == null)
        {
            result.text = "Please open the web view first.";
            return;
        }

        // Execute the JavaScript. The result will be returned in OnEvalJavaScriptFinished event.
        _webView.EvaluatingJavaScript(input.text);
    }
예제 #5
0
 private void MPMainUIOnLoadComplete(UniWebView webView, bool success, string errorMessage)
 {
     if (success)
     {
         paymentDetails.Add(module_id, "molpay-mobile-xdk-unity3d");
         paymentDetails.Add(wrapper_version, "1");
         paymentDetails.Add(webview_url_prefix, uniwebview);
         webView.EvaluatingJavaScript("updateSdkData(" + Json.Serialize(paymentDetails) + ")");
         webView.OnLoadComplete -= MPMainUIOnLoadComplete;
     }
 }
예제 #6
0
 //9. By using EvaluatingJavaScript method, you can talk to webview from Unity.
 //It can evel a javascript or run a js method in the web page.
 //(In the demo, it will be called when the cube hits the sphere)
 public void ShowAlertInWebview(float time, bool first)
 {
     _moveVector = Vector3.zero;
     if (first)
     {
         //Eval the js and wait for the OnEvalJavaScriptFinished event to be raised.
         //The sample(float time) is written in the js in webpage, in which we pop
         //up an alert and return a demo string.
         //When the js excute finished, OnEvalJavaScriptFinished will be raised.
         _webView.EvaluatingJavaScript("sample(" + time + ")");
     }
 }
예제 #7
0
        private void NativeWebRequestUrlUpdates(UniWebView webView, string url)
        {
            try
            {
                Dictionary <string, object> data = new Dictionary <string, object>();
                data.Add("requestPath", url);

                webView.EvaluatingJavaScript("nativeWebRequestUrlUpdates(" + Json.Serialize(data) + ")");
            }
            catch (Exception)
            {
            }
        }
예제 #8
0
 private void MPMOLPayUIOnLoadComplete(UniWebView webView, bool success, string errorMessage)
 {
     if (hijackWindowOpen)
     {
         webView.EvaluatingJavaScript("window.open = function (open) {" +
                                      "return function(url, name, features) {" +
                                      "window.location = url;" +
                                      "return window;" +
                                      "};" +
                                      "} (window.open); ");
     }
     NativeWebRequestUrlUpdates(mpMainUI, finishLoadUrl);
 }
예제 #9
0
 static void runJS(string evalScript, UniWebView webView)
 {
     webView.AddJavaScript(evalScript);
     webView.EvaluatingJavaScript(evalScript);
 }
예제 #10
0
 private void OnReceivedMessage(UniWebView webView, UniWebViewMessage message)
 {
     UnityEngine.Debug.Log("OnReceivedMessage");
     UnityEngine.Debug.Log(message.rawMessage);
     if (string.Equals(message.path, "webview"))
     {
         Vector3 zero = Vector3.zero;
         if (message.args.ContainsKey("funcname"))
         {
             if (string.Equals(message.args["funcname"], "dnqueryuserinfo"))
             {
                 if (message.args.ContainsKey("callback"))
                 {
                     UnityEngine.Debug.Log("Will callback");
                     string arg = message.args["callback"];
                     Dictionary <string, object> dictionary = new Dictionary <string, object>();
                     dictionary["appid"]        = this.mAppId;
                     dictionary["openid"]       = this.mOpenid;
                     dictionary["access_token"] = this.mToken;
                     dictionary["partition"]    = this.mServerid;
                     dictionary["roleid"]       = this.mRoleid;
                     dictionary["entertime"]    = this.mOpenTime;
                     dictionary["nickname"]     = this.mNickName;
                     string arg2 = Json.Serialize(dictionary);
                     string text = string.Format("{0}({1})", arg, arg2);
                     UnityEngine.Debug.Log(text);
                     webView.EvaluatingJavaScript(text);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnclosewebview"))
             {
                 this.CloseWebView(webView);
             }
             else if (string.Equals(message.args["funcname"], "dniswifi"))
             {
                 if (message.args.ContainsKey("callback"))
                 {
                     UnityEngine.Debug.Log("Will dniswifi callback");
                     string arg3  = message.args["callback"];
                     bool   flag  = Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork;
                     int    num   = (!flag) ? 0 : 1;
                     string text2 = string.Format("{0}({1})", arg3, num);
                     UnityEngine.Debug.Log(text2);
                     webView.EvaluatingJavaScript(text2);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnisbgopen"))
             {
                 if (message.args.ContainsKey("callback"))
                 {
                     UnityEngine.Debug.Log("Will dnisbgopen callback");
                     string arg4  = message.args["callback"];
                     int    num2  = (!this._is_bgopen) ? 0 : 1;
                     string text3 = string.Format("{0}({1})", arg4, num2);
                     UnityEngine.Debug.Log(text3);
                     webView.EvaluatingJavaScript(text3);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnopenbg"))
             {
                 this._is_bgopen = true;
                 UniWeb.m_uiUtility.OnSetBg(true);
             }
             else if (string.Equals(message.args["funcname"], "dnclosebg"))
             {
                 this._is_bgopen = false;
                 UniWeb.m_uiUtility.OnSetBg(false);
             }
             else if (string.Equals(message.args["funcname"], "dnchangemenu"))
             {
                 if (message.args.ContainsKey("menutype"))
                 {
                     int menutype = int.Parse(message.args["menutype"]);
                     UniWeb.m_uiUtility.OnSetWebViewMenu(menutype);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnbackgame"))
             {
                 if (message.args.ContainsKey("backtype"))
                 {
                     int menutype2 = int.Parse(message.args["backtype"]);
                     UniWeb.m_uiUtility.OnSetWebViewMenu(menutype2);
                 }
                 if (message.args.ContainsKey("callback"))
                 {
                     UnityEngine.Debug.Log("Will dnbackgame callback");
                     string arg5  = message.args["callback"];
                     string text4 = string.Format("{0}()", arg5);
                     UnityEngine.Debug.Log(text4);
                     webView.EvaluatingJavaScript(text4);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnrefreshredpoint"))
             {
                 if (message.args.ContainsKey("args"))
                 {
                     string text5 = WWW.UnEscapeURL(message.args["args"]);
                     UnityEngine.Debug.Log("dnrefreshredpoint" + text5);
                     UniWeb.m_uiUtility.OnWebViewRefershRefPoint(text5);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnsetheaderinfo"))
             {
                 if (message.args.ContainsKey("args"))
                 {
                     string text6 = WWW.UnEscapeURL(message.args["args"]);
                     UnityEngine.Debug.Log("dnsetheaderinfo" + text6);
                     UniWeb.m_uiUtility.OnWebViewSetheaderInfo(text6);
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnshownav"))
             {
                 if (message.args.ContainsKey("type"))
                 {
                     int num3 = int.Parse(message.args["type"]);
                     if (num3 == 1)
                     {
                         this._gap = this.GetGap();
                     }
                     else
                     {
                         this._gap = 0;
                     }
                     this._webView.ForceResize();
                 }
             }
             else if (string.Equals(message.args["funcname"], "dncloseloading"))
             {
                 if (message.args.ContainsKey("show"))
                 {
                     int num4 = int.Parse(message.args["show"]);
                     UnityEngine.Debug.Log("dncloseloading: " + message.args["show"]);
                     UniWeb.m_uiUtility.OnWebViewCloseLoading(num4);
                     if (num4 == 1)
                     {
                         this._webView.Hide();
                     }
                     else
                     {
                         this._webView.Show();
                     }
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnshowreconnect"))
             {
                 if (message.args.ContainsKey("show"))
                 {
                     int num5 = int.Parse(message.args["show"]);
                     UnityEngine.Debug.Log("dnshowreconnect: " + message.args["show"]);
                     UniWeb.m_uiUtility.OnWebViewShowReconnect(num5);
                     if (num5 == 1)
                     {
                         this._webView.Hide();
                     }
                     else
                     {
                         this._webView.Show();
                     }
                 }
             }
             else if (string.Equals(message.args["funcname"], "dnsetlivetab"))
             {
                 UniWeb.m_uiUtility.OnWebViewLiveTab();
             }
             else if (string.Equals(message.args["funcname"], "dnbackhistory"))
             {
                 this._webView.GoBack();
             }
             else if (string.Equals(message.args["funcname"], "dnsetshareinfo"))
             {
                 string json = WWW.UnEscapeURL(message.args["args"]);
                 Dictionary <string, object> dictionary2 = Json.Deserialize(json) as Dictionary <string, object>;
                 XPlatform platf = base.gameObject.GetComponent <XPlatform>();
                 object    title;
                 dictionary2.TryGetValue("title", out title);
                 object obj;
                 dictionary2.TryGetValue("imgurl", out obj);
                 object desc;
                 dictionary2.TryGetValue("desc", out desc);
                 object url;
                 dictionary2.TryGetValue("url", out url);
                 object type;
                 dictionary2.TryGetValue("type", out type);
                 if (type.Equals("qq") || type.Equals("qzone"))
                 {
                     Dictionary <string, string> dictionary3 = new Dictionary <string, string>();
                     dictionary3["scene"] = ((!type.Equals("qq")) ? "QZone" : "Session");
                     if (url != null)
                     {
                         dictionary3["targetUrl"] = "https:" + url.ToString();
                     }
                     if (obj != null)
                     {
                         dictionary3["imageUrl"] = obj.ToString();
                     }
                     if (title != null)
                     {
                         dictionary3["title"] = title.ToString();
                     }
                     if (desc != null)
                     {
                         dictionary3["description"] = desc.ToString();
                     }
                     dictionary3["summary"] = string.Empty;
                     string json2 = Json.Serialize(dictionary3);
                     platf.SendGameExData("share_send_to_struct_qq", json2);
                 }
                 else if (type.Equals("weixin") || type.Equals("timeline"))
                 {
                     if (!base.gameObject.activeSelf)
                     {
                         return;
                     }
                     base.StartCoroutine(this.DownloadPic(obj.ToString(), delegate(string filepath)
                     {
                         if (!string.IsNullOrEmpty(filepath))
                         {
                             Dictionary <string, string> dictionary4 = new Dictionary <string, string>();
                             dictionary4["scene"] = ((!type.Equals("weixin")) ? "Timeline" : "Session");
                             if (title != null)
                             {
                                 dictionary4["title"] = title.ToString();
                             }
                             if (desc != null)
                             {
                                 dictionary4["desc"] = desc.ToString();
                             }
                             if (url != null)
                             {
                                 dictionary4["url"] = url.ToString();
                             }
                             dictionary4["mediaTagName"] = "MSG_INVITE";
                             dictionary4["filePath"]     = filepath;
                             dictionary4["messageExt"]   = "ShareUrlWithWeixin";
                             string json3 = Json.Serialize(dictionary4);
                             platf.SendGameExData("share_send_to_with_url_wx", json3);
                         }
                     }));
                 }
                 else
                 {
                     UnityEngine.Debug.LogError("err type: " + type);
                 }
             }
         }
     }
 }
예제 #11
0
    public void EvaluatingJavaScript(string javaScript)
    {
#if UNITY_IOS || UNITY_ANDROID || UNITY_EDITOR
        uniWebView.EvaluatingJavaScript(javaScript);
#endif
    }
예제 #12
0
 public void RunJavaScript(string fun, string method)
 {
     webView.AddJavaScript(fun);           //"function concatme(){publicWebFunction(); }"
     webView.EvaluatingJavaScript(method); //"concatme()"
 }