UnityRenderStreaming 使用UGUI

前言

自从UnityRenderStreaming 2.2.2开始,已经支持在Web页面中使用Unity UI 以下是使用教程


Unity官方已经有详细教程,不过还是有人不会用,就比如我!!但是我已经搞明白了

官方使用方法
https://docs.unity3d.com/Packages/com.unity.renderstreaming@2.2/manual/input.html

在这里插入图片描述
划重点!如果只是完成上面这一步,是可以在web页面实现点击ui的操作,但是Unity不能是在后台运行的状态,鼠标焦点要在Unity中,意味着你鼠标的焦点必须在运行的Unity项目中,用其它的电脑去访问web页面然后点击UI。

解决方法:
1.更新你的inputsystem包,在这里插入图片描述

2.在这里插入图片描述
3.创建一个脚本,内容在下面,替换原有的EventSystem 组件
在这里插入图片描述

using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;

public class CustomEventSystem : EventSystem
{
    protected override void Awake()
    {
        base.Awake();
        unsafe
        {
            InputSystem.onDeviceCommand += InputSystemOnDeviceCommand;
        }
    }

    private static unsafe long? InputSystemOnDeviceCommand(InputDevice device, InputDeviceCommand* command)
    {
        if (command->type != QueryCanRunInBackground.Type)
        {
            // return null is skip this evaluation
            return null;
        }

        ((QueryCanRunInBackground*)command)->canRunInBackground = true;
        return InputDeviceCommand.GenericSuccess;
    }

    protected override void OnApplicationFocus(bool hasFocus)
    {
        //Do not change focus flag on eventsystem
    }
}

在这里插入图片描述
替换前需要先删除下面的InputSystemUIModule,再删除Event System
替换上去脚本,再添加Standalone Input Mode,点击Replace…

4.以上操作已经能够实现,如果你是在Unity编辑器运行项目,还需要一步操作
Open Window->Analysis->Input Debugger and turn on Lock Input to Game View in Options.

完成使用UGUI的修改了!干活去了

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值