Unity VRTK4+SteamVR传送组件使用和层级关系

头盔整体

传送

被抓取物体:

UI 交互

GitHub - studentutu/Tilia.UnityUI: Tilia package for VRTK 4 featuring support for Unity UI. Ported from VRTK 3.3.0 with additional fixes. Can be used with both old and new input module. Dependency on https://www.vrtk.io/tilia.html

输入,代码示例

csharp 复制代码
using Valve.VR;
using Zinnia.Action;

/*
 * Description: 
 * Author:      #AUTHOR#
 * CreateTime:  #CREATETIME#
*/

public class SteamToZinniaBoolAction : BooleanAction
{
    public SteamVR_Action_Boolean steamVRAction;
    public SteamVR_Input_Sources inputSource = SteamVR_Input_Sources.Any;

    protected override void OnEnable()
    {
        base.OnEnable();
        // OnChange 在"按下"和"松开"都会回调,newState = true/false
        steamVRAction?.AddOnChangeListener(OnChange, inputSource);
    }

    protected override void OnDisable()
    {
        base.OnDisable();
        steamVRAction?.RemoveOnChangeListener(OnChange, inputSource);
    }

    private void OnChange(SteamVR_Action_Boolean fromAction,
                          SteamVR_Input_Sources fromSource,
                          bool newState)
    {
        Receive(newState);
    }
}
csharp 复制代码
using UnityEngine;
using Valve.VR;
using Zinnia.Action;

public class Vector2ToFloatAction : FloatAction
{
    public enum AxisType
    {
        Horizontal,
        Vertical
    }

    public SteamVR_Action_Vector2 moveAction;
    public SteamVR_Input_Sources inputSource = SteamVR_Input_Sources.RightHand;
    public AxisType axisType = AxisType.Horizontal;
    public float mulltiplier = 1.0f;

    protected virtual void Update()
    {
        if (moveAction != null)
        {
            Vector2 axis = moveAction.GetAxis(inputSource);

            float value = axisType == AxisType.Horizontal ? axis.x : axis.y;

            // 设置 FloatAction 的接收值
            Receive(value * mulltiplier);
        }
    }
}
相关推荐
WiChP15 分钟前
【V0.1B15】从零开始的2D游戏引擎开发之路
游戏引擎
zhchyun20081 天前
# 【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(06)
ui·unity·游戏引擎
Behaviour2 天前
Unity游戏HybridCLR 热更新接入实战
游戏·unity·游戏引擎
LONGZETECH2 天前
新能源汽车动力电池实训教学痛点与虚拟仿真技术解决方案
c语言·3d·unity·架构·汽车·汽车教学软件
王维志2 天前
UiSplineRenderer
unity·游戏引擎
k4m7v2pz2 天前
Godot 4 仿 agar.io:相机缩放被 max_zoom 卡死,窗口越大球越小的根因与修复
游戏引擎·godot·相机·缩放·clamp·camera2d
FairGuard手游加固2 天前
iOS 游戏加固技术解析:代码混淆、资源加密、内存保护与重签名检测
安全·游戏·macos·unity·ios·objective-c
k4m7v2pz3 天前
Godot 4 窗口拉伸黑边与变形:stretch 配置全解析
数码相机·游戏引擎·godot·2d游戏·黑边·stretch·画面比例
UWA3 天前
GPM 2.0 WebGL 监测能力扩容|覆盖 Unity/Cocos/LayaAir 多引擎微信 & 抖音小游戏
unity·微信·性能优化·小游戏·webgl
Behaviour4 天前
Unity 手游网络同步技术
网络·unity·c#·游戏引擎