UE4与WEB-UI通信

前端HTML代码

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"} 」的弹窗。

相关推荐
OEC小胖胖3 小时前
去中心化身份:2025年Web3身份验证系统开发实践
前端·web3·去中心化·区块链
vvilkim4 小时前
Electron 进程间通信(IPC)深度优化指南
前端·javascript·electron
ai小鬼头5 小时前
百度秒搭发布:无代码编程如何让普通人轻松打造AI应用?
前端·后端·github
漂流瓶jz5 小时前
清除浮动/避开margin折叠:前端CSS中BFC的特点与限制
前端·css·面试
前端 贾公子5 小时前
在移动端使用 Tailwind CSS (uniapp)
前端·uni-app
散步去海边6 小时前
Cursor 进阶使用教程
前端·ai编程·cursor
清幽竹客6 小时前
vue-30(理解 Nuxt.js 目录结构)
前端·javascript·vue.js
weiweiweb8886 小时前
cesium加载Draco几何压缩数据
前端·javascript·vue.js
幼儿园技术家6 小时前
微信小店与微信小程序简单集成指南
前端
我不吃饼干9 天前
鸽了六年的某大厂面试题:你会手写一个模板引擎吗?
前端·javascript·面试