123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- using System;
- using System.Diagnostics;
- using UnityEngine;
- using Valve.VR;
- public class SteamVR_TrackedController : MonoBehaviour
- {
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler MenuButtonClicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler MenuButtonUnclicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler TriggerClicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler TriggerUnclicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler SteamClicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler PadClicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler PadUnclicked;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler PadTouched;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler PadUntouched;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler Gripped;
- [DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event ClickedEventHandler Ungripped;
- private void Start()
- {
- if (base.GetComponent<SteamVR_TrackedObject>() == null)
- {
- base.gameObject.AddComponent<SteamVR_TrackedObject>();
- }
- if (this.controllerIndex != 0U)
- {
- base.GetComponent<SteamVR_TrackedObject>().index = (SteamVR_TrackedObject.EIndex)this.controllerIndex;
- if (base.GetComponent<SteamVR_RenderModel>() != null)
- {
- base.GetComponent<SteamVR_RenderModel>().index = (SteamVR_TrackedObject.EIndex)this.controllerIndex;
- }
- }
- else
- {
- this.controllerIndex = (uint)base.GetComponent<SteamVR_TrackedObject>().index;
- }
- }
- public void SetDeviceIndex(int index)
- {
- this.controllerIndex = (uint)index;
- }
- public virtual void OnTriggerClicked(ClickedEventArgs e)
- {
- if (this.TriggerClicked != null)
- {
- this.TriggerClicked(this, e);
- }
- }
- public virtual void OnTriggerUnclicked(ClickedEventArgs e)
- {
- if (this.TriggerUnclicked != null)
- {
- this.TriggerUnclicked(this, e);
- }
- }
- public virtual void OnMenuClicked(ClickedEventArgs e)
- {
- if (this.MenuButtonClicked != null)
- {
- this.MenuButtonClicked(this, e);
- }
- }
- public virtual void OnMenuUnclicked(ClickedEventArgs e)
- {
- if (this.MenuButtonUnclicked != null)
- {
- this.MenuButtonUnclicked(this, e);
- }
- }
- public virtual void OnSteamClicked(ClickedEventArgs e)
- {
- if (this.SteamClicked != null)
- {
- this.SteamClicked(this, e);
- }
- }
- public virtual void OnPadClicked(ClickedEventArgs e)
- {
- if (this.PadClicked != null)
- {
- this.PadClicked(this, e);
- }
- }
- public virtual void OnPadUnclicked(ClickedEventArgs e)
- {
- if (this.PadUnclicked != null)
- {
- this.PadUnclicked(this, e);
- }
- }
- public virtual void OnPadTouched(ClickedEventArgs e)
- {
- if (this.PadTouched != null)
- {
- this.PadTouched(this, e);
- }
- }
- public virtual void OnPadUntouched(ClickedEventArgs e)
- {
- if (this.PadUntouched != null)
- {
- this.PadUntouched(this, e);
- }
- }
- public virtual void OnGripped(ClickedEventArgs e)
- {
- if (this.Gripped != null)
- {
- this.Gripped(this, e);
- }
- }
- public virtual void OnUngripped(ClickedEventArgs e)
- {
- if (this.Ungripped != null)
- {
- this.Ungripped(this, e);
- }
- }
- private void Update()
- {
- CVRSystem system = OpenVR.System;
- if (system != null && system.GetControllerState(this.controllerIndex, ref this.controllerState))
- {
- ulong num = this.controllerState.ulButtonPressed & 8589934592UL;
- if (num > 0UL && !this.triggerPressed)
- {
- this.triggerPressed = true;
- ClickedEventArgs e;
- e.controllerIndex = this.controllerIndex;
- e.flags = (uint)this.controllerState.ulButtonPressed;
- e.padX = this.controllerState.rAxis0.x;
- e.padY = this.controllerState.rAxis0.y;
- this.OnTriggerClicked(e);
- }
- else if (num == 0UL && this.triggerPressed)
- {
- this.triggerPressed = false;
- ClickedEventArgs e2;
- e2.controllerIndex = this.controllerIndex;
- e2.flags = (uint)this.controllerState.ulButtonPressed;
- e2.padX = this.controllerState.rAxis0.x;
- e2.padY = this.controllerState.rAxis0.y;
- this.OnTriggerUnclicked(e2);
- }
- ulong num2 = this.controllerState.ulButtonPressed & 4UL;
- if (num2 > 0UL && !this.gripped)
- {
- this.gripped = true;
- ClickedEventArgs e3;
- e3.controllerIndex = this.controllerIndex;
- e3.flags = (uint)this.controllerState.ulButtonPressed;
- e3.padX = this.controllerState.rAxis0.x;
- e3.padY = this.controllerState.rAxis0.y;
- this.OnGripped(e3);
- }
- else if (num2 == 0UL && this.gripped)
- {
- this.gripped = false;
- ClickedEventArgs e4;
- e4.controllerIndex = this.controllerIndex;
- e4.flags = (uint)this.controllerState.ulButtonPressed;
- e4.padX = this.controllerState.rAxis0.x;
- e4.padY = this.controllerState.rAxis0.y;
- this.OnUngripped(e4);
- }
- ulong num3 = this.controllerState.ulButtonPressed & 4294967296UL;
- if (num3 > 0UL && !this.padPressed)
- {
- this.padPressed = true;
- ClickedEventArgs e5;
- e5.controllerIndex = this.controllerIndex;
- e5.flags = (uint)this.controllerState.ulButtonPressed;
- e5.padX = this.controllerState.rAxis0.x;
- e5.padY = this.controllerState.rAxis0.y;
- this.OnPadClicked(e5);
- }
- else if (num3 == 0UL && this.padPressed)
- {
- this.padPressed = false;
- ClickedEventArgs e6;
- e6.controllerIndex = this.controllerIndex;
- e6.flags = (uint)this.controllerState.ulButtonPressed;
- e6.padX = this.controllerState.rAxis0.x;
- e6.padY = this.controllerState.rAxis0.y;
- this.OnPadUnclicked(e6);
- }
- ulong num4 = this.controllerState.ulButtonPressed & 2UL;
- if (num4 > 0UL && !this.menuPressed)
- {
- this.menuPressed = true;
- ClickedEventArgs e7;
- e7.controllerIndex = this.controllerIndex;
- e7.flags = (uint)this.controllerState.ulButtonPressed;
- e7.padX = this.controllerState.rAxis0.x;
- e7.padY = this.controllerState.rAxis0.y;
- this.OnMenuClicked(e7);
- }
- else if (num4 == 0UL && this.menuPressed)
- {
- this.menuPressed = false;
- ClickedEventArgs e8;
- e8.controllerIndex = this.controllerIndex;
- e8.flags = (uint)this.controllerState.ulButtonPressed;
- e8.padX = this.controllerState.rAxis0.x;
- e8.padY = this.controllerState.rAxis0.y;
- this.OnMenuUnclicked(e8);
- }
- num3 = (this.controllerState.ulButtonTouched & 4294967296UL);
- if (num3 > 0UL && !this.padTouched)
- {
- this.padTouched = true;
- ClickedEventArgs e9;
- e9.controllerIndex = this.controllerIndex;
- e9.flags = (uint)this.controllerState.ulButtonPressed;
- e9.padX = this.controllerState.rAxis0.x;
- e9.padY = this.controllerState.rAxis0.y;
- this.OnPadTouched(e9);
- }
- else if (num3 == 0UL && this.padTouched)
- {
- this.padTouched = false;
- ClickedEventArgs e10;
- e10.controllerIndex = this.controllerIndex;
- e10.flags = (uint)this.controllerState.ulButtonPressed;
- e10.padX = this.controllerState.rAxis0.x;
- e10.padY = this.controllerState.rAxis0.y;
- this.OnPadUntouched(e10);
- }
- }
- }
- public uint controllerIndex;
- public VRControllerState_t controllerState;
- public bool triggerPressed;
- public bool steamPressed;
- public bool menuPressed;
- public bool padPressed;
- public bool padTouched;
- public bool gripped;
- }
|