【UE4】 html中 ue4与 js数据互通

一 UE4中开启Web UI插件

1. 创建.html文件

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
    <button onclick = "bindTest()"> 绑定测试 </button>
	<button onclick = "callUE4Func()"> callUE4Func </button>
	<script>
	
	// create the global ue4(...) helper function
    // 帮助函数
	"object"!=typeof ue||"object"!=typeof ue.interface?("object"!=typeof ue&&(ue={}),ue.interface={},ue.interface.broadcast=function(e,t){if("string"==typeof e){var o=[e,""];void 0!==t&&(o[1]=t);var n=encodeURIComponent(JSON.stringify(o));"object"==typeof history&&"function"==typeof history.pushState?(history.pushState({},"","#"+n),history.pushState({},"","#"+encodeURIComponent("[]"))):(document.location.hash=n,document.location.hash=encodeURIComponent("[]"))}}):function(e){ue.interface={},ue.interface.broadcast=function(t,o){"string"==typeof t&&(void 0!==o?e.broadcast(t,JSON.stringify(o)):e.broadcast(t,""))}}(ue.interface),(ue4=ue.interface.broadcast);

    // 绑定测试
	function bindTest()
	{
		
		ue.testobject.bindtestfunction("helle bind").then(function(ReturnValue){
		alert("hello bind.  " + ReturnValue);
		});
	}
    // js调用UE4中函数
	function callUE4Func()
	{
		ue4("callUE4Func", "Param test");
		
		alert("callUE4Func.");
	}
    // UE4中调用js函数
	ue.interface.UE4CallFunc = function(Json)
	{
		alert("UE4CallFunc:  "+ Json);
	}
	
	</script>
</body>
</html>

2. 蓝图中创建UMG,添加Web Ui组件


绑定对应js调用UE4函数

UE4调用js函数

按钮调用函数 传入参数可为空

参考:

【UE4】在Html中用JS访问UE中对象数据_哔哩哔哩_bilibili

(72条消息) 【UE4】一个实现Web穿透,用HTML开发UI的方式——WebUI的用法_DvLee1024的博客-CSDN博客_unreal web

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值