VRHeightOffset.cs
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/******************************************************************************
* Copyright (C) Leap Motion, Inc. 2011-2017. *
* Leap Motion proprietary and confidential. *
* *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
******************************************************************************/
using UnityEngine;
using System;
using System.Linq;
using Leap.Unity;
public class VRHeightOffset : MonoBehaviour {
[Serializable]
public class DeviceHeightPair {
public string DeviceName;
public float HeightOffset;
public DeviceHeightPair(string deviceName, float heightOffset) {
DeviceName = deviceName;
HeightOffset = heightOffset;
}
}
public DeviceHeightPair[] _deviceOffsets;
public KeyCode moveUpKey = KeyCode.None;
public KeyCode moveDownKey = KeyCode.None;
public float stepSize = 0.1f;
void Reset() {
_deviceOffsets = new DeviceHeightPair[1];
_deviceOffsets[0] = new DeviceHeightPair("oculus", 1f);
}
void Start() {
if (XRSupportUtil.IsXRDevicePresent()
&& XRSupportUtil.IsXREnabled()
&& _deviceOffsets != null) {
string deviceName = XRSupportUtil.GetLoadedDeviceName();
var deviceHeightPair = _deviceOffsets.FirstOrDefault(d => deviceName.ToLower().Contains(d.DeviceName.ToLower()));
if (deviceHeightPair != null) {
transform.Translate(Vector3.up * deviceHeightPair.HeightOffset);
}
}
}
private void Update() {
if (Input.GetKeyDown(moveUpKey)) {
transform.Translate(Vector3.up * stepSize);
}
if (Input.GetKeyDown(moveDownKey)) {
transform.Translate(Vector3.down * stepSize);
}
}
}