UE5.4像素流及前端接入

打印 上一主题 下一主题

主题 913|帖子 913|积分 2739

在ue5.2之后,ue像素流的源码放入到Github仓库中,由社区维护。
像素流送Github
https://github.com/EpicGames/PixelStreamingInfrastructure/tree/master/Frontend
创建一个虚幻项目

使用虚幻引擎5.2以上创建一个初始项目
 

创建项目后打开Pixel Streaming插件,重启项目

项目创建完成。
创建并启动Vue项目

创建项目

默认电脑已安装node.js与Vue脚手架
  1. npm install -g @vue/cil
复制代码
在Vscode大概下令行输入
  1. vue create test_vue
复制代码
test_vue为项目名称
创建完成

启动项目

在下令行进入到项目地点文件夹

使用npm run 查看可运行下令

使用
  1. npm run serve
复制代码
成功启动后


引入相干的依靠库

在ue的5.2之后,像素流集成不再引入相干文件,换成使用npm引入相干的依靠。与正常的Vue引入依靠流程一致。
  1. npm install @epicgames-ps/lib-pixelstreamingfrontend-ue5.2
  2. npm install @epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2
复制代码
背面的5.2为引擎版本,引入与引擎对应的版本,否则可能有未知错误。
新建vue文件


在components文件夹下创建新的Vue文件

在文件中输入下方的代码
  1. <template>
  2.     <div>
  3.       <!-- 页面内容 -->
  4.     </div>
  5. </template>
  6.   
  7.   <script>
  8. import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
  9. import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';
  10. export default {
  11.     name: 'PlayerView',
  12.     mounted() {
  13.       const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
  14.       PixelStreamingApplicationStyles.applyStyleSheet();
  15.   
  16.       // Example of how to set the logger level
  17.       // Logger.SetLoggerVerbosity(10);
  18.   
  19.       // Create a config object
  20.       const config = new Config({ useUrlParams: true });
  21.   
  22.       // Create a Native DOM delegate instance that implements the Delegate interface class
  23.       const stream = new PixelStreaming(config);
  24.       const application = new Application({
  25.         stream,
  26.         onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
  27.       });
  28.   
  29.       document.body.appendChild(application.rootElement);
  30.     },
  31.     methods: {
  32.       // ...
  33.     }
  34. }
  35. </script>
  36.   
  37. <style>
  38. body {
  39.     width: 100vw;
  40.     height: 100vh;
  41.     min-height: -webkit-fill-available;
  42.     font-family: 'Montserrat';
  43.     margin: 0;
  44. }
  45. </style>
复制代码
在App.vue中引入新的页面并把初始页面注释,此中PlayerView为在页面界说的模块名称
  1. <template>
  2.     <div>
  3.       <!-- 页面内容 -->
  4.     </div>
  5. </template>
  6.   
  7.   <script>
  8. import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
  9. import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';
  10. export default {
  11.     name: 'PlayerView',
  12.     mounted() {
  13.       const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
  14.       PixelStreamingApplicationStyles.applyStyleSheet();
  15.   
  16.       // Example of how to set the logger level
  17.       // Logger.SetLoggerVerbosity(10);
  18.   
  19.       // Create a config object
  20.       const config = new Config({ useUrlParams: true });
  21.   
  22.       // Create a Native DOM delegate instance that implements the Delegate interface class
  23.       const stream = new PixelStreaming(config);
  24.       const application = new Application({
  25.         stream,
  26.         onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
  27.       });
  28.   
  29.       document.body.appendChild(application.rootElement);
  30.     },
  31.     methods: {
  32.       // ...
  33.     }
  34. }
  35. </script>
  36.   
  37. <style>
  38. body {
  39.     width: 100vw;
  40.     height: 100vh;
  41.     min-height: -webkit-fill-available;
  42.     font-family: 'Montserrat';
  43.     margin: 0;
  44. }
  45. </style>
复制代码
之后启动项目会看到下面页面

启动像素流

虚幻启动像素流

在编辑器的像素流送选项下点击启动信令服务器,流送关卡编辑器就流送完整编辑器

前端修改地点


点击前端的设置,修改流送地点(上图的红色框中),之后链接就会看到画面

到此前端引入像素流完成。
前端与UE通讯

UE蓝图

在虚幻引擎的玩家控制器引入PixStreamingInput组件

向前端发送消息


接受前端的消息


前端代码

在前端创建变量,袒露stream对象,它内里就有我们的通讯函数
  1. <template>
  2.     <div>
  3.       <!-- 页面内容 -->
  4.       <button @click="SendMesage">发送消息</button>
  5.     </div>
  6. </template>
  7.   
  8.   <script>
  9. import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
  10. import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';
  11. export default {
  12.     name: 'PlayerView',
  13. data(){
  14.     return{
  15.         s:null
  16.     }
  17. },
  18.     mounted() {
  19.       const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
  20.       PixelStreamingApplicationStyles.applyStyleSheet();
  21.   
  22.       // Example of how to set the logger level
  23.       // Logger.SetLoggerVerbosity(10);
  24.   
  25.       // Create a config object
  26.       const config = new Config({ useUrlParams: true });
  27.   
  28.       // Create a Native DOM delegate instance that implements the Delegate interface class
  29.       const stream = new PixelStreaming(config);
  30.       this.s = stream;
  31.       
  32.       const application = new Application({
  33.         stream,
  34.         onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
  35.       });
  36.   
  37.       document.body.appendChild(application.rootElement);
  38.       stream.addEventListener("handle_responses",this.HandleResponse)
  39.       
  40.     },
  41.     methods: {
  42.       // ...
  43.       SendMesage:function() {
  44.         console.log(this.s);
  45.         this.s.emitUIInteraction("111");
  46.       },
  47.       HandleResponse:function(res){
  48.         console.log(res)
  49.       }
  50.     }
  51. }
  52. </script>
  53.   
  54. <style>
  55. body {
  56.     width: 100vw;
  57.     height: 100vh;
  58.     min-height: -webkit-fill-available;
  59.     font-family: 'Montserrat';
  60.     margin: 0;
  61. }
  62. </style>
复制代码

至此就可以实现UE与前端的双端通讯。
留意,通讯不可以是流送编辑器,必须是打包大概以独立线程能运行才可以。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

西河刘卡车医

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表