Unity InputAction使用中遇到的坑

今天发现一个问题,同事写的一个类继承自TrackedPoseDriver,打包运行后手部追踪位置无法追踪。
在这里插入图片描述
这里有两个手的Action引用。
我们整个项目有一个启用和关闭的控制,所以开始查了项目的开关,发现也都是开的。

经过折腾发现他的这个脚本是打包成AB发布的,所以他就不受控制了,需要单独enable。

干脆改掉算了,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.XR;

public class TrackedPoseDriverExtended : TrackedPoseDriver
{
    public HandEnum handEnum;
    [HideInInspector]
    public Vector3 tempVector3 = Vector3.zero;
    [HideInInspector]
    public Quaternion tempQuaternion = Quaternion.identity;

    protected override void Awake()
    {

        base.Awake();
        if (InputManager.inst == null || InputManager.inst.inputAction == null)
        {
            return;
        }
        //这里自己指向引用,因为这个脚本是在ab包里,如果不这样指向,ab包是单独的Action,会导致没enable
        if (handEnum == HandEnum.Left)
        {
            positionInput = new InputActionProperty(InputManager.inst.inputAction.Player.HandPos_Left);
            rotationInput = new InputActionProperty(InputManager.inst.inputAction.Player.HandRot_Left);
        }
        else
        {
            positionInput = new InputActionProperty(InputManager.inst.inputAction.Player.HandPos_Right);
            rotationInput = new InputActionProperty(InputManager.inst.inputAction.Player.HandRot_Right);
        }

    }
    protected override void SetLocalTransform(Vector3 newPosition, Quaternion newRotation)
    {
        //Debug.Log($"22222222222 :{positionInput.action.enabled}, {newPosition}, {newRotation}");
        newPosition = tempQuaternion * (tempVector3 + newPosition);
        newRotation = tempQuaternion * newRotation;

        base.SetLocalTransform(newPosition, newRotation);
    }
}

这样就使用我的InputAction管理类统一了。

这真的是巨大一个坑,查了很久,放上来有相同问题的希望能看到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thinbug

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值