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

相关推荐
2601_963771371 小时前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
蓝银草同学1 小时前
Stream 实战:博客列表排序、过滤与分页(AI 辅助学习 Java 8)
java·前端·后端
2601_957190901 小时前
飞行影院安装施工指南:场地、动感系统与影片内容配套
大数据·前端·人工智能
爱折腾的小黑牛1 小时前
简记往来批量录入功能的实现:从文本到结构化数据
前端·算法
YHHLAI1 小时前
Agent 智能体开发实战 · 第六课:MCP 协议 —— 让 Agent 跨进程调用工具
前端·人工智能
SmartBoyW1 小时前
前端死磕:一文彻底搞懂 JS 事件循环 (Event Loop) 与宏微任务
前端·javascript
爱勇宝2 小时前
3位工程师靠“删AI代码”创业,一周收费1万美元:以后最贵的能力,可能不是写代码
前端·后端·架构
Curvatureflight2 小时前
客户端日志上报怎么设计?让线上问题不再只靠用户截图
前端·系统架构
不法2 小时前
uniapp map地图导航/地图路线
前端·vue.js·uni-app