UE与JS通信


一、JS调用UE

1.前端代码

  <script>
  //第一步:定义帮助函数 可直接复制
   "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);

    // js调用ue4, 参数1:函数名 参数2:json数据对象
    // 该调用可根据具体需求写在对应位置,此处为测试 
    ue4('JScallUE4', { name: 'xiaoli' });

  </script>

2.UE实现

新建控件蓝图,在变量处新建变量,类型为webinterferce
在这里插入图片描述
UE蓝图如图
在这里插入图片描述
在这里插入图片描述

二、UE调用JS

1.前端代码

代码如下(示例):

<script>
  //第一步:定义帮助函数 可直接复制
   "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);

    // 定义UE可调用的函数UE4CallJS
    // 该调用可根据具体需求写在对应位置,此处为测试 
    ue.interface.UE4CallJS = function (Json) {
		document.getElementById('visual').style.display = "";
	};
	ue.interface.Invisible = function (Json) {
		document.getElementById('visual').style.display = "none";
	};

  </script>

2.UE实现

  • 新建控件蓝图,名字为web,在画布面板添加WebInterface
    在这里插入图片描述

  • 新建HUD类,父类为InterfaceHUD

  • 在HUD类新建变量,变量类型为web
    代码如下(示例):
    在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大田斗小木子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值