Exemple #1
0
    public void Hide()
    {
#if UNITY_IOS || UNITY_ANDROID || UNITY_EDITOR
        uniWebView.Hide();
#endif
    }
 private void OnReceivedMessage(UniWebView webView, UniWebViewMessage message)
 {
     Debug.Log(message.rawMessage);
     if (string.Equals(message.path, "move"))
     {
         Vector3 zero = Vector3.zero;
         if (string.Equals(message.args["direction"], "up"))
         {
             zero = new Vector3(0f, 0f, 1f);
         }
         else if (string.Equals(message.args["direction"], "down"))
         {
             zero = new Vector3(0f, 0f, -1f);
         }
         else if (string.Equals(message.args["direction"], "left"))
         {
             zero = new Vector3(-1f, 0f, 0f);
         }
         else if (string.Equals(message.args["direction"], "right"))
         {
             zero = new Vector3(1f, 0f, 0f);
         }
         int result = 0;
         if (int.TryParse(message.args["distance"], out result))
         {
             zero *= result;
         }
         this._moveVector = zero;
     }
     else if (string.Equals(message.path, "add"))
     {
         if (this._cube != null)
         {
             UnityEngine.Object.Destroy(this._cube);
         }
         this._cube = UnityEngine.Object.Instantiate(this.cubePrefab) as GameObject;
         this._cube.GetComponent<UniWebViewCube>().webViewDemo = this;
         this._moveVector = Vector3.zero;
     }
     else if (string.Equals(message.path, "close"))
     {
         webView.Hide();
         UnityEngine.Object.Destroy(webView);
         webView.OnReceivedMessage -= new UniWebView.ReceivedMessageDelegate(this.OnReceivedMessage);
         webView.OnLoadComplete -= new UniWebView.LoadCompleteDelegate(this.OnLoadComplete);
         webView.OnWebViewShouldClose -= new UniWebView.WebViewShouldCloseDelegate(this.OnWebViewShouldClose);
         webView.OnEvalJavaScriptFinished -= new UniWebView.EvalJavaScriptFinishedDelegate(this.OnEvalJavaScriptFinished);
         webView.InsetsForScreenOreitation -= new UniWebView.InsetsForScreenOreitationDelegate(this.InsetsForScreenOreitation);
         this._webView = null;
     }
 }
Exemple #3
0
    //6. The webview can talk to Unity by a url with scheme of "uniwebview". See the webpage for more
    //   Every time a url with this scheme clicked, OnReceivedMessage of webview event get raised.
    void OnReceivedMessage(UniWebView webView, UniWebViewMessage message)
    {
        Debug.Log("Received a message from native");
        Debug.Log(message.rawMessage);
        //7. You can get the information out from the url path and query in the UniWebViewMessage
        //For example, a url of "uniwebview://move?direction=up&distance=1" in the web page will
        //be parsed to a UniWebViewMessage object with:
        //				message.scheme => "uniwebview"
        //              message.path => "move"
        //              message.args["direction"] => "up"
        //              message.args["distance"] => "1"
        // "uniwebview" scheme is sending message to Unity by default.
        // If you want to use your customized url schemes and make them sending message to UniWebView,
        // use webView.AddUrlScheme("your_scheme") and webView.RemoveUrlScheme("your_scheme")
        if (string.Equals(message.path, "move"))
        {
            Vector3 direction = Vector3.zero;
            if (string.Equals(message.args["direction"], "up"))
            {
                direction = new Vector3(0, 0, 1);
            }
            else if (string.Equals(message.args["direction"], "down"))
            {
                direction = new Vector3(0, 0, -1);
            }
            else if (string.Equals(message.args["direction"], "left"))
            {
                direction = new Vector3(-1, 0, 0);
            }
            else if (string.Equals(message.args["direction"], "right"))
            {
                direction = new Vector3(1, 0, 0);
            }

            int distance = 0;
            if (int.TryParse(message.args["distance"], out distance))
            {
                direction *= distance;
            }

            _moveVector = direction;
        }
        else if (string.Equals(message.path, "add"))
        {
            if (_cube != null)
            {
                Destroy(_cube);
            }
            _cube = GameObject.Instantiate(cubePrefab) as GameObject;
            _cube.GetComponent <UniWebViewCube>().webViewDemo = this;
            _moveVector = Vector3.zero;
        }
        else if (string.Equals(message.path, "close"))
        {
            //8. When you done your work with the webview,
            //you can hide it, destory it and do some clean work.
            webView.Hide();
            Destroy(webView);
            webView.OnReceivedMessage         -= OnReceivedMessage;
            webView.OnLoadComplete            -= OnLoadComplete;
            webView.OnWebViewShouldClose      -= OnWebViewShouldClose;
            webView.OnEvalJavaScriptFinished  -= OnEvalJavaScriptFinished;
            webView.InsetsForScreenOreitation -= InsetsForScreenOreitation;
            _webView = null;
        }
    }
