using System; using System.Collections; using UnityEngine; using Valve.VR; public class ViveControllerButtons : AVRControllerButtons { public ViveControllerButtons() { ulong[] array = new ulong[5]; array[1] = 4294967296UL; this.m_aryTouch2RealVive = array; base..ctor(); } protected override void Awake() { base.Awake(); this.m_eType = AVRControllerButtons.TYPE.VIVE; this.m_trackedObject = base.GetComponent(); } private void Start() { this.m_device = SteamVR_Controller.Input((int)this.m_trackedObject.index); this.m_trTrackedDeviceParent = base.transform.parent.Find("Tracked Devices"); this.m_TrackObjs = this.m_trTrackedDeviceParent.GetComponentsInChildren(true); } public override bool ShowHand { get { foreach (SteamVR_TrackedObject steamVR_TrackedObject in this.m_TrackObjs) { if (steamVR_TrackedObject.index == this.m_trackedObject.index) { return steamVR_TrackedObject.gameObject.transform.localScale.sqrMagnitude < 0.0100000007f; } } return false; } set { foreach (SteamVR_TrackedObject steamVR_TrackedObject in this.m_TrackObjs) { if (steamVR_TrackedObject.index == this.m_trackedObject.index) { if (value) { steamVR_TrackedObject.gameObject.transform.localScale = new Vector3(0f, 0f, 0f); } else { steamVR_TrackedObject.gameObject.transform.localScale = new Vector3(1f, 1f, 1f); } } } } } public override void Haptic(byte f_byFoce, float f_fTime) { if (this.m_device != null) { if (this.m_coVib != null) { base.StopCoroutine(this.m_coVib); } this.m_coVib = base.StartCoroutine(this.CoVib(f_byFoce, f_fTime)); } } private IEnumerator CoVib(byte f_byFoce, float f_fTime) { for (float fTime = 0f; fTime < f_fTime; fTime += Time.deltaTime) { yield return null; if (this.m_device != null) { this.m_device.TriggerHapticPulse((ushort)(1000f * ((float)f_byFoce / 255f)), EVRButtonId.k_EButton_Axis0); } } this.m_coVib = null; yield break; } public override bool GetPressDown(AVRControllerButtons.BTN f_eBtn) { if (this.m_device == null) { return false; } if (f_eBtn != AVRControllerButtons.BTN.VIRTUAL_L_CLICK && f_eBtn != AVRControllerButtons.BTN.VIRTUAL_R_CLICK) { return this.m_device.GetPressDown(this.m_aryBtn2RealVive[(int)f_eBtn]); } if (!this.m_device.GetPressDown(4294967296UL)) { return false; } if (this.m_device.GetAxis(EVRButtonId.k_EButton_Axis0).x < 0.7f) { this.m_bPressLeft = true; return f_eBtn == AVRControllerButtons.BTN.VIRTUAL_L_CLICK; } this.m_bPressLeft = false; return f_eBtn == AVRControllerButtons.BTN.VIRTUAL_R_CLICK; } public override bool GetPress(AVRControllerButtons.BTN f_eBtn) { if (this.m_device == null) { return false; } if (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_L_CLICK || f_eBtn == AVRControllerButtons.BTN.VIRTUAL_R_CLICK) { return this.m_device.GetPress(4294967296UL) && ((!this.m_bPressLeft) ? (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_R_CLICK) : (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_L_CLICK)); } return this.m_device.GetPress(this.m_aryBtn2RealVive[(int)f_eBtn]); } public override bool GetPressUp(AVRControllerButtons.BTN f_eBtn) { if (this.m_device == null) { return false; } if (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_L_CLICK || f_eBtn == AVRControllerButtons.BTN.VIRTUAL_R_CLICK) { return this.m_device.GetPressUp(4294967296UL) && ((!this.m_bPressLeft) ? (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_R_CLICK) : (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_L_CLICK)); } return this.m_device.GetPressUp(this.m_aryBtn2RealVive[(int)f_eBtn]); } public override bool GetTouchDown(AVRControllerButtons.TOUCH f_eTouch) { return this.m_device != null && this.m_device.GetTouchDown(this.m_aryTouch2RealVive[(int)f_eTouch]); } public override bool GetTouch(AVRControllerButtons.TOUCH f_eTouch) { return this.m_device != null && this.m_device.GetTouch(this.m_aryTouch2RealVive[(int)f_eTouch]); } public override bool GetTouchUp(AVRControllerButtons.TOUCH f_eTouch) { return this.m_device != null && this.m_device.GetTouchUp(this.m_aryTouch2RealVive[(int)f_eTouch]); } public override Vector2 GetAxis() { if (this.m_device == null) { return Vector2.zero; } return this.m_device.GetAxis(EVRButtonId.k_EButton_Axis0); } public override float GetTriggerRate() { if (this.m_device == null) { return 0f; } return this.m_device.GetAxis(EVRButtonId.k_EButton_Axis1).x; } private void Update() { this.m_device = SteamVR_Controller.Input((int)this.m_trackedObject.index); if (this.m_device != null && this.m_device.GetPressDown(4294967296UL)) { if (this.m_device.GetAxis(EVRButtonId.k_EButton_Axis0).x < 0.7f) { this.m_bPressLeft = true; } else { this.m_bPressLeft = false; } } } private ulong[] m_aryBtn2RealVive = new ulong[] { 2UL, 4294967296UL, 4294967296UL, 8589934592UL, 2UL, 8589934592UL, 4294967296UL, 4UL }; private ulong[] m_aryTouch2RealVive; private SteamVR_TrackedObject m_trackedObject; private Transform m_trTrackedDeviceParent; private SteamVR_TrackedObject[] m_TrackObjs; private SteamVR_Controller.Device m_device; private bool m_bPressLeft; private Coroutine m_coVib; }