- Home /
Change menu graphic material based on which controller type is being used in Steam VR.
I have an in game/vr computer screen showing the controller settings in my project. I have different graphics to put on this screen based on when the user is running the game with a Valve Index controller or a Vive (pro) Controller. Each graphic is set with its own material which I can swap but what I need to know is how the build recognizes which controller is being used?
SteamVR and Unity OpenVR must have a way of telling which controller is in use as it automatically swaps out the model of the controller but I don't know how to tap into that recognition so I can swap my graphic.
I have been looking at SteamVR_RenderModel.cs (mostly around line 145-167.) but I can't seem to figure it out and I don't even know if I'm looking in the right place? (https://github.com/ValveSoftware/steamvr_unity_plugin)
Do any of you know how to do this?
I have found the IVR system but the documentation is confusing? Can any one help me understand how I would change out player instructions based on what controller is in use? It seems like this would be a common need but I have not found any information clarifying the concept while scouring the web for a solution.
https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetTrackedDeviceProperty https://github.com/ValveSoftware/openvr/wiki/API-Documentation https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetTrackedDeviceClass
This is as far as I have made it. Its not much.
using UnityEngine;
using Valve.VR;
public class ControllerBasedRenderer : $$anonymous$$onoBehaviour
{
public Renderer Object;
public $$anonymous$$aterial default$$anonymous$$aterial;
public $$anonymous$$aterial vive$$anonymous$$aterial;
public $$anonymous$$aterial index$$anonymous$$aterial;
public $$anonymous$$aterial oculus$$anonymous$$aterial;
void OnEnable()
{
//Subscribe to the event that is called by S$$anonymous$$mVR_Render$$anonymous$$odel, when the controller and it's associated material has been loaded completely.
S$$anonymous$$mVR_Events.Render$$anonymous$$odelLoaded.Listen(OnControllerLoaded);
}
void Start() //$$anonymous$$eep the script accessible to turn off/on in the inspector.
{
}
public void Update$$anonymous$$aterial($$anonymous$$aterial new$$anonymous$$aterial)
{
//How can I find if Vive or if index/knuckles?
//if(controler index is the vive?){
Object.material = vive$$anonymous$$aterial;
//if its an index controller in use?
//Object.material = index$$anonymous$$aterial;
//if its an oculas touch?
//Object.material = oculus$$anonymous$$aterial;
}
void OnControllerLoaded(S$$anonymous$$mVR_Render$$anonymous$$odel controllerRender$$anonymous$$odel, bool success)
{
Update$$anonymous$$aterial(default$$anonymous$$aterial);
}
void OnDisable()
{
//Unsubscribe to the event if this object is disabled.
S$$anonymous$$mVR_Events.Render$$anonymous$$odelLoaded.Remove(OnControllerLoaded);
}
}