Exemple #4
0
	//6. The webview can talk to Unity by a url with scheme of "uniwebview". See the webpage for more
	//   Every time a url with this scheme clicked, OnReceivedMessage of webview event get raised.
	void OnReceivedMessage(UniWebView webView, UniWebViewMessage message) {
        Debug.Log("Received a message from native");
		Debug.Log(message.rawMessage);
		//7. You can get the information out from the url path and query in the UniWebViewMessage
		//For example, a url of "uniwebview://move?direction=up&distance=1" in the web page will
		//be parsed to a UniWebViewMessage object with:
		//				message.scheme => "uniwebview"
		//              message.path => "move"
		//              message.args["direction"] => "up"
		//              message.args["distance"] => "1"
		// "uniwebview" scheme is sending message to Unity by default.
		// If you want to use your customized url schemes and make them sending message to UniWebView,
		// use webView.AddUrlScheme("your_scheme") and webView.RemoveUrlScheme("your_scheme")
		if (string.Equals(message.path,"move")) {
			Vector3 direction = Vector3.zero;
			if (string.Equals(message.args["direction"],"up")) {
				direction = new Vector3(0,0,1);
			} else if (string.Equals(message.args["direction"],"down")) {
				direction = new Vector3(0,0,-1);
			} else if (string.Equals(message.args["direction"],"left")) {
				direction = new Vector3(-1,0,0);
			} else if (string.Equals(message.args["direction"],"right")) {
				direction = new Vector3(1,0,0);
			}

			int distance = 0;
			if (int.TryParse(message.args["distance"], out distance)) {
				direction *= distance;
			}

			_moveVector = direction;

		} else if (string.Equals(message.path, "add")) {
			if (_cube != null) {
				Destroy(_cube);
			}
			_cube = GameObject.Instantiate(cubePrefab) as GameObject;
			_cube.GetComponent<UniWebViewCube>().webViewDemo = this;
			_moveVector = Vector3.zero;
		} else if (string.Equals(message.path, "close")) {
			//8. When you done your work with the webview,
			//you can hide it, destory it and do some clean work.
			webView.Hide();
			Destroy(webView);
			webView.OnReceivedMessage -= OnReceivedMessage;
			webView.OnLoadComplete -= OnLoadComplete;
			webView.OnWebViewShouldClose -= OnWebViewShouldClose;
			webView.OnEvalJavaScriptFinished -= OnEvalJavaScriptFinished;
			webView.InsetsForScreenOreitation -= InsetsForScreenOreitation;
			_webView = null;
		}
	}
Exemple #5
0
 void OnDisable()
 {
     _webView.Hide();
 }
Exemple #6
0
 public override void OnFinishedHide()
 {
     m_WebView.Hide();
     EventItemPrefab.Clear();
     base.OnFinishedHide();
 }
        public static void Init(Action <bool> InInitCallback)
        {
            if (_webView != null)
            {
                InInitCallback?.Invoke(true);
                return;
            }

            _webView = UnityEngine.Object.FindObjectOfType <UniWebView>();
            if (_webView != null)
            {
                InInitCallback?.Invoke(true);
                return;
            }

            GameObject gameObject = GameObject.Find("UniWebView");

            if (null == gameObject)
            {
                gameObject = new GameObject("UniWebView");
            }
            _webView = gameObject.AddComponent <UniWebView>();
            UnityEngine.Object.DontDestroyOnLoad(gameObject);

            _webView.SetShowToolbar(false);
            _webView.SetBackButtonEnabled(false);
            _webView.SetBouncesEnabled(false);
            _webView.SetAllowFileAccessFromFileURLs(true);
            _webView.BackgroundColor = Color.white;

            UniWebView.PageFinishedDelegate onPageFinished = null;

            onPageFinished = (InWebView, InCode, InUrl) =>
            {
                isWebViewShowing = false;
#if !UNITY_EDITOR && UNITY_IOS
                RegisterKeyboardNotification();
#endif
                _webView.Hide();
                // ReSharper disable once AccessToModifiedClosure
                _webView.OnPageFinished -= onPageFinished;
                InInitCallback?.Invoke(true);
            };

            UniWebView.PageErrorReceivedDelegate onPageErrorReceived = null;
            onPageErrorReceived = (InView, InCode, InMessage) =>
            {
                Log.Error($"[WebViewBridge] UniWebView.OnPageErrorReceived : errorCode = {InCode}, msg = {InMessage}");
                _webView.Hide();
                _webView.OnPageErrorReceived -= onPageErrorReceived;
                UnityEngine.Object.DestroyImmediate(_webView);
                InInitCallback?.Invoke(false);
            };

            _webView.OnPageFinished += onPageFinished;

            _webView.OnPageErrorReceived += onPageErrorReceived;

            _webView.OnShouldClose += InView =>
            {
#if UNITY_ANDROID
                if (isWebViewShowing)
                {
                    CallJsFunction("goBack");
                }
                else
                {
                    ADA_Manager.PageManager.Instance.BackButtonAction();
                }
#endif
                return(isWebViewShowing);
            };
        }
Exemple #8
0
 public void Close()
 {
     _webView?.Hide();
 }
Exemple #9
0
 public void Hide()
 {
     webView.Hide();
 }