- 在Unity创建一个3D Core工程PicoWebShell
- 下载Unity WebView插件(它的sample工程好像不能正常运行):https://github.com/gree/unity-webview
- 双击导入dist/unity-webview.unitypackage
- 创建一个空对象
- 在Assets目录里创建下面WebShell.cs文件,然后拖到空对象
- 点播放即可
using UnityEngine;
using Gree.UnityWebView;
public class WebShell : MonoBehaviour
{
private WebViewObject webView;
void Start()
{
// 创建WebView
webView = gameObject.AddComponent<WebViewObject>();
// 初始化
webView.Init((msg) =>
{
Debug.Log("Web消息: " + msg);
});
// 设置网页显示位置(全屏)
webView.SetMargins(0, 0, 0, 0);
// 启动网页
webView.LoadURL("https://。。。");
// 显示出来
webView.SetVisibility(true);
Debug.Log("✅ WebView 启动成功!");
}
}
评论