steamVR设备交互

内容来自官方,翻译方便理解使用

官方插件SteamVR Plugin

插件示例场景文件位置

交互的核心脚本是 Interactable

 一、人物移动

添加Teleporting预制体后,按下手柄的圆盘才能显示移动光线,此时缺少移动地板所以射线红色。

 创建一个plane并添加Teleport Area脚本,此时射线绿色表示能移动。

按压手柄圆盘,会出现绿色的移动线,松开圆盘,会移动到对应的位置。

 

 修改Arc Distance值,可以改变手柄移动射线弧的长度。

二、简单交互

 拾取对象简易模版

//======= Copyright (c) Valve Corporation, All rights reserved. ===============
//
// Purpose: 交互模板
//
//=============================================================================

using UnityEngine;
using System.Collections;

namespace Valve.VR.InteractionSystem.Sample
{
    //-------------------------------------------------------------------------
    [RequireComponent(typeof(Interactable))]
    public class InteractableTemplate : MonoBehaviour
    {
        private Vector3 oldPosition;
        private Quaternion oldRotation;

        private Hand.AttachmentFlags attachmentFlags = Hand.defaultAttachmentFlags & (~Hand.AttachmentFlags.SnapOnAttach) & (~Hand.AttachmentFlags.DetachOthers) & (~Hand.AttachmentFlags.VelocityMovement);

        private Interactable interactable;

        //-------------------------------------------------
        void Awake()
        {
            interactable = this.GetComponent<Interactable>();
        }


        //-------------------------------------------------
        //当手开始悬停在这个对象上时调用
        //-------------------------------------------------
        private void OnHandHoverBegin(Hand hand)
        {

        }


        //-------------------------------------------------
        // 当手停止悬停在此对象上时调用
        //-------------------------------------------------
        private void OnHandHoverEnd(Hand hand)
        {

        }


        //-------------------------------------------------
        // 当一只手悬停在这个对象上时,每次调用Update()
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool isGrabEnding = hand.IsGrabEnding(this.gameObject);

            if (interactable.attachedToHand == null && startingGrabType != GrabTypes.None)
            {
                // 保存我们的位置/旋转,以便我们可以在分离时恢复它
                oldPosition = transform.position;
                oldRotation = transform.rotation;

                // 调用这个来继续接收HandHoverUpdate消息,并防止手悬停在其他任何东西上
                hand.HoverLock(interactable);

                // 把这个东西固定在手上
                hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
            }
            else if (isGrabEnding)
            {
                // 把这个东西从手上拆下来
                hand.DetachObject(gameObject);

                // 调用此命令撤消HoverLock
                hand.HoverUnlock(interactable);

                // 恢复位置/旋转
                transform.position = oldPosition;
                transform.rotation = oldRotation;
            }
        }


        //-------------------------------------------------
        // 当GameObject附在手上时调用
        //-------------------------------------------------
        private void OnAttachedToHand(Hand hand)
        {

        }



        //-------------------------------------------------
        // 当GameObject从手上分离时调用
        //-------------------------------------------------
        private void OnDetachedFromHand(Hand hand)
        {

        }


        //-------------------------------------------------
        // 当GameObject附着在手上时,每次调用Update()
        //-------------------------------------------------
        private void HandAttachedUpdate(Hand hand)
        {

        }

        private void Update()
        {

        }


        //-------------------------------------------------
        // 当附加的GameObject成为主要附加对象时调用
        //-------------------------------------------------
        private void OnHandFocusAcquired(Hand hand)
        {

        }


        //-------------------------------------------------
        // 当另一个附加游戏对象成为主要附加对象时调用
        //-------------------------------------------------
        private void OnHandFocusLost(Hand hand)
        {

        }
    }
}

三、投掷

四、线性驱动

五、环形驱动

六、悬浮按钮

七、射箭

八、遥控

猜你喜欢

转载自blog.csdn.net/m0_73841296/article/details/131639331