Hi Everyone,
I have been working on a steam VR game, and I ran into an issue. I am creating a custom key bind for the HTC Vive control to hand the UP, DOWN, LEFT, and RIGHT press on the control pad.
Everything works fine in the Unity Editor however whenever I build the project, the default controls work (such as teleport, grip, etc), but the custom controls do not work.
I tried two different methods to get everything to work. Both work in the editor, but neither work whenever I build the project.
I highlighted the area that accesses the custom bindings in Red. If anyone has a suggestion, I’d appreciate it.
Thanks,
-Gabe
Here is the current bit of code I wrote for the object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public enum controlPressType { Grip, Pinch, Up, Down, Left, Right };
namespace Valve.VR.InteractionSystem.Sample
{
[RequireComponent(typeof(Interactable))]
public class interactiveObject : MonoBehaviour
{
public SteamVR_Input_Sources thisHand;
Interactable interactable;
[EnumFlags]
[Tooltip(“The flags used to attach this object to the hand.”)]
public Hand.AttachmentFlags attachmentFlags = Hand.AttachmentFlags.ParentToHand | Hand.AttachmentFlags.DetachFromOtherHand | Hand.AttachmentFlags.TurnOnKinematic;
[SteamVR_DefaultAction(“Up”, “default”)]
public SteamVR_Action_Boolean upAction;
[SteamVR_DefaultAction(“Down”, “default”)]
public SteamVR_Action_Boolean downAction;
[SteamVR_DefaultAction(“Left”, “default”)]
public SteamVR_Action_Boolean leftAction;
[SteamVR_DefaultAction(“Right”, “default”)]
public SteamVR_Action_Boolean rightAction;
public controlPressType ButtonToReleaseFromHand = controlPressType.Grip;
public bool setRotationOnGrab = false;
public Vector3 grabRotation;
public bool setOffsetOnGrab = false;
public Vector3 grabOffset;
public GameObject instructionsPrefab;
public string pinchLabel, gripLabel, upLabel, downLabel, leftLabel, rightLabel;
//Events to trigger on different Situations
public UnityEvent OnPinchHold, OnPinchRelease, OnGripHold, OnGripRelease, onDownPress, onDownRelease, onLeftPress, onLeftRelease, onRightPress, onRightRelease, onUpPressed, onUpReleased;
bool upPressed = false, downPressed = false, leftPressed = false, rightPressed = false;
private void Awake()
{
interactable = this.GetComponent();
}
// Use this for initialization
void Start()
{
if (instructionsPrefab != null)
{
instructionsPrefab = Instantiate(instructionsPrefab, transform.position, transform.rotation);
instructionsPrefab.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
}
private void OnHandHoverBegin(Hand hand)
{
//Debug.Log(“Remote Hover”);
}
protected virtual void HandHoverUpdate(Hand hand)
{
GrabTypes startingGrabType = hand.GetGrabStarting();
if (startingGrabType == GrabTypes.Pinch)
{
hand.AttachObject(gameObject, startingGrabType, attachmentFlags);
gameObject.transform.position = hand.transform.position;
hand.HideGrabHint();
Transform t = hand.currentAttachedObject.transform;
t.localEulerAngles = grabRotation;
t.localPosition += grabOffset;
if (instructionsPrefab != null)
{
instructionsPrefab.transform.rotation = hand.transform.rotation;
instructionsPrefab.transform.position = hand.transform.position;
instructionsPrefab.transform.SetParent(hand.transform, true);
instructionsPrefab.SetActive(true);
instructionsPrefab.GetComponent().setLabels(pinchLabel, gripLabel, upLabel, downLabel, leftLabel, rightLabel);
instructionsPrefab.GetComponent().showDiagram();
}
}
}
protected virtual void HandAttachedUpdate(Hand hand)
{
GrabTypes currentGrabType = hand.GetGrabStarting();
GrabTypes endGrabType = hand.GetGrabEnding();
//if press the side grip release the object
if (currentGrabType == GrabTypes.Grip)
{
if (ButtonToReleaseFromHand == controlPressType.Grip)
{
hand.DetachObject(gameObject, true);
if (instructionsPrefab != null)
instructionsPrefab.SetActive(false);
}
OnGripHold.Invoke();
Debug.Log(“Grip Pressed”);
}
if (endGrabType == GrabTypes.Grip)
{
//releaseGrip(hand);
OnGripRelease.Invoke();
}
//if PinchButtonIsPressed
if (currentGrabType == GrabTypes.Pinch)
{
if (ButtonToReleaseFromHand == controlPressType.Pinch)
{
hand.DetachObject(gameObject, true);
if (instructionsPrefab != null)
instructionsPrefab.SetActive(false);
}
OnPinchHold.Invoke();
}
if (endGrabType == GrabTypes.Pinch)
{
OnPinchRelease.Invoke();
}
//if up button is pressed
if (!upPressed)
{
//if (upAction.GetState(hand.handType))
if (SteamVR_Input._default.inActions.Up.GetStateUp(thisHand))
{
Debug.Log(“Up Pressed”);
upPressed = true;
onUpPressed.Invoke();
if (ButtonToReleaseFromHand == controlPressType.Up)
releaseGrip(hand);
}
}
else
{
//if (!upAction.GetState(hand.handType))
if (SteamVR_Input._default.inActions.Up.GetStateDown(thisHand))
{
upPressed = false;
onUpReleased.Invoke();
}
}
//if down button is pressed
if (!downPressed)
{
//if (downAction.GetState(hand.handType))
if (SteamVR_Input._default.inActions.Down.GetStateDown(thisHand))
{
downPressed = true;
onDownPress.Invoke();
if (ButtonToReleaseFromHand == controlPressType.Down)
releaseGrip(hand);
}
}
else
{
//if (!downAction.GetState(hand.handType))
if (SteamVR_Input._default.inActions.Down.GetStateUp(thisHand))
{
downPressed = false;
onDownRelease.Invoke();
}
}
//if left button is pressed
if (!leftPressed)
{
if (leftAction.GetState(hand.handType))
{
leftPressed = true;
onLeftPress.Invoke();
if (ButtonToReleaseFromHand == controlPressType.Left)
releaseGrip(hand);
}
}
else
{
if (!leftAction.GetState(hand.handType))
{
leftPressed = false;
onLeftRelease.Invoke();
}
}
//if right button is pressed
if (!rightPressed)
{
if (rightAction.GetState(hand.handType))
{
rightPressed = true;
onRightPress.Invoke();
if (ButtonToReleaseFromHand == controlPressType.Right)
releaseGrip(hand);
}
}
else
{
if (!rightAction.GetState(hand.handType))
{
rightPressed = false;
onRightRelease.Invoke();
}
}
//rotate weapon trigger to hand gesture
}
public void releaseGrip(Hand hand)
{
hand.DetachObject(gameObject, true);
if (instructionsPrefab != null)
instructionsPrefab.SetActive(false);
}
}
}