UE5.4像素流及前端接入

在ue5.2之后,ue像素流的源码放入到Github仓库中,由社区维护。

像素流送Githubicon-default.png?t=O83Ahttps://github.com/EpicGames/PixelStreamingInfrastructure/tree/master/Frontend

创建一个虚幻项目

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

 

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

项目创建完成。

创建并启动Vue项目

创建项目

默认电脑已安装node.js与Vue脚手架

npm install -g @vue/cil

在Vscode或者命令行输入

vue create test_vue

test_vue为项目名称

创建完成

启动项目

在命令行进入到项目所在文件夹

使用npm run 查看可运行命令

使用

npm run serve

成功启动后

引入相关的依赖库

在ue的5.2之后,像素流集成不再引入相关文件,换成使用npm引入相关的依赖。与正常的Vue引入依赖流程一致。

npm install @epicgames-ps/lib-pixelstreamingfrontend-ue5.2
npm install @epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2

后面的5.2为引擎版本,引入与引擎对应的版本,否则可能有未知错误。

新建vue文件

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

在文件中输入下方的代码

<template>
    <div>
      <!-- 页面内容 -->
    </div>
</template>
  
  <script>
import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';


export default {
    name: 'PlayerView',
    mounted() {
      const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
      PixelStreamingApplicationStyles.applyStyleSheet();
  
      // Example of how to set the logger level
      // Logger.SetLoggerVerbosity(10);
  
      // Create a config object
      const config = new Config({ useUrlParams: true });
  
      // Create a Native DOM delegate instance that implements the Delegate interface class
      const stream = new PixelStreaming(config);
      const application = new Application({
        stream,
        onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
      });
  
      document.body.appendChild(application.rootElement);
    },
    methods: {
      // ...
    }
}
</script>
  
<style>
body {
    width: 100vw;
    height: 100vh;
    min-height: -webkit-fill-available;
    font-family: 'Montserrat';
    margin: 0;
}
</style>

在App.vue中引入新的页面并把初始页面注释,其中PlayerView为在页面定义的模块名称

<template>
    <div>
      <!-- 页面内容 -->
    </div>
</template>
  
  <script>
import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';


export default {
    name: 'PlayerView',
    mounted() {
      const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
      PixelStreamingApplicationStyles.applyStyleSheet();
  
      // Example of how to set the logger level
      // Logger.SetLoggerVerbosity(10);
  
      // Create a config object
      const config = new Config({ useUrlParams: true });
  
      // Create a Native DOM delegate instance that implements the Delegate interface class
      const stream = new PixelStreaming(config);
      const application = new Application({
        stream,
        onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
      });
  
      document.body.appendChild(application.rootElement);
    },
    methods: {
      // ...
    }
}
</script>
  
<style>
body {
    width: 100vw;
    height: 100vh;
    min-height: -webkit-fill-available;
    font-family: 'Montserrat';
    margin: 0;
}
</style>

之后启动项目会看到下面页面

启动像素流

虚幻启动像素流

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

前端修改地址

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

到此前端引入像素流完成。

前端与UE通信

UE蓝图

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

向前端发送消息

接受前端的消息

前端代码

在前端创建变量,暴露stream对象,它里面就有我们的通讯函数

<template>
    <div>
      <!-- 页面内容 -->
      <button @click="SendMesage">发送消息</button>
    </div>
</template>
  
  <script>
import { Config, PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.2';
import { Application, PixelStreamingApplicationStyle } from '@epicgames-ps/lib-pixelstreamingfrontend-ui-ue5.2';




export default {
    name: 'PlayerView',
data(){
    return{
        s:null
    }
},
    mounted() {
      const PixelStreamingApplicationStyles = new PixelStreamingApplicationStyle();
      PixelStreamingApplicationStyles.applyStyleSheet();
  
      // Example of how to set the logger level
      // Logger.SetLoggerVerbosity(10);
  
      // Create a config object
      const config = new Config({ useUrlParams: true });
  
      // Create a Native DOM delegate instance that implements the Delegate interface class
      const stream = new PixelStreaming(config);
      this.s = stream;
      
      const application = new Application({
        stream,
        onColorModeChanged: (isLightMode) => PixelStreamingApplicationStyles.setColorMode(isLightMode)
      });
  
      document.body.appendChild(application.rootElement);
      stream.addEventListener("handle_responses",this.HandleResponse)
      
    },
    methods: {
      // ...
      SendMesage:function() {
        console.log(this.s);
        this.s.emitUIInteraction("111");
      },
      HandleResponse:function(res){
        console.log(res)
      }
    }
}
</script>
  
<style>
body {
    width: 100vw;
    height: 100vh;
    min-height: -webkit-fill-available;
    font-family: 'Montserrat';
    margin: 0;
}
</style>

至此就可以实现UE与前端的双端通信。

注意,通讯不可以是流送编辑器,必须是打包或者以独立线程能运行才可以。

### UE5.4 中实现像素流并正确显示鼠标的解决方案 在 Unreal Engine 5.4 (UE5.4) 中,要实现在像素流应用中正确显示鼠标指针的功能,通常涉及几个方面的配置和调整。 #### 启用 Pixel Streaming 插件 为了使用像素流功能,必须先启用 `Pixel Streaming` 插件。这可以通过编辑器中的插件管理器完成,确保该插件处于激活状态[^2]。 ```cpp // 在项目设置中启用 Pixel Streaming 插件 Plugins -> Add Plugin from Marketplace -> Search for "Pixel Streaming" ``` #### 配置 WebRTC 设置 对于浏览器端的像素流传输,WebRTC 是核心组件之一。需要确认服务器端已安装必要的依赖项,并按照官方文档进行了适当配置。 #### 修改输入映射 为了让鼠标事件正常工作,可能需要自定义项目的输入映射(Input Mapping),特别是针对触摸屏设备或者当应用程序作为网页运行时。可以在 `Project Settings -> Input` 下找到相应的选项进行修改。 #### 调整视口参数 有时,默认情况下虚拟摄像机捕捉到的画面不包含光标图像。此时应该检查视口(Viewport)的相关属性设定,比如是否启用了渲染鼠标(`Render Mouse Cursor`)等功能。 ```json { "r.Streaming.RenderMouseCursor": true, } ``` 上述 JSON 片段展示了如何通过命令行参数来强制使能远程会话期间的鼠标游标渲染。此配置应放置于 `.ini` 文件内的 `[SystemSettings]` 或者其他合适的位置。 #### 处理跨域资源共享(CORS) 如果遇到因安全策略而导致无法加载资源的问题,则需确保后端服务允许来自前端页面所在域名的请求访问所需文件(如纹理贴图)。可通过调整 HTTP 响应头解决此类问题。 ```bash Access-Control-Allow-Origin: * ``` 以上措施有助于改善基于 UE5.4像素流环境中鼠标的可见性和响应行为。值得注意的是,具体实施细节可能会依据实际应用场景有所差异,因此建议参照最新版本的手册获取最权威的信息指引。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值