0% found this document useful (0 votes)
111 views9 pages

.txt

The ControllerInputPoller class manages input from VR controllers in a Unity application, specifically handling left and right hand controllers and the head device. It initializes the controller types, polls input states, and provides methods to retrieve button presses, grip states, and device positions. The class also implements singleton behavior to ensure only one instance exists during runtime.

Uploaded by

lowito2618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views9 pages

.txt

The ControllerInputPoller class manages input from VR controllers in a Unity application, specifically handling left and right hand controllers and the head device. It initializes the controller types, polls input states, and provides methods to retrieve button presses, grip states, and device positions. The class also implements singleton behavior to ensure only one instance exists during runtime.

Uploaded by

lowito2618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

using System;

using GorillaLocomotion;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;

// Token: 0x0200037A RID: 890


public class ControllerInputPoller : MonoBehaviour
{
// Token: 0x17000223 RID: 547
// (get) Token: 0x06001445 RID: 5189
// (set) Token: 0x06001446 RID: 5190
public GorillaControllerType controllerType { get; private set; }

// Token: 0x06001447 RID: 5191


private void Awake()
{
if (ControllerInputPoller.instance == null)
{
ControllerInputPoller.instance = this;
return;
}
if (ControllerInputPoller.instance != this)
{
Object.Destroy(base.gameObject);
}
}

// Token: 0x06001448 RID: 5192


private void Update()
{
InputDevice inputDevice = this.leftControllerDevice;
if (!this.leftControllerDevice.isValid)
{
this.leftControllerDevice =
InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);
if (this.leftControllerDevice.isValid)
{
this.controllerType = GorillaControllerType.OCULUS_DEFAULT;
if
(this.leftControllerDevice.name.ToLower().Contains("knuckles"))
{
this.controllerType = GorillaControllerType.INDEX;
}
Debug.Log(string.Format("Found left controller: {0}
ControllerType: {1}", this.leftControllerDevice.name, this.controllerType));
}
}
InputDevice inputDevice2 = this.rightControllerDevice;
if (!this.rightControllerDevice.isValid)
{
this.rightControllerDevice =
InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
}
InputDevice inputDevice3 = this.headDevice;
if (!this.headDevice.isValid)
{
this.headDevice =
InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
}
InputDevice inputDevice4 = this.leftControllerDevice;
InputDevice inputDevice5 = this.rightControllerDevice;
InputDevice inputDevice6 = this.headDevice;

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.primaryButton, out
this.leftControllerPrimaryButton);

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.secondaryButton,
out this.leftControllerSecondaryButton);
this.leftControllerDevice.TryGetFeatureValue(CommonUsages.primaryTouch,
out this.leftControllerPrimaryButtonTouch);

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.secondaryTouch, out
this.leftControllerSecondaryButtonTouch);
this.leftControllerDevice.TryGetFeatureValue(CommonUsages.grip, out
this.leftControllerGripFloat);
this.leftControllerDevice.TryGetFeatureValue(CommonUsages.trigger, out
this.leftControllerIndexFloat);

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.devicePosition, out
this.leftControllerPosition);

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.deviceRotation, out
this.leftControllerRotation);

this.leftControllerDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out
this.leftControllerPrimary2DAxis);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.primaryButton, out
this.rightControllerPrimaryButton);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.secondaryButton,
out this.rightControllerSecondaryButton);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.primaryTouch, out
this.rightControllerPrimaryButtonTouch);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.secondaryTouch,
out this.rightControllerSecondaryButtonTouch);
this.rightControllerDevice.TryGetFeatureValue(CommonUsages.grip, out
this.rightControllerGripFloat);
this.rightControllerDevice.TryGetFeatureValue(CommonUsages.trigger, out
this.rightControllerIndexFloat);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.devicePosition,
out this.rightControllerPosition);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.deviceRotation,
out this.rightControllerRotation);

