目录
内嵌网页:
1、unity工程导入 ZFBrowser插件 :插件下载链接(待上传)
2、在Hierarchy创建一个 Canvas-gameobject
3、给空物体添加 PointerUIGUI 脚本,会自动添加两个组件
4、把前端写好的页面放到与Assets同级目录下BrowserAssets文件夹内
在browser脚本Url处写入localGame://xxxxxx.html
运行即可。
与前端通信:
前端代码(测试)
在html里面写function
然后写个button给button注册该方法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试实例</title>
<script>
function TestAgain()
{
}
</script>
</head>
<button type="button" onclick="TestAgain()" >这是一个按钮</button>
<body>
</body>
</html>
unity代码(测试)
将此脚本挂在刚刚创建的空物体上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZenFulcrum.EmbeddedBrowser;
public class Main : MonoBehaviour
{
private Browser m_htmlPanel;
void Start()
{
m_htmlPanel = GetComponent<Browser>();
m_htmlPanel.RegisterFunction("TestAgain", TestAgain);//RegisterFunction(前端方法名,unity方法名)
}
public void TestAgain(JSONNode args)
{
Debug.Log("通信成功");
}
void Update()
{
}
}
运行测试