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;
}
}
unity调android ios 浏览器 uniwebview2.1使用的更多相关文章
- [原]unity调Android(三)
private UnityPlayer mUnityPlayer; @Override protected void onCreate(Bundle savedInstanceState) ...
- Android/iOS内嵌Unity开发示例
Unity 与 Android/iOS 交叉开发主要有两种方式,以 Android 为例,一是 Android 生成 jar 或者 aar 包,导入到 unity3d plugin/bin/ 目录下: ...
- unity 与 android 协调工作 注意事项
原地址:http://blog.csdn.net/u012085988/article/details/17436191 1.unity调android函数 AndroidJavaClass jc = ...
- Unity在Android和iOS中如何调用Native API
本文主要是对unity中如何在Android和iOS中调用Native API进行介绍. 首先unity支持在C#中调用C++ dll,这样可以在Android和iOS中提供C++接口在unity中调 ...
- Tomcat双向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端超安全通信
紧接着<Tomcat单向Https验证搭建,亲自实现与主流浏览器.Android/iOS移动客户端安全通信>,此处演示下更安全的双向Https认证的通信机制,为了清晰明了,以下进行单独描述 ...
- Tomcat单向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端安全通信
众所周知,iOS9已经开始在联网方面默认强制使用Https替换原来的Http请求了,虽然Http和Https各有各的优势,但是总得来说,到了现在这个安全的信息时代,开发者已经离不开Https了. 网上 ...
- Unity 5.3.1 No Android/IOS module loaded
unity我一直在用5.0以下的版本 昨天升级到了最新版本5.3.1 发现无法打android包,ios也不行 提示“No Android/IOS module loaded” 下面有个Module ...
- Unity 发布到IOS,Android的各种坑
Unity 发布到IOS的注意事项1.开发环境MAC环境:Xcode环境 7.2.1Unity环境:Unity5.32.基本说明首先,我说一下,这是我在对Unity发布到IOS的实际使用中,总结出来的 ...
- unity 联机调试(android ios)
http://blog.csdn.net/OnafioO/article/details/44903491 (这种没用,只是在手机看到画面而已) 手机安装unityRemote并运行,unity中设置 ...
随机推荐
- MVC5中使用jQuery Post 二维数组和一维数组到Action
很久没有写了,最近在做一个MVC项目,这是我做的第一个MVC项目.之前可以说多MVC一点都不了解,今天把昨天遇到的一个问题记录下来.MVC大神就请飘过吧,跟我遇到同样问题的可以进来看看.遇到的第一个问 ...
- 【leetcode】Jump Game I, II 跳跃游戏一和二
题目: Jump Game I: Given an array of non-negative integers, you are initially positioned at the first ...
- SAM4E单片机之旅——5、LED呼吸和PWM
PWM在高频情况下,一个很好的用处就是通过控制占空比来控制输出的功率,比如控制风扇转速.LED灯的亮度等.这次就利用PWM的中断功能,动态改变脉冲的占空比,来实现呼吸灯的效果. 一.实现思路 PWM可 ...
- iframe调用父页面js函数 方法 元素
在一个页面中添加iframe,但是有时需要与父页面进行通信,传递参数. 网上总结有以下方法: 一.iframe标签中 src属性传参 <iframe src="test.jsp?i ...
- kong
https://docs.konghq.com/install/centos/ wget https://bintray.com/kong/kong-community-edition-rpm/dow ...
- Routine Subroutine Coroutine 子程序 协程
https://en.wikipedia.org/wiki/Subroutine In computer programming, a subroutine is a sequence of prog ...
- Error:Execution failed for task ':app:clean'. > Unable to delete directory: ***/app/build/generated/***
第一次从svn拉下来的工程,在clean的时候会出现 Error:Execution failed for task ':app:clean'. > Unable to delete direc ...
- Android 属性动画ObjectAnimator和ValueAnimator讲解
区别: ObjectAnimator 是直接对某个view进行更改. ValueAnimator 根据 TimeInterpolator 在不断产生相应的数据,来传进view ,view自己做改变. ...
- windows定时计划备份MySql
使用 MySql 的 mysqldump 将数据库文件备份成 sql 文件. Windows下备份 本地的数据库环境 MySql 安装环境:C:\MySql 数据库名称:bbs root root 数 ...
- 基于sys文件系统的LED驱动的移植【原创】
基于RK3188平台LED驱动程序的移植的移植.如有不正确之处,欢迎大家指点. 本文的LED驱动程序不是通过打开设备节点来访问和控制LED的,是通过sys文件系统来控制LED. 板子上有四盏灯以及对应 ...