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);
        }
    }
}
相关推荐
小贺儿开发11 小时前
Unity 家居视频遥控(细节优化)
科技·unity·程序员·udp·视频·工具·通信
淡海水12 小时前
13-04-面试-源码级深度追问链
数据结构·unity·面试·c#·游戏引擎·源码·il2cpp
小小数媒成员1 天前
UGUI 性能优化(详细,全,深入)
开发语言·unity·游戏引擎
林川~012 天前
Unity新输入系统使用笔记
unity·input system
小贺儿开发2 天前
Unity 结合百度AI开放平台 手写文字识别
人工智能·科技·学习·unity·云服务·文字识别·手写文字
goujunwe2 天前
GEO 评估方法:如何自测你的内容,会不会被 AI 引用
搜索引擎·网络安全·游戏引擎·全文检索·中文分词
林川~012 天前
Unity 万能物理检测工具:射线检测 / 范围检测 / 层级过滤 / 编辑器可视化(可直接拿去用)
游戏·unity·c#·射线检测·通用工具
yi碗汤园3 天前
MQTT消息队列遥测传输协议
网络·网络协议·unity
林川~013 天前
Unity 常用 API 与核心类全解:从生命周期到协程,附性能避坑清单(Unity 6 适配)
unity·游戏引擎·常用api
sensen_kiss3 天前
CPT306 Coursework 1 个人游戏作业——坦克大战
unity·游戏程序·游戏策划