this.rightControllerDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out
this.rightControllerPrimary2DAxis);
this.leftControllerPrimaryButton =
SteamVR_Actions.gorillaTag_LeftPrimaryClick.GetState(SteamVR_Input_Sources.LeftHand
);
this.leftControllerSecondaryButton =
SteamVR_Actions.gorillaTag_LeftSecondaryClick.GetState(SteamVR_Input_Sources.LeftHa
nd);
this.leftControllerPrimaryButtonTouch =
SteamVR_Actions.gorillaTag_LeftPrimaryTouch.GetState(SteamVR_Input_Sources.LeftHand
);
this.leftControllerSecondaryButtonTouch =
SteamVR_Actions.gorillaTag_LeftSecondaryTouch.GetState(SteamVR_Input_Sources.LeftHa
nd);
this.leftControllerGripFloat =
SteamVR_Actions.gorillaTag_LeftGripFloat.GetAxis(SteamVR_Input_Sources.LeftHand);
this.leftControllerIndexFloat =
SteamVR_Actions.gorillaTag_LeftTriggerFloat.GetAxis(SteamVR_Input_Sources.LeftHand)
;
this.rightControllerPrimaryButton =
SteamVR_Actions.gorillaTag_RightPrimaryClick.GetState(SteamVR_Input_Sources.RightHa
nd);
this.rightControllerSecondaryButton =
SteamVR_Actions.gorillaTag_RightSecondaryClick.GetState(SteamVR_Input_Sources.Right
Hand);
this.rightControllerPrimaryButtonTouch =
SteamVR_Actions.gorillaTag_RightPrimaryTouch.GetState(SteamVR_Input_Sources.RightHa
nd);
this.rightControllerSecondaryButtonTouch =
SteamVR_Actions.gorillaTag_RightSecondaryTouch.GetState(SteamVR_Input_Sources.Right
Hand);
this.rightControllerGripFloat =
SteamVR_Actions.gorillaTag_RightGripFloat.GetAxis(SteamVR_Input_Sources.RightHand);
this.rightControllerIndexFloat =
SteamVR_Actions.gorillaTag_RightTriggerFloat.GetAxis(SteamVR_Input_Sources.RightHan
d);
this.rightControllerPrimary2DAxis =
SteamVR_Actions.gorillaTag_RightJoystick2DAxis.GetAxis(SteamVR_Input_Sources.RightH
and);
this.headDevice.TryGetFeatureValue(CommonUsages.devicePosition, out
this.headPosition);
this.headDevice.TryGetFeatureValue(CommonUsages.deviceRotation, out
this.headRotation);
if (this.controllerType == GorillaControllerType.OCULUS_DEFAULT)
{
this.CalculateGrabState(this.leftControllerGripFloat, ref
this.leftGrab, ref this.leftGrabRelease, ref this.leftGrabMomentary, ref
this.leftGrabReleaseMomentary, 0.75f, 0.65f);
this.CalculateGrabState(this.rightControllerGripFloat, ref
this.rightGrab, ref this.rightGrabRelease, ref this.rightGrabMomentary, ref
this.rightGrabReleaseMomentary, 0.75f, 0.65f);
}
if (this.controllerType == GorillaControllerType.INDEX)
{
this.CalculateGrabState(this.leftControllerGripFloat, ref
this.leftGrab, ref this.leftGrabRelease, ref this.leftGrabMomentary, ref
this.leftGrabReleaseMomentary, 0.1f, 0.01f);
this.CalculateGrabState(this.rightControllerGripFloat, ref
this.rightGrab, ref this.rightGrabRelease, ref this.rightGrabMomentary, ref
this.rightGrabReleaseMomentary, 0.1f, 0.01f);
}
if (!this.leftGrab || !this.rightGrab || this.rightControllerIndexFloat
>= 0.5f || this.leftControllerIndexFloat >= 0.5f)
{
return;
}
Player player = Player.Instance;
if (player.wasLeftHandTouching || player.wasRightHandTouching)
{
player.transform.position += new
Vector3(player.headCollider.transform.forward.x * 1.3f, 0.06f,
player.headCollider.transform.forward.z * 1.3f);
}
this.leftControllerGripFloat = 0f;
this.rightControllerGripFloat = 0f;
}

