RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Unity中如何内嵌网页插件UniWebView

这篇文章给大家分享的是有关Unity中如何内嵌网页插件UniWebView的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

成都创新互联是专业的水富网站建设公司,水富接单;提供成都网站建设、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行水富网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

一、常见Unity中内嵌网页实现方式:

1、UnityWebCore只支持windows

2、Unity-Webview支持Android,IOS

3、UniWebView支持mac os,Android,IOS,WP8(2.0以后)

二、UniWebView 根据手机平台调用相应的WebView组件来显示网页,支持和javascript的交互,不支持windows和editor上显示。

1、下载并导入unitypackage

http://uniwebview.onevcat.com/

2、设置Webview,加载并显示网页

// Find the UniWebView component on the gameObject.
// It is supposed you have already dragged this script to the same gameObject which UniWebView on.
// Or you will get a null exception :(
_webView = GetComponent();
 
// Listen to some event of UniWebView
_webView.OnLoadComplete += OnLoadComplete;
_webView.OnReceivedMessage += OnReceivedMessage;
_webView.OnEvalJavaScriptFinished += OnEvalJavaScriptFinished;
// Almost full screen but 5 points gap in each edge.
_webView.insets = new UniWebViewEdgeInsets(5,5,5,5);
// Set a url string to load
_webView.url = "http://uniwebview.onevcat.com/demo/index.html";
// Tell the web view begin to load the url just set.
_webView.Load();
 
// Then wait for the OnLoadComplete event
 
//...
 
// The listening method of OnLoadComplete method.
void OnLoadComplete(UniWebView webView, bool success, string errorMessage) {
  if (success) {
    // Great, everything goes well. Show the web view now.
    webView.Show();
  } else {
    // Oops, something wrong.
    Debug.LogError("Something wrong in web view loading: " + errorMessage);
  }
}

3、网址解析

uniwebview://move?direction=up&distance=1会解析成

path = "move"
args = {
    direction = "up",
    distance = "1"
}

4、监听消息

void OnReceivedMessage(UniWebView webView, UniWebViewMessage message) {
   Debug.Log(message.rawMessage);
   if (string.Equals(message.path, "move")) {
      // It is time to move!
 
      // In this example:
      // message.args["direction"] = "up"
      // message.args["distance"] = "1"
   }
}

感谢各位的阅读!关于“Unity中如何内嵌网页插件UniWebView”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


文章标题:Unity中如何内嵌网页插件UniWebView
URL地址:http://cqwzjz.cn/article/pspdhc.html