Beispiel #1
0
        public void Show(string url)
        {
            /*if(WebView == null) {
             *  if(complete != null)complete();
             *  return;
             * }*/
            UniWebView.CleanCache();
            UniWebView.AddUrlScheme("lufy");
            UniWebView.OnLoadComplete += OnLoadCompleteEvent; // 読み込み完了後のイベント登録

            /*
             * UniWebView.OnReceivedMessage += OnReceivedMessage; // URLスキーマー取得のイベント登録
             * UniWebView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished; // JavaScript実行完了時のイベント登録
             */
            UniWebView.SetBackgroundColor(Color.clear);  // 透過処理を有効化
            UniWebView.backButtonEnable = false;         // Androidの戻るボタン(ソフトウェア)を無効化
            UniWebView.SetShowSpinnerWhenLoading(false); // iOSの読み込み中スピナーを無効化
            UniWebView.toolBarShow = false;              // iOSのツールブラウザーを無効化
            UniWebView.HideToolBar(false);               // iOSのツールブラウザーを無効化
            UniWebView.zoomEnable = false;               // iOSの ズームを無効化
            string userAgent = "Mozilla /5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B5110e Safari/601.1 ";

            UniWebView.SetUserAgent(userAgent);

            /*UniWebView.insets.left   = 0;
            *  UniWebView.insets.top    = 10;
            *  UniWebView.insets.right  = 0;*/
            UniWebView.insets.bottom = 106;

            RequestLoad(url);
            //if(complete != null)complete();
        }
Beispiel #2
0
 public void ToolBar()
 {
     if (_webView.toolBarShow)
     {
         _webView.HideToolBar(true);
     }
     else
     {
         _webView.ShowToolBar(true);
     }
 }
