VRHeightOffset.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Linq;
  3. using UnityEngine;
  4. using UnityEngine.VR;
  5. public class VRHeightOffset : MonoBehaviour
  6. {
  7. private void Reset()
  8. {
  9. this._deviceOffsets = new VRHeightOffset.DeviceHeightPair[1];
  10. this._deviceOffsets[0] = new VRHeightOffset.DeviceHeightPair("oculus", 1f);
  11. }
  12. private void Start()
  13. {
  14. if (VRDevice.isPresent && VRSettings.enabled && this._deviceOffsets != null)
  15. {
  16. string deviceName = VRSettings.loadedDeviceName;
  17. VRHeightOffset.DeviceHeightPair deviceHeightPair = this._deviceOffsets.FirstOrDefault((VRHeightOffset.DeviceHeightPair d) => deviceName.ToLower().Contains(d.DeviceName.ToLower()));
  18. if (deviceHeightPair != null)
  19. {
  20. base.transform.Translate(Vector3.up * deviceHeightPair.HeightOffset);
  21. }
  22. }
  23. }
  24. public VRHeightOffset.DeviceHeightPair[] _deviceOffsets;
  25. [Serializable]
  26. public class DeviceHeightPair
  27. {
  28. public DeviceHeightPair(string deviceName, float heightOffset)
  29. {
  30. this.DeviceName = deviceName;
  31. this.HeightOffset = heightOffset;
  32. }
  33. public string DeviceName;
  34. public float HeightOffset;
  35. }
  36. }