private void Start() { var url = UniWebViewHelper.StreamingAssetURLForPath("local_www/test.html"); webview.Load(url); webview.Show(); }
public void LoadFromFile() { if (_webView != null) { return; } _webView = CreateWebView(); _webView.url = UniWebViewHelper.streamingAssetURLForPath(_fileName); // Set the height of webview half of the screen height. int bottomInset = UniWebViewHelper.screenHeight; _webView.insets = new UniWebViewEdgeInsets(0, 0, bottomInset / 2, 0); // `OnEvalJavaScriptFinished` will be called after you invoking some JavaScript function. _webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished; _webView.OnWebViewShouldClose += (webView) => { _webView = null; return(true); }; _webView.Load(); _webView.Show(); }
public void LoadFromFile() { var webView = CreateWebView(); webView.url = UniWebViewHelper.streamingAssetURLForPath(fileName); webView.Load(); webView.Show(); }
/// <summary> /// Get Width Height va ti? le man hinh de tinh toan /// Khi add mot component khong thuoc NGUI , nhung muon tinh toan no voi NGUI thi can get /// </summary> /// <param name="gameObject"></param> /// <returns>Vector3 , x = width , y = height , z = ratio (ti le)</returns> public static Vector3 GetWidthHeightScreenFollowNGUI(GameObject gameObject) { int uiFactor = UniWebViewHelper.RunningOnRetinaIOS() ? 2 : 1; UIRoot mRoot = NGUITools.FindInParents <UIRoot>(gameObject); float ratio = ((float)mRoot.activeHeight / Screen.height) * uiFactor; int width = Mathf.FloorToInt(Screen.width * ratio / uiFactor); int height = Mathf.FloorToInt(Screen.height * ratio / uiFactor); return(new Vector3(width, height, ratio)); }
void Start() { var webViewGameObject = new GameObject("UniWebView"); webView = webViewGameObject.AddComponent <UniWebView>(); webView.ReferenceRectTransform = GetComponent <RectTransform>(); // webView.Frame = new Rect(0, 0, Screen.width, Screen.height/2f); url = UniWebViewHelper.StreamingAssetURLForPath("local_www/" + url); webView.SetVerticalScrollBarEnabled(false); webView.Load(url); webView.Show(); }
static int PersistentDataURLForPath(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); string o = UniWebViewHelper.PersistentDataURLForPath(arg0); LuaDLL.lua_pushstring(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void LoadUrl() { if (m_UniWebView != null) { m_UniWebView.CleanCache(); } if (m_InputField.text == null) { return; } m_UniWebView = UniWebViewHelper.CreateUniWebView(gameObject, url, 200, 0, 0, 0); m_UniWebView.OnLoadComplete += OnLoadComplete; m_UniWebView.OnReceivedMessage += OnReceivedMessage; m_UniWebView.Load(); }
public void LoadUrl() { if (m_UniWebView != null) { m_UniWebView.CleanCache(); } Canvas parentCanvasOver = overPanel.GetComponentInParent <Canvas>(); Canvas parentCanvasBottom = bottomPanel.GetComponentInParent <Canvas>(); int overPixel = (int)(overPanel.rect.height * parentCanvasOver.scaleFactor + 0.5f); int bottomPixel = (int)(bottomPanel.rect.height * parentCanvasBottom.scaleFactor + 0.5f); m_UniWebView = UniWebViewHelper.CreateUniWebView(gameObject, url, overPixel, 0, bottomPixel, 0); m_UniWebView.OnLoadComplete += OnLoadComplete; m_UniWebView.Load(); }
// Use this for initialization void Start() { _untilNextTimerUpdate = 0; _locationUpdateCoroutine = null; webView = _webView; eggsCanvas = _eggsCanvas; loginCanvas = _loginCanvas; logoCanvas = _logoCanvas; tutorialCanvas = _tutorialCanvas; registerCanvas = _registerCanvas; kaijuCanvas = _kaijuCanvas; //checkedInCanvas = _checkedInCanvas; friendsCanvas = _friendsCanvas; friendSearchCanvas = _friendSearchCanvas; _logoCanvas.enabled = true; _eggsCanvas.enabled = false; _friendsCanvas.enabled = false; _loginCanvas.enabled = false; _kaijuCanvas.enabled = false; _registerCanvas.enabled = false; _wrongPasswordText.enabled = false; _connectionErrorText.enabled = false; _tutorialCanvas.enabled = false; _userNotFoundText.enabled = false; _userFoundText.enabled = false; _addFriendSucceedText.enabled = false; _enterYourFriendsUsernameText.enabled = false; _friendSearchCanvas.enabled = false; _userSearchResult = null; //_mainMenuCanvas.enabled = false; //_mapCanvas.enabled = false; _kaijuCanvas.enabled = false; mapLoaded = false; _webView.url = UniWebViewHelper.streamingAssetURLForPath(MAP_ADDRESS); _webView.OnLoadComplete += onLoadComplete; _webView.OnReceivedMessage += onReceivedMessage; friendEggToegg(); }
private void SetWebView() { int uiFactor = UniWebViewHelper.RunningOnRetinaIOS() ? 2:1; UIRoot mRoot = NGUITools.FindInParents <UIRoot>(gameObject); float ratio = ((float)mRoot.activeHeight / Screen.height) * uiFactor; int width = Mathf.FloorToInt(Screen.width * ratio / uiFactor); int height = Mathf.FloorToInt(Screen.height * ratio / uiFactor); UISliceBackgroundPopup backgroundPopup = gameObject.GetComponentInChildren <UISliceBackgroundPopup>(); int webMarginWidth = Mathf.FloorToInt(width - (backgroundPopup.PopupWidth - 30f)); int webMarginHeight = Mathf.FloorToInt(height - (backgroundPopup.PopupHeight - 30f)); int leftRight = Mathf.FloorToInt(webMarginWidth / (2 * ratio)); int top = Mathf.RoundToInt(((webMarginHeight / 2) + backgroundPopup.buttonClose.GetComponentInChildren <UISprite>().height) / ratio); int bottom = Mathf.RoundToInt(webMarginHeight / (2 * ratio)); webView.insets = new UniWebViewEdgeInsets(top, leftRight, bottom, leftRight); }
/// <summary> /// 加载并显示WEB UI /// </summary> public void CreateWebView() { webView = UniWebViewHelper.CreateWebView(); //1.找到资源保存的文件夹 #if UNITY_ANDROID // var assetUrl = "/sdcard/DCIM/AR游/CustomOverlay.html"; var assetUrl = UniWebViewHelper.PersistentDataURLForPath("DownloadFile/Web/CustomOverlay.html"); #elif UNITY_IOS || UNITY_IPHONE var assetUrl = UniWebViewHelper.PersistentDataURLForPath("DownloadFile/Web/CustomOverlay.html"); #endif Debug.Log("web view url =====" + assetUrl); webView.ReferenceRectTransform = WebUI; webView.urlOnStart = assetUrl; webView.Load(assetUrl); webView.Show(); webView.OnMessageReceived += WebView_OnMessageReceived; webView.OnPageFinished += WebView_OnPageFinished; webView.OnPageStarted += WebView_OnPageStarted; webView.OnPageErrorReceived += WebView_OnPageErrorReceived; }
static int _CreateUniWebViewHelper(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { UniWebViewHelper obj = new UniWebViewHelper(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UniWebViewHelper.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public void LoadFromFile() { if (_webView != null) { return; } _webView = CreateWebView(); _webView.url = UniWebViewHelper.streamingAssetURLForPath(_fileName); // Set the height of webview half of the screen height. int bottomInset = UniWebViewHelper.screenHeight; _webView.insets = new UniWebViewEdgeInsets(0, 0, bottomInset / 2, 0); // If a url with format of "uniwebview://yourPath?param1=value1¶m2=value2" clicked, // a message will be sent from your web page to Unity, // the OnReceivedMessage event will get raised with a "UniWebViewMessage" object as argument. _webView.OnReceivedMessage += OnReceivedMessage; _webView.Load(); _webView.Show(); }
/* * public void goToMainMenu() * { * lastGameState = gameState; * Debug.Log ("go to main menu"); * * mainMenuCamera.enabled = true; * if (destroyCityScene) * Destroy (destroyCityScene); * if (phoneCameraScene) * Destroy (phoneCameraScene); * * gameState = GameState.MainMenu; * } */ public void goToMapView() { gameObject.GetComponent <AudioSource> ().Play(); if (destroyCityScene) { Destroy(destroyCityScene); } if (phoneCameraScene) { Destroy(phoneCameraScene); } if (markerIdAnalytics != null) { Analytics.CustomEvent("BuildingDestruction", new Dictionary <string, object> { { "BuildingId", markerIdAnalytics }, { "PlayerId", SpatialClient2.single.userId }, { "Time", DateTime.UtcNow.ToString() }, { "DestructionTime", destructionTime } }); markerIdAnalytics = null; } lastGameState = gameState; Debug.Log("go to map"); mainMenuCamera.enabled = true; //UniWebView mapWebView = (UniWebView)(mainMenuCamera.GetComponent<MainMenuScript> ()._webView); MessageController.single.displayWaitScreen(null); UniWebView mapWebView = GetComponent <MainMenuScript>()._webView; mapWebView.Stop(); mapWebView.url = UniWebViewHelper.streamingAssetURLForPath(MainMenuScript.MAP_ADDRESS); mapWebView.Load(); gameState = GameState.MapView; }
UniWebViewEdgeInsets InsetsForScreenOreitation(UniWebView webView, UniWebViewOrientation orientation) { Vector3[] fourCornersArray = new Vector3[4]; mContent.GetWorldCorners(fourCornersArray); Camera cameraTmp = null; if (mCanvas.renderMode == RenderMode.ScreenSpaceOverlay) { } else { cameraTmp = mCanvas.worldCamera; } Vector2 bottomLeft = RectTransformUtility.WorldToScreenPoint(cameraTmp, fourCornersArray[0]); //Vector2 pos1 = cameraTmp.WorldToScreenPoint(fourCornersArray[1]); Vector2 topRight = RectTransformUtility.WorldToScreenPoint(cameraTmp, fourCornersArray[2]); // Vector2 pos3 = cameraTmp.WorldToScreenPoint(fourCornersArray[3]); float _top = Screen.height - topRight.y; float _left = bottomLeft.x; float _bottom = bottomLeft.y; float _right = Screen.width - topRight.x; if (orientation == UniWebViewOrientation.Portrait) //竖屏 { int offset = 0; return(new UniWebViewEdgeInsets(UniWebViewHelper.ConvertPixelToPoint(_top, false) + offset, UniWebViewHelper.ConvertPixelToPoint(_left, true) + offset, UniWebViewHelper.ConvertPixelToPoint(_bottom, false) + offset, UniWebViewHelper.ConvertPixelToPoint(_right, true) + offset)); } else//横屏 { int offset = 0; return(new UniWebViewEdgeInsets(UniWebViewHelper.ConvertPixelToPoint(_top, false) + offset, UniWebViewHelper.ConvertPixelToPoint(_left, true) + offset, UniWebViewHelper.ConvertPixelToPoint(_bottom, false) + offset, UniWebViewHelper.ConvertPixelToPoint(_right, true) + offset)); } }
public void LoadFromStreamingAssets(string path) { var url = UniWebViewHelper.StreamingAssetURLForPath(filePath); GetComponent <UniWebView>().Load(url); }
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); } }