UE4与WEB-UI通信

前端HTML代码

	<!DOCTYPE html>
	<html>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1">
	    <title>test web ui</title>
	    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
	    <script type="text/javascript">
	        // WEB UI ~~ UE
	        "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),(window.ue4=ue.interface.broadcast);window.ue=ue;
	    </script>
	</head>
	<body>
	    <h1>测试WebUI与UE交互</h1>
	    <button id="btn">调用UE</button>
	
	    <script type="text/javascript">
	        // UE调用方法定义
	        ue.interface.ue2js = function(ueData){
	            alert(ueData)
	        }
	
	        $(function(){
	            $('#btn').on('click',function(){
	                // 调用UE方法
	                ue4('js2ue',{"name":"js to ue"})
	            })
	        })
	    </script>
	</body>
	</html>

UE4蓝图代码

在这里插入图片描述
点击页面的《调用UE》按钮后,UE的界面上会打印“js to ue”,同样,在UE侧点击按钮后,页面上会弹出含有「 {“name”:“jason”} 」的弹窗。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值