• unity调android ios 浏览器 uniwebview2.1使用


    uniwebview2.1使用


    插件下载地址:

    http://download.csdn.net/detail/onafioo/9576200


    示例

    public class BrowserMgr {
    
    	private static UniWebView _webView;
    
    	static GameObject BrowserGo;
    
    	public static void Open(string url){
    		if(!CheckURL(url)){
    			Debug.Log("[N]---browser url error!! url:"+url);
    			return;
    		}
    
    		if(null == BrowserGo)BrowserGo = new GameObject("browser");
    		_webView = BrowserGo.GetComponent<UniWebView>();
    		if (_webView == null) {
    			_webView = BrowserGo.AddComponent<UniWebView>();
    			_webView.OnReceivedMessage += OnReceivedMessage;
    			_webView.OnLoadComplete += OnLoadComplete;
    			_webView.OnWebViewShouldClose += OnWebViewShouldClose;
    			//_webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished;
    			_webView.InsetsForScreenOreitation += InsetsForScreenOreitation;
    		}
    		
    		int bottomInset = (int)(UniWebViewHelper.screenHeight);
    		_webView.insets = new UniWebViewEdgeInsets(0,0,0,0);
    		_webView.url = url;
    
    		//_webView.url = "http://uniwebview.onevcat.com/demo/index1-1.html";
    		//_webView.url = "http://192.168.12.110:8401/t.html";
    		//_webView.url = "http://www.sina.com.cn/";
    		_webView.SetSpinnerLabelText("载入中...");
    		_webView.SetShowSpinnerWhenLoading(true);
    		Debug.Log("URL:"+_webView.url);
    		ShowViewEventArgs e = new ShowViewEventArgs(ViewNames.HomeView.ToString(), true, true, true);
    		App.Instance.EventManager.SendEvent(e);
    		_webView.Load();
    	}
    
    	/// <summary>
    	/// 浏览器载入成功回调
    	/// </summary>
    	/// <param name="webView">Web view.</param>
    	/// <param name="success">If set to <c>true</c> success.</param>
    	/// <param name="errorMessage">Error message.</param>
    	static void OnLoadComplete(UniWebView webView, bool success, string errorMessage) {
    		if (success) {
    			Debug.Log("[N]---browser load complete!");
    			webView.Show();
    		} else {
    			Debug.Log("[N]---Something wrong in webview loading: " + errorMessage);
    		}
    	}
    
    	/// <summary>
    	/// 页面标签信息回调
    	/// </summary>
    	/// <param name="webView">Web view.</param>
    	/// <param name="message">Message.</param>
    	static void OnReceivedMessage(UniWebView webView, UniWebViewMessage message) {
    		Debug.Log("[N]---"+message.rawMessage);
    		//NTODO 处理下必要的页面标签返回信息
    	}
    
    	/// <summary>
    	/// 弹出Alert
    	/// </summary>
    	/// <param name="alert">Alert.</param>
    	public void ShowAlertInWebview(string alert) {_webView.EvaluatingJavaScript(alert);}
    
    	/// <summary>
    	/// 浏览器关闭回调
    	/// </summary>
    	/// <param name="webView">Web view.</param>
    	static bool OnWebViewShouldClose(UniWebView webView) 
    	{
    		Debug.Log("[N]---browser close!");
    		if (webView == _webView) {
    			_webView = null;
    			return true;
    		}
    		return false;
    	}
    	
    	/// <summary>
    	/// 横竖屏切换
    	/// </summary>
    	/// <returns>The for screen oreitation.</returns>
    	/// <param name="webView">Web view.</param>
    	/// <param name="orientation">Orientation.</param>
    	static UniWebViewEdgeInsets InsetsForScreenOreitation(UniWebView webView, UniWebViewOrientation orientation) {
    		int bottomInset = (int)(UniWebViewHelper.screenHeight);
    		if (orientation == UniWebViewOrientation.Portrait) return new UniWebViewEdgeInsets(0,0,bottomInset,0);
    		else return new UniWebViewEdgeInsets(0,0,bottomInset,0);
    	}
    
    	/// <summary>
    	/// 检测URL合法性
    	/// </summary>
    	/// <returns><c>true</c>, if UR was checked, <c>false</c> otherwise.</returns>
    	/// <param name="url">URL.</param>
    	static bool CheckURL(string url){
    		bool b = false;
    		b = Regex.IsMatch(url,"^http://[a-z0-9A-Z.-]*");
    		return b;
    	}
    
    }
    


  • 相关阅读:
    Java堆、栈和常量池
    Java多线程内存模型
    To-do List
    Java Collections Framework 汇总
    关于ArrayList.clear()与=null以及new ArrayList<E>()
    开源协议
    git-svn — 让git和svn协同工作
    Java Collections Framework 之 RandomAccess接口
    转 : CSS Modules详解及React中实践
    转 : JBoss Web和 Tomcat的区别
  • 原文地址:https://www.cnblogs.com/nafio/p/9137313.html
Copyright © 2020-2023  润新知