ViveControllerHit.cs 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using Valve.VR;
  5. public class ViveControllerHit : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. this.m_trackedObject = base.transform.parent.GetComponent<SteamVR_TrackedObject>();
  10. NDebug.Assert(this.m_trackedObject != null, "SteamVR_TrackedObject が親から取得不可能。");
  11. }
  12. private void Update()
  13. {
  14. }
  15. private void OnCollisionEnter(Collision collision)
  16. {
  17. this.m_device = SteamVR_Controller.Input((int)this.m_trackedObject.index);
  18. if (this.m_device != null)
  19. {
  20. base.StartCoroutine(this.CoVive());
  21. }
  22. }
  23. private IEnumerator CoVive()
  24. {
  25. for (float fTime = 0f; fTime < this.m_fViveTimeMS; fTime += Time.deltaTime)
  26. {
  27. yield return null;
  28. this.m_device.TriggerHapticPulse(this.m_uViveForce, EVRButtonId.k_EButton_Axis0);
  29. }
  30. yield break;
  31. }
  32. public ushort m_uViveForce = 1000;
  33. public float m_fViveTimeMS = 0.1f;
  34. private SteamVR_TrackedObject m_trackedObject;
  35. private SteamVR_Controller.Device m_device;
  36. }