123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.VR;
- public class VRHeightOffset : MonoBehaviour
- {
- private void Reset()
- {
- this._deviceOffsets = new VRHeightOffset.DeviceHeightPair[1];
- this._deviceOffsets[0] = new VRHeightOffset.DeviceHeightPair("oculus", 1f);
- }
- private void Start()
- {
- if (VRDevice.isPresent && VRSettings.enabled && this._deviceOffsets != null)
- {
- string deviceName = VRSettings.loadedDeviceName;
- VRHeightOffset.DeviceHeightPair deviceHeightPair = this._deviceOffsets.FirstOrDefault((VRHeightOffset.DeviceHeightPair d) => deviceName.ToLower().Contains(d.DeviceName.ToLower()));
- if (deviceHeightPair != null)
- {
- base.transform.Translate(Vector3.up * deviceHeightPair.HeightOffset);
- }
- }
- }
- public VRHeightOffset.DeviceHeightPair[] _deviceOffsets;
- [Serializable]
- public class DeviceHeightPair
- {
- public DeviceHeightPair(string deviceName, float heightOffset)
- {
- this.DeviceName = deviceName;
- this.HeightOffset = heightOffset;
- }
- public string DeviceName;
- public float HeightOffset;
- }
- }
|