コード例 #1
0
    // Try to open local page from StreamingAssets.
    // That function copy index.html page from StreamingAssets to persistance path
    // And trying to open it in webView
    void LoadLocalPage()
    {
        errStatus = false;

        string localPage   = "index.html";
        string assetsPath  = System.IO.Path.Combine(Application.streamingAssetsPath, localPage);
        string storagePath = Application.persistentDataPath + "/" + localPage;

        if (assetsPath.Contains("://"))
        {
            WWW www = new WWW(assetsPath);
            while (!www.isDone)
            {
            }

            if (string.IsNullOrEmpty(www.error))
            {
                System.IO.File.WriteAllBytes(storagePath, www.bytes);
            }
            webViewObject.LoadURL("file://" + storagePath);
        }
        else
        {
            webViewObject.LoadURL(assetsPath);
        }
        devStatus = "LOADED LOCAL URL";
    }
コード例 #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);
            }
        }
    }
コード例 #3
0
 public void LoadWebPage(string url, string jsEvalString)
 {
     m_jsEvalString = jsEvalString;
     NavigationPanel.SetActive(true);
     WebView.SetMargins(0, 100, 0, 0);//to place navigation bar
     WebView.LoadURL(url);
 }
コード例 #4
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;
        }
    }
コード例 #5
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;
        }
    }
コード例 #6
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);
    }
コード例 #7
0
    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);
    }
コード例 #8
0
        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;
        }
コード例 #9
0
    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);
    }
コード例 #10
0
    // Use this for initialization
    void Start()
    {
        //웹뷰 오브젝트 얻기
        m_Web = gameObject.GetComponent <WebViewObject>();

        //없을 경우 추가하기
        if (m_Web == null)
        {
            m_Web = gameObject.AddComponent <WebViewObject>();
        }

        m_Web.Init(RecvURL);
        m_Web.SetMargins(50, 150, 50, 50);
        m_Web.LoadURL(m_URL.text); //http:// 필수
        m_Web.SetVisibility(true);
    }
コード例 #11
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;
    }
コード例 #12
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;
        }
    }
コード例 #13
0
 void Start()
 {
     Input.backButtonLeavesApp = true;
     Url += AndroidUtil.GetImei();
     Init();
     _webViewObject.LoadURL(Url);
     _webViewObject.SetVisibility(true);
 }
コード例 #14
0
 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
 }
コード例 #15
0
ファイル: Wv.cs プロジェクト: dpr3309/DELL_TEMP_001
        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"));
        }
コード例 #16
0
    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"));
    }
コード例 #17
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);
    }
コード例 #18
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);
 }
コード例 #19
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);
 }
コード例 #20
0
 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);
 }
コード例 #21
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);
     }
         );
 }
コード例 #22
0
    public void StartWebView()
    {
        string strUrl = "http://52.79.169.121/%ea%b5%90%ec%9c%a1%ec%98%81%ec%83%81/%ec%bb%b4%ed%94%8c%eb%a0%88%ec%9d%b8-%ec%9e%85%eb%a7%9b/";

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

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

        webViewObject.LoadURL(strUrl);
        webViewObject.SetVisibility(true);
        webViewObject.SetMargins(50, 50, 50, 50);
    }
コード例 #23
0
ファイル: WebView.cs プロジェクト: furikake6000/WebViewTest
    // Use this for initialization
    void Start()
    {
        wb = gameObject.GetComponent <WebViewObject>();

        wb.Init((msg) => {
            Debug.Log(msg);
        });
        wb.LoadURL(AssetsPath() + "/Web/index.html");
        // 中央に配置
        wb.SetMargins(0, 0, 0, 0);
        wb.SetVisibility(true);
    }
コード例 #24
0
    public void StartWebView()
    {
        string strUrl = "http://52.79.169.121/%EA%B5%90%EC%9C%A1%EC%98%81%EC%83%81/%EC%A3%BC%EB%AC%B8-%EB%B0%9B%EA%B8%B0/";

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

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

        webViewObject.LoadURL(strUrl);
        webViewObject.SetVisibility(true);
        webViewObject.SetMargins(50, 50, 50, 50);
    }
コード例 #25
0
ファイル: ShowWebView.cs プロジェクト: ladnack/ViewAngleDemo
    void OnGUI()
    {
        Rect textArea = new Rect(100, 0, 400, 100);

        url = GUI.TextArea(textArea, url);

        if (GUI.Button(new Rect(500, 0, 100, 100), "GO"))
        {
            webViewObject.LoadURL(url);
            webViewObject.SetVisibility(true);
        }
    }
