Getting the menu button input on the SteamVR controller - c#

Hi2,
Does anyone know how to get the menu button input on the steamVR controller via C# code in Unity?
Currently I am able to get the input from the the trigger, trackpad, and grip button.
private void Update()
{
if (SteamVR_Input._default.inActions.GrabGrip.GetStateDown(inputSource))
Debug.Log("grab grip"); // the side button on the controller
if (SteamVR_Input._default.inActions.GrabPinch.GetStateDown(inputSource))
Debug.Log("grab pinch"); // the back button on the controller
if (SteamVR_Input._default.inActions.Teleport.GetStateDown(inputSource))
Debug.Log("teleport"); // the big middle button on the controller
}
any help is appreciated. ^_^

Select in the menu 'Window -> SteamVR Input'. From there click on 'Open Binding UI'.
Your browser will open a screen where you can see this:
The red arrow points to where you can add an action for the menu button (sorry, mine is in German). Call it 'MenuClick' and make sure you save that in your private settings.
Then, in your code access it as
if (SteamVR_Input._default.inActions.MenuClick.GetStateDown(inputSource))
Debug.Log("menu button pressed"); // the menu button on the controller

Related

Unity: Trying to Link a Button to URL In a Condition "if"

I've been struggling with my AR project in Unity. The main problem is the button opens the link repeatedly and it won't stop. The concept I want to reach here is when I scanned a marker, a description text will pop up along with the button, the button will take user to a URL.
The code I'm using is:
public Transform ButtonMap;
TextObjectName.GetComponent<text>().text=name;
if (name == "QRCode1"){
ButtonMap.GetComponent.<Button>().onClick.AddListener(delegate {Application.OpenURL("https://www.google.com"); });
}
The code has no errors, but when I pressed it, it will open the link repeatedly until I stop the app.
Please Help
Regards

Back button on ui appears until you hit options and back

New to coding here, setting up a UI in unity and having a visual issue where the back button appears until I hit options and back on the start up page, any reccomendations for a fix?
Image showing back button behind the quit button
Settings of the image on the right
You can use Gameobject.setactive(true/false) and try to manage the panel by making empty game object inside UI Canvas and name it as a panel so the whole button became a child and you can easily manage it
for example like this one
public Gameobject startPanel;
public Gameobject optionPanel;
public void Startpnl()
{
//deadActive optionPanel and Activate startPanel
startPanel.setActive(true);
optionPanel.setActive(false);
}
public void optionpnl()
{
//deadActive starPanel and Activate OptionPanel
startPanel.setActive(false);
optionPanel.setActive(true);
}

How i can set the Searchbar Inative and User click on this for open a Dialog

My Question is how can i Build in Android C# an SreachView this is off by but Show and any User click on this a Dialog open and asked the User to give her ok.
I work in a Fragment
SearchView searchView;
searchView = (SearchView)View.FindViewById(Resource.Id.MenuSearchitem);
searchView.ClearFocus();
searchView.SetOnQueryTextListener(this);
searchView.SetOnQueryTextFocusChangeListener(this);
searchView.SetIconifiedByDefault(false);
searchView.SubmitButtonEnabled = true;
searchView.QueryHint = mapViewModel.AddressPlaceholder;
thats all fine, but nothing work for click on the searchbar and no dialog is open.
follow ways i have used IOnFocusChangeListener and IOnSuggestionListener dont gave the right way for me
you can use onTouchListner, wherever you will touch on the screen the touch event will be triggered, there you can check which widget is clicked just check it and open dialog in it.

Windows Mixed Reality - AttachToController

So I'm using the AttachToController script to attach a window floated on top of the controller - which works great. In the script that calls up the window, I figure out which hand pressed the controller's menu button and set the Handedness field appropriately (Left or Right). The problem I'm trying to solve is this: Let's say the user clicks on the right controller's menu button and then later on, the left menu button is clicked. The problem I'm experiencing is that even though I've altered the Handedness field, the window still appears attached to the right controller.
private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs args)
{
hand = args.state.source.handedness;
...
}
private void SetHandednessAndActivate(GameObject go)
{
AttachToController script = go.GetComponentInChildren<AttachToController>();
if (script != null)
{
script.Handedness = hand;
}
go.SetActive(true);
}
Just to be clear, if the user clicks the left controller menu button first, the window is always on the left and the same holds true for the right controller. What I want is for the window to move to whichever controller is used.
Instead of
script.Handedness = hand;
Use
script.ChangeHandedness(hand);
All the other bits are handled by the script.

Unity: Only mouse works on first input (EventSystem / Canvas)

In Unity I have a simple world space canvas with a single button set up.
If you click the button with the mouse it works.
If you use another method (Like 'joystick button 0') it will not activate the button.
Once 'mouse button 0' has been clicked once subsequent button clicks using the 'joystick button 0' register.
Additional info; If you set the project to VR or move cursor away from the button 'joystick button 0' will continue to activate the button even if the cursor isn't over the button. It will stop once 'mouse button 0' is pressed to deselect the button.
The goal is to use 'joystick button 0' / 'joystick button 1' as the only inputs to the canvas and ultimately have a mouse look feature using a joypad.
Any Idea what is going on / how to get this working?
Input is the default unity setup. ('mouse 0' only mapped to 'Fire1' / not mapped to 'Submit') (EventSystem's "Submit Button" is mapped to 'Submit')
See Script:
using UnityEngine;
using System.Collections;
public class ButtonTestScript : MonoBehaviour {
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Submit"))
Debug.Log("Submit");
else if(Input.GetButtonDown("Cancel"))
Debug.Log("Cancel");
//Lock The Cusor
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = true;
}
public void ButtonClick()
{
Debug.Log("Button Clicked = " + gameObject.name);
}
}
The short answer is the system isn't built to work like that. The longer answer is:
https://unity3d.com/learn/tutorials/topics/virtual-reality/interaction-vr

Categories