admin管理员组文章数量:1026989
1.自带浏览器
这个比较简单,直接调用unity官方的API即可,会直接使用默认浏览器打开网页,这里就不多做解释了。
代码
public InputField input;
private void OpenUrlByUnity()
{
string inputStr = input.text;
if (!string.IsNullOrEmpty(inputStr))
Application.OpenURL(inputStr);
}
2.内嵌浏览器(不跳出APP)
该方案是使用unity store里的插件实现的。插件链接
使用该插件不会切出APP。
示例效果
注意此时是没有切出游戏的。
测试代码
public InputField input;
public CanvasWebViewPrefab webPrefab;
private async void OpenUrlByWeb()
{
if (webPrefab != null)
{
webPrefab.gameObject.SetActive(true);
string inputStr = input.text;
if (!string.IsNullOrEmpty(inputStr))
{
await webPrefab.WaitUntilInitialized();
webPrefab.WebView.LoadUrl(inputStr);
}
}
}
实现具体需求参考插件文档即可,还是蛮详细的。
1.自带浏览器
这个比较简单,直接调用unity官方的API即可,会直接使用默认浏览器打开网页,这里就不多做解释了。
代码
public InputField input;
private void OpenUrlByUnity()
{
string inputStr = input.text;
if (!string.IsNullOrEmpty(inputStr))
Application.OpenURL(inputStr);
}
2.内嵌浏览器(不跳出APP)
该方案是使用unity store里的插件实现的。插件链接
使用该插件不会切出APP。
示例效果
注意此时是没有切出游戏的。
测试代码
public InputField input;
public CanvasWebViewPrefab webPrefab;
private async void OpenUrlByWeb()
{
if (webPrefab != null)
{
webPrefab.gameObject.SetActive(true);
string inputStr = input.text;
if (!string.IsNullOrEmpty(inputStr))
{
await webPrefab.WaitUntilInitialized();
webPrefab.WebView.LoadUrl(inputStr);
}
}
}
实现具体需求参考插件文档即可,还是蛮详细的。
版权声明:本文标题:Unity内打开网页的两种方式(自带浏览器、内嵌浏览器) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/jiaocheng/1737920300a1521238.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论