public void Init() { // Get control input settings from script ViveControlInputs = new Dictionary <ViveControlType, ViveControlInput>(); ViveControlInputs.Add(ViveControlType.Grip, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "grip"))); ViveControlInputs.Add(ViveControlType.Trigger, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "trigger"))); ViveControlInputs.Add(ViveControlType.Touchpad, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "touchpadclick"), SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "touchpadtouch"), SteamVR_Input.GetAction <SteamVR_Action_Vector2>("srinput", "touchpadposition"))); //// Get control input settings from inspector //for (int i = 0; i < (int)ViveControlType.Max; ++i) // ViveControlInputs[(ViveControlType)i] = ViveControlInputList[i]; // Disable 2D Player.instance.allowToggleTo2D = false; // Get hand and add listener to each button hand = ViveSR_Experience.instance.targetHand; for (int i = 0; i < (int)ViveControlType.Max; ++i) { ViveControlType type = (ViveControlType)i; if (type == ViveControlType.Touchpad) { ViveControlInputs[type].actionTouch.AddOnUpdateListener(ClickListener, hand.handType); } ViveControlInputs[type].actionClick.AddOnUpdateListener(ClickListener, hand.handType); } }
void ClickListener(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState) { if (fromSource != SteamVR_Input_Sources.LeftHand && fromSource != SteamVR_Input_Sources.RightHand) { return; } // Get button according to control type ViveControlType controlType = ViveControlInputs.First(x => fromAction == x.Value.actionClick || fromAction == x.Value.actionTouch).Key; ViveControlInput input = ViveControlInputs[controlType]; // Get button click status ButtonStage status = GetInputActionStatus(fromAction, input); if (status == ButtonStage.None) { return; } // Call each button's delegate behavior if (controlType == ViveControlType.Grip) { if (gripDelegate != null) { gripDelegate(status, Vector2.zero); } if (gripDelegate_Late != null) { gripDelegate_Late(status, Vector2.zero); } } else if (controlType == ViveControlType.Trigger) { if (triggerDelegate != null) { triggerDelegate(status, Vector2.zero); } if (triggerDelegate_Late != null) { triggerDelegate_Late(status, Vector2.zero); } } else if (controlType == ViveControlType.Touchpad) { if (touchpadDelegate != null) { touchpadDelegate(status, input.actionPosition.GetAxis(hand.handType)); } if (touchpadDelegate_Late != null) { touchpadDelegate_Late(status, input.actionPosition.GetAxis(hand.handType)); } } }