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);
        }
    }
}
相关推荐
玖玥拾2 天前
C# 语言进阶(十四)Unity UI界面开发 + 网络消息联动
服务器·开发语言·网络·ui·unity·c#·游戏引擎
野区捕龙为宠2 天前
Unity 持久化数据
unity·游戏引擎·lucene
郝学胜-神的一滴2 天前
[简化版 GAMES 101] 计算机图形学 17:纹理技术从基础原理到多场景实战应用
c++·unity·游戏引擎·图形渲染·three.js·opengl·unreal
_ZHOURUI_H_3 天前
MyFramework: 同样是 Unity 游戏开发框架,和 HTFramework 的设计取向有什么不同?(下)
unity·游戏引擎·游戏开发·游戏ui·手游开发
小贺儿开发4 天前
Unity 知识库智能问答系统(RAG)
人工智能·unity·ai·大模型·智能问答·知识库·互动
丁小未4 天前
基于MVVM框架的XUUI 扩展的UI管理系统教程
unity·mvvm·ui框架·xuui·ui管理器
丁小未5 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
丁小未5 天前
基于MVVM框架的XUUI MoreComplex案例
unity·c#
EQ-雪梨蛋花汤5 天前
【Unity笔记】VR 一体机画面锯齿、模型边缘闪烁、接缝抖动排查:MSAA、Mipmap、Render Scale、Z-Fighting 全流程记录
笔记·unity·vr
松树戈5 天前
【Godot4精进之路】03~Godot编辑器常用界面介绍
编辑器·游戏引擎·godot