コード例 #26
0
 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
 }
コード例 #27
0
 public void OpenWindow(string url)
 {
             #if UNITY_ANDROID
     unityActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic <AndroidJavaObject>("currentActivity");
     unityActivityClass.Call("openBrowser", url, _ua, "Logins.html#");
             #else
     if (!webObj)
     {
         webObj = GetComponent <WebViewObject>();
     }
     webObj.LoadURL(url);
             #endif
 }
コード例 #28
0
    public void Open()
    {
        if (string.IsNullOrEmpty(url))
        {
            return;
        }

        // web.enabled = true;
        isVisible = true;

        web.LoadURL(url);
        web.SetVisibility(true);
    }
コード例 #29
0
        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.");
                }
            }
        }
コード例 #30
0
    public void StartWebView()
    {
        string strUrl = "http://www.fb.com";

        webViewObject =
            (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init((msg) => {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
        });

        webViewObject.LoadURL(strUrl);
        webViewObject.SetVisibility(true);
        webViewObject.SetMargins(100, 100, 100, 100);
    }
コード例 #31
0
ファイル: WebView.cs プロジェクト: ljy8509113/BoardGameUnity
    public void StartWebView(string url)
    {
        string strUrl = "http://192.168.0.8:8080/BoardGame/gameList.do";

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

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

        webViewObject.LoadURL(strUrl);
        webViewObject.SetVisibility(true);
        webViewObject.SetMargins(50, 50, 50, 50);
    }
コード例 #32
0
ファイル: WebView.cs プロジェクト: sigrain/Capsule
    // Start is called before the first frame update
    void Start()
    {
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            // Id: (msg) => Debug.Log(string.Format("CallOnLoaded[{0}]", msg)),
            enableWKWebView: true);

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

//今回は実験としてGoogleを入れてます。
        webViewObject.LoadURL("https://www.google.co.jp");
    }
コード例 #33
0
 static int QPYX_LoadURL_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 2);
         WebViewObject QPYX_obj_YXQP  = (WebViewObject)ToLua.CheckObject <WebViewObject>(L_YXQP, 1);
         string        QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2);
         QPYX_obj_YXQP.LoadURL(QPYX_arg0_YXQP);
         return(0);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
コード例 #34
0
    //------------------------------ Public Methods ------------------------------//
    #region Control
    /// <summary>
    /// Load and show <paramref name="url"/> page.
    /// </summary>
    public static void LoadUrl(string url)
    {
        // Init
        if (m_webViewObject == null)
        {
            m_webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
            m_webViewObject.Init(
                cb: unityCallback,    // JS -> "Unity.call('msg'); return false;" / <a href="unity:msg">
                ld: OnLoadedCallback, // Loaded anything including error page.
                err: OnErrorCallback, // On Error only
                transparent: true,
                //ua: "custom user agent string",
                enableWKWebView: true // iOS
                );
        }

#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
        m_webViewObject.bitmapRefreshCycle = 1;
#endif
        m_webViewObject.SetMargins(m_margin.left, m_margin.top, m_margin.right, m_margin.bottom);
        m_webViewObject.SetVisibility(true);

        // Load page
#if !UNITY_WEBPLAYER
        // Remote
        if (url.StartsWith("http"))
        {
            m_webViewObject.LoadURL(url.Replace(" ", "%20"));
        }
        // Local
        else
        {
            var dst = System.IO.Path.Combine(Application.persistentDataPath, url);
            m_webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
        }
#endif
    }
コード例 #35
0
    public void show()
    {
        if (webViewObject == null)
        {
            webViewObject = GetComponent<WebViewObject>();
            webViewObject.Init();
            webViewObject.LoadURL(url);
            webViewObject.SetMargins(0,58,0,0);    // マージン(単位px) 左、上、右、下
            Debug.Log("nai");
        }
        else
            Debug.Log("aru");

        webViewObject.SetVisibility(true);

        _bg.SetActive(true);
        _closeButton.SetActive(true);

        Util.Resource.getModel().GetComponent<Model>().pause();
    }
コード例 #36
0
ファイル: SampleWebView.cs プロジェクト: Ginjack/dir-kn
    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);");
    }
コード例 #37
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);
                }
            }
        }
    }
コード例 #38
0
        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.");
                }
            }
        }
コード例 #39
0
ファイル: SampleWebView.cs プロジェクト: gree/unity-webview
    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;
    }
コード例 #40
0
ファイル: VK.cs プロジェクト: kirillrybin/unity-vk-mobile
    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");
        }
    }