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

相关推荐
ZhengEnCi21 分钟前
苹果滑动为什么有「肉感」:橡皮筋越界阻尼与弹簧动画的物理原理
前端
Moment28 分钟前
不会后期的我,发现了一个开源胶片神器😍😍😍
前端·后端·开源
L1mbo31 分钟前
Lite模式 缓解微信开发者工具卡顿,附 uni-app 实践方案
前端·微信小程序
FungLeo43 分钟前
成为全栈·Vue管理后台篇·仪表盘不是几张卡片:组合统计接口与角色视图
前端·javascript·vue.js·rbac·仪表盘·管理后台·tanstack query
SameX1 小时前
HarmonyOS 做桌面卡片 onAddForm 要同步返回但数据在数据库里的解法
前端
deli0071 小时前
手机夜景模式为什么要举 3 秒?8 帧 RAW 堆栈 SNR 实测
前端
松仔log1 小时前
Kotlin中级——callbackFlow
java·前端·kotlin
三小河1 小时前
SWC 凭什么比 Babel 快 ?项目优化迁移踩坑记录
前端·后端
再吃一根胡萝卜1 小时前
不改一行官方源码:用一个插件把 DeepSeek Harness 换成「平安one」
前端
涛涛ing2 小时前
2026年,你选的不再是框架,是渲染模型
前端