Beispiel #3
0
 private void _webView_OnLoadComplete(UniWebView webView, bool success, string errorMessage)
 {
     if (success)
     {
         if (webView.currentUrl.Contains("#access_token="))
         {
             lingPai = getAccessToken(webView.currentUrl);
             StartCoroutine("GetUserMessage");
             PlayerPrefs.SetString("Token", lingPai);
             _webView.Hide(true, UniWebViewTransitionEdge.Bottom, 0.3f);
             _webView.HideToolBar(true);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// WebView表示.
        /// </summary>
        public void Show(ShowParam param = null)
        {
            param = param ?? new ShowParam();

            var area = GetDrawArea(param.buffer);

            if (area != null)
            {
                #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
                uniWebView.insets = area;

                uniWebView.SetShowSpinnerWhenLoading(param.showSpinner);
                uniWebView.HideToolBar(param.toolBarShowAnim);
                uniWebView.Show(param.fade, param.direction, param.duration, param.finishAction);
                #endif
            }
        }
Beispiel #5
0
        //----- property -----

        //----- method -----

        public IObservable <Unit> Initialize()
        {
            if (initialized)
            {
                return(Observable.ReturnUnit());
            }

            #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
            uniWebView = UnityUtility.GetOrAddComponent <UniWebView>(gameObject);

            // .
            uniWebView.HideToolBar(false);

            // URLリンクをデバイスのデフォルトブラウザで開くかどうかの設定.
            uniWebView.openLinksInExternalBrowser = false;

            // 横スクロールバー.
            uniWebView.SetHorizontalScrollBarShow(false);

            // 縦スクロールバー.
            uniWebView.SetVerticalScrollBarShow(false);
            uniWebView.CleanCache();
            #endif

            #if UNITY_ANDROID
            uniWebView.SetUseWideViewPort(false);
            uniWebView.backButtonEnable = true;
            #endif

            #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
            uniWebView.OnLoadComplete       += OnLoadComplete;
            uniWebView.OnReceivedMessage    += OnReceivedMessage;
            uniWebView.OnWebViewShouldClose += OnWebViewShouldClose;
            #endif

            initialized = true;

            return(Observable.ReturnUnit());
        }
Beispiel #6
0
    void OnGUI()
    {
        int uiFactor = UniWebViewHelper.RunningOnRetinaIOS() ? 2 : 1;

        if (GUI.Button(new Rect(0, Screen.height - uiFactor * 100, uiFactor * 100, uiFactor * 50), "Open"))
        {
            //2. You can add a UniWebView either in Unity Editor or by code.
            //Here we check if there is already a UniWebView component. If not, add one.
            _webView = GetComponent <UniWebView>();
            if (_webView == null)
            {
                _webView = gameObject.AddComponent <UniWebView>();
                _webView.OnReceivedMessage        += OnReceivedMessage;
                _webView.OnLoadComplete           += OnLoadComplete;
                _webView.OnWebViewShouldClose     += OnWebViewShouldClose;
                _webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished;
            }

            //3. Set the frame of this webview. Give it a url to load. Add event listener to it.
            int bottomInset = Screen.height / (2 * uiFactor);
            _webView.insets = new UniWebViewEdgeInsets(5, 5, bottomInset, 5);
            _webView.url    = "http://uniwebview.onevcat.com/demo/index1-1.html";

            //You can read a local html file, by putting the file into /Assets/StreamingAssets folder
            //And use the url like these
            //If you are using "Split Application Binary" for Android, see the FAQ section of manual for more.

            /*
             #if UNITY_EDITOR
             * _webView.url = Application.streamingAssetsPath + "/index.html";
             #elif UNITY_IOS
             * _webView.url = Application.streamingAssetsPath + "/index.html";
             #elif UNITY_ANDROID
             * _webView.url = "file:///android_asset/index.html";
             #endif
             */

            // You can set the spinner visibility and text of the webview.
            // This line can change the text of spinner to "Wait..." (default is  "Loading...")
            //_webView.SetSpinnerLabelText("Wait...");
            // This line will tell UniWebView to not show the spinner as well as the text when loading.
            //_webView.SetShowSpinnerWhenLoading(false);

            //4.Now, you can load the webview and waiting for OnLoadComplete event now.
            _webView.Load();

            _errorMessage = null;

            //You can also load some HTML string instead from a url or local file.
            //When loading from the HTML string, the _webView.url will take no effect.
            //_webView.LoadHTMLString("<body>I am a html string</body>",null);

            //If you want the webview show immediately, instead of the OnLoadComplete event, call Show()
            //A blank webview will appear first, then load the web page content in it
            //_webView.Show();
        }

        if (_webView != null && GUI.Button(new Rect(uiFactor * 100,
                                                    Screen.height - uiFactor * 100,
                                                    uiFactor * 100,
                                                    uiFactor * 50), "Back"))
        {
            _webView.GoBack();
        }

        //Tool bar is hidden by default. You can use it to navigate or close the webview.
        //The tool bar is only avaliable in iOS system. You can use "back button" of Android to go back.
        if (_webView != null && GUI.Button(new Rect(uiFactor * 200,
                                                    Screen.height - uiFactor * 100,
                                                    uiFactor * 100,
                                                    uiFactor * 50), "ToolBar"))
        {
            if (_webView.toolBarShow)
            {
                _webView.HideToolBar(true);
            }
            else
            {
                _webView.ShowToolBar(true);
            }
        }

        if (_errorMessage != null)
        {
            GUI.Label(new Rect(0, 0, uiFactor * 300, uiFactor * 50), _errorMessage);
        }
    }
Beispiel #7
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(0, Screen.height - 150, 150, 80), "Open"))
        {
            //2. You can add a UniWebView either in Unity Editor or by code.
            //Here we check if there is already a UniWebView component. If not, add one.
            _webView = GetComponent <UniWebView>();
            if (_webView == null)
            {
                _webView = gameObject.AddComponent <UniWebView>();
                _webView.OnReceivedMessage        += OnReceivedMessage;
                _webView.OnLoadComplete           += OnLoadComplete;
                _webView.OnWebViewShouldClose     += OnWebViewShouldClose;
                _webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished;

                _webView.InsetsForScreenOreitation += InsetsForScreenOreitation;
            }

            //3. You can set the insets of this webview by assigning an insets value simply
            //   like this:

            /*
             *              int bottomInset = (int)(UniWebViewHelper.screenHeight * 0.5f);
             *              _webView.insets = new UniWebViewEdgeInsets(5,5,bottomInset,5);
             */

            // Or you can also use the `InsetsForScreenOreitation` delegate to specify different
            // insets for portrait or landscape screen. If your webpage should resize on both portrait
            // and landscape, please use the delegate way. See the `InsetsForScreenOreitation` method
            // in this file for more.

            // Now, set the url you want to load.
            _webView.url = "http://uniwebview.onevcat.com/demo/index1-1.html";

            //You can read a local html file, by putting the file into /Assets/StreamingAssets folder
            //And use the url like these
            //If you are using "Split Application Binary" for Android, see the FAQ section of manual for more.

            /*
             #if UNITY_EDITOR
             * _webView.url = Application.streamingAssetsPath + "/index.html";
             #elif UNITY_IOS
             * _webView.url = Application.streamingAssetsPath + "/index.html";
             #elif UNITY_ANDROID
             * _webView.url = "file:///android_asset/index.html";
             #elif UNITY_WP8
             * _webView.url = "Data/StreamingAssets/index.html";
             #endif
             */

            // You can set the spinner visibility and text of the webview.
            // This line can change the text of spinner to "Wait..." (default is  "Loading...")
            //_webView.SetSpinnerLabelText("Wait...");
            // This line will tell UniWebView to not show the spinner as well as the text when loading.
            //_webView.SetShowSpinnerWhenLoading(false);

            //4.Now, you can load the webview and waiting for OnLoadComplete event now.
            _webView.Load();

            _errorMessage = null;

            //You can also load some HTML string instead from a url or local file.
            //When loading from the HTML string, the _webView.url will take no effect.
            //_webView.LoadHTMLString("<body>I am a html string</body>",null);

            //If you want the webview show immediately, instead of the OnLoadComplete event, call Show()
            //A blank webview will appear first, then load the web page content in it
            //_webView.Show();
        }

        if (_webView != null && GUI.Button(new Rect(150,
                                                    Screen.height - 150,
                                                    150,
                                                    80), "Back"))
        {
            _webView.GoBack();
        }

        //Tool bar is hidden by default. You can use it to navigate or close the webview.
        //The tool bar is only avaliable in iOS system. You can use "back button" of Android to go back.
        if (_webView != null && GUI.Button(new Rect(300,
                                                    Screen.height - 150,
                                                    150,
                                                    80), "ToolBar"))
        {
            if (_webView.toolBarShow)
            {
                _webView.HideToolBar(true);
            }
            else
            {
                _webView.ShowToolBar(true);
            }
        }

        if (_errorMessage != null)
        {
            GUI.Label(new Rect(0, 0, Screen.width, 80), _errorMessage);
        }
    }