// Token: 0x06001449 RID: 5193


private void CalculateGrabState(float grabValue, ref bool grab, ref bool
grabRelease, ref bool grabMomentary, ref bool grabReleaseMomentary, float
grabThreshold, float grabReleaseThreshold)
{
bool flag = grabValue >= grabThreshold;
bool flag2 = grabValue <= grabReleaseThreshold;
grabMomentary = (flag && flag != grab);
grabReleaseMomentary = (flag2 && flag2 != grabRelease);
grab = flag;
grabRelease = flag2;
}

// Token: 0x0600144A RID: 5194


public static bool GetGrab(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftGrab;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightGrab;
}

// Token: 0x0600144B RID: 5195


public static bool GetGrabRelease(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftGrabRelease;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightGrabRelease;
}

// Token: 0x0600144C RID: 5196


public static bool GetGrabMomentary(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftGrabMomentary;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightGrabMomentary;
}

// Token: 0x0600144D RID: 5197


public static bool GetGrabReleaseMomentary(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftGrabReleaseMomentary;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightGrabReleaseMomentary;
}

// Token: 0x0600144E RID: 5198


public static Vector2 Primary2DAxis(XRNode node)
{
if (node == XRNode.LeftHand)
{
return
ControllerInputPoller.instance.leftControllerPrimary2DAxis;
}
return ControllerInputPoller.instance.rightControllerPrimary2DAxis;
}

// Token: 0x0600144F RID: 5199


public static bool PrimaryButtonPress(XRNode node)
{
if (node == XRNode.LeftHand)
{
return
ControllerInputPoller.instance.leftControllerPrimaryButton;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightControllerPrimaryButton;
}

// Token: 0x06001450 RID: 5200


public static bool SecondaryButtonPress(XRNode node)
{
if (node == XRNode.LeftHand)
{
return
ControllerInputPoller.instance.leftControllerSecondaryButton;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightControllerSecondaryButton;
}

// Token: 0x06001451 RID: 5201


public static bool PrimaryButtonTouch(XRNode node)
{
if (node == XRNode.LeftHand)
{
return
ControllerInputPoller.instance.leftControllerPrimaryButtonTouch;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightControllerPrimaryButtonTouch;
}

// Token: 0x06001452 RID: 5202


public static bool SecondaryButtonTouch(XRNode node)
{
if (node == XRNode.LeftHand)
{
return
ControllerInputPoller.instance.leftControllerSecondaryButtonTouch;
}
return node == XRNode.RightHand &&
ControllerInputPoller.instance.rightControllerSecondaryButtonTouch;
}

// Token: 0x06001453 RID: 5203


public static float GripFloat(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftControllerGripFloat;
}
if (node == XRNode.RightHand)
{
return ControllerInputPoller.instance.rightControllerGripFloat;
}
return 0f;
}

// Token: 0x06001454 RID: 5204


public static float TriggerFloat(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftControllerIndexFloat;
}
if (node == XRNode.RightHand)
{
return ControllerInputPoller.instance.rightControllerIndexFloat;
}
return 0f;
}

// Token: 0x06001455 RID: 5205


public static float TriggerTouch(XRNode node)
{
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftControllerIndexTouch;
}
if (node == XRNode.RightHand)
{
return ControllerInputPoller.instance.rightControllerIndexTouch;
}
return 0f;
}

// Token: 0x06001456 RID: 5206


public static Vector3 DevicePosition(XRNode node)
{
if (node == XRNode.Head)
{
return ControllerInputPoller.instance.headPosition;
}
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftControllerPosition;
}
if (node == XRNode.RightHand)
{
return ControllerInputPoller.instance.rightControllerPosition;
}
return Vector3.zero;
}

// Token: 0x06001457 RID: 5207


public static Quaternion DeviceRotation(XRNode node)
{
if (node == XRNode.Head)
{
return ControllerInputPoller.instance.headRotation;
}
if (node == XRNode.LeftHand)
{
return ControllerInputPoller.instance.leftControllerRotation;
}
if (node == XRNode.RightHand)
{
return ControllerInputPoller.instance.rightControllerRotation;
}
return Quaternion.identity;
}

// Token: 0x06001458 RID: 5208


public static bool PositionValid(XRNode node)
{
if (node == XRNode.Head)
{
InputDevice inputDevice =
ControllerInputPoller.instance.headDevice;
return ControllerInputPoller.instance.headDevice.isValid;
}
if (node == XRNode.LeftHand)
{
InputDevice inputDevice2 =
ControllerInputPoller.instance.leftControllerDevice;
return
ControllerInputPoller.instance.leftControllerDevice.isValid;
}
if (node == XRNode.RightHand)
{
InputDevice inputDevice3 =
ControllerInputPoller.instance.rightControllerDevice;
return
ControllerInputPoller.instance.rightControllerDevice.isValid;
}
return false;
}

// Token: 0x0400164A RID: 5706


[OnEnterPlay_SetNull]
public static volatile ControllerInputPoller instance;

// Token: 0x0400164B RID: 5707


public float leftControllerIndexFloat;
// Token: 0x0400164C RID: 5708
public float leftControllerGripFloat;

// Token: 0x0400164D RID: 5709


public float rightControllerIndexFloat;

// Token: 0x0400164E RID: 5710


public float rightControllerGripFloat;

// Token: 0x0400164F RID: 5711


public float leftControllerIndexTouch;

// Token: 0x04001650 RID: 5712


public float rightControllerIndexTouch;

// Token: 0x04001651 RID: 5713


public float rightStickLRFloat;

// Token: 0x04001652 RID: 5714


public Vector3 leftControllerPosition;

// Token: 0x04001653 RID: 5715


public Vector3 rightControllerPosition;

// Token: 0x04001654 RID: 5716


public Vector3 headPosition;

// Token: 0x04001655 RID: 5717


public Quaternion leftControllerRotation;

// Token: 0x04001656 RID: 5718


public Quaternion rightControllerRotation;

// Token: 0x04001657 RID: 5719


public Quaternion headRotation;

// Token: 0x04001658 RID: 5720


public InputDevice leftControllerDevice;

// Token: 0x04001659 RID: 5721


public InputDevice rightControllerDevice;

// Token: 0x0400165A RID: 5722


public InputDevice headDevice;

// Token: 0x0400165B RID: 5723


public bool leftControllerPrimaryButton;

// Token: 0x0400165C RID: 5724


public bool leftControllerSecondaryButton;

// Token: 0x0400165D RID: 5725


public bool rightControllerPrimaryButton;

// Token: 0x0400165E RID: 5726


public bool rightControllerSecondaryButton;

// Token: 0x0400165F RID: 5727


public bool leftControllerPrimaryButtonTouch;

// Token: 0x04001660 RID: 5728


public bool leftControllerSecondaryButtonTouch;

// Token: 0x04001661 RID: 5729


public bool rightControllerPrimaryButtonTouch;

// Token: 0x04001662 RID: 5730


public bool rightControllerSecondaryButtonTouch;

// Token: 0x04001663 RID: 5731


public bool leftGrab;

// Token: 0x04001664 RID: 5732


public bool leftGrabRelease;

// Token: 0x04001665 RID: 5733


public bool rightGrab;

// Token: 0x04001666 RID: 5734


public bool rightGrabRelease;

// Token: 0x04001667 RID: 5735


public bool leftGrabMomentary;

// Token: 0x04001668 RID: 5736


public bool leftGrabReleaseMomentary;

// Token: 0x04001669 RID: 5737


public bool rightGrabMomentary;

// Token: 0x0400166A RID: 5738


public bool rightGrabReleaseMomentary;

// Token: 0x0400166C RID: 5740


public Vector2 leftControllerPrimary2DAxis;

// Token: 0x0400166D RID: 5741


public Vector2 rightControllerPrimary2DAxis;

// Token: 0x04003F0C RID: 16140


private int ticks2;
}

You might also like