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中设置 ...
随机推荐
- 在zend framework框架中try{}catch(Exception e){}的跳转问题
请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1 首先我先说明我遇到的问题 try{ //导入学生信息 $ModelStudent->insert($dat ...
- 九度OJ 1103:二次方程计算器 (解方程)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2804 解决:633 题目描述: 设计一个二次方程计算器 输入: 每个案例是关于x的一个二次方程表达式,为了简单,每个系数都是整数形式. 输 ...
- The JSP specification requires that an attribute name is preceded by whitespace--异常
异常信息:org.apache.jasper.JasperException: /pages/selectedCourse.jsp (line: 4, column: 39) The JSP spec ...
- java.lang.ClassNotFoundException: Didn't find class "org.reactivestreams.Publisher" on path
缺少jar包 reactive-streams-1.0.0.jar 和 reactive-streams-1.0.0-sources.jar 常用于 Rxjava 开发过程中 <?xml ...
- Whats the difference between service tomcat ./startup.sh and ./catalina.sh run
stack overflow 给出的答案: catalina.sh run starts tomcat in the foreground, displaying the logs on the co ...
- Python pip源,解决安装慢的问题
经常在使用Python的时候需要安装各种模块,而pip是很强大的模块安装工具,但是由于国外官方pypi经常被墙,导致不可用,所以我们最好是将自己使用的pip源更换一下,这样就能解决被墙导致的装不上库的 ...
- codeforces B. Multitasking 解题报告
题目链接:http://codeforces.com/problemset/problem/384/B 题目意思:给出n个数组,每个数组包括m个数字,当k = 0 时,需要把n个数组都按照从小到大的顺 ...
- coeforces 665D D. Simple Subset(最大团orsb题)
题目链接: D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Django中使用静态资源/文件
Django中常需要引用js,css,小图像文件,一般我们把这一类文件称为静态文件,放置在static文件夹中,接下来,对Django中配置静态文件进行下傻瓜式的步骤介绍 在工程目录下新建static ...
- Java 高阶 —— 相等性比较
1. 包装类 所有的相同类型的包装类对象之间的值的比较,全部使用 equals 方法: 对于 Integer a = ?,在 -128 到 127 范围内的赋值,Integer 对象是在 Intege ...