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);
        }
    }
}
相关推荐
zdr尽职尽责5 天前
UnityCli 兼容2022版本
ui·unity·ai·c#·游戏引擎
ellis19707 天前
Claude Code[二] 上下文相关的机制
unity·ai编程
zdr尽职尽责8 天前
Unity 3C 动画系统:从「蜘蛛网」到可维护的动画架构
unity·架构·游戏引擎
国家一级摸鱼选手9 天前
[Unity]几何碰撞检测:SAT 分离轴定理详解(从数学原理到 C# 实现)
unity·c#·游戏引擎·分离轴定理(sat)·多边形相交
暴走约伯10 天前
【VFX工具链源码拆解 09】终极工业化闭环:基于 ID 规则驱动的全自动场景建档、骨骼挂载与男转女场景迁移
unity·c#·游戏引擎·材质
寂寞的船11 天前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
寂寞的船12 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
探求虚无13 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
17岁的勇气14 天前
Unity Shader unity文档学习笔记(二十二):shader变体
笔记·学习·unity
寂寞的船15 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene