Tanoda
HandOffsetter.cs
Go to the documentation of this file.
1
using
System.Collections;
2
using
System.Collections.Generic;
3
using
System.Text;
4
using
NaughtyAttributes;
5
using
UnityEngine
;
6
#if !UNITY_WEBGL
7
using
Valve.VR;
8
#if USE_LEAP
9
using
Leap
.
Unity
;
10
#endif
11
using
ViveHandTracking;
12
#endif
13
14
class
HandOffsetter
: MonoBehaviour
15
{
16
17
//#if !UNITY_WEBGL
18
// public HandRenderer hand;
19
// public ModelRenderer ModelRenderer;
20
// public Camera VRCam;
21
// public float multiplierX = 0.00021f;
22
// public float multiplierY = 0.0002f;
23
//#if USE_LEAP
24
// public RigidHand[] LeapHands;
25
//#endif
26
// public Transform leapZone1, leapZone2;
27
// [ProgressBar("%", 1)]
28
// public float leapOrHand = 0.0f;
29
// [SerializeField]
30
// private bool useLeap = false;
31
// [ReadOnly]
32
// [SerializeField]
33
// private bool isCosmos = false;
34
35
// void Start()
36
// {
37
// if (GetHmdTypeSteamVRToString().Contains("cosmos"))
38
// {
39
// isCosmos = true;
40
// return;
41
// }
42
// var sb = new StringBuilder(128);
43
// ETrackedPropertyError error = ETrackedPropertyError.TrackedProp_Success;
44
// for (uint i = 0; i < 12; i++)
45
// {
46
// sb.Clear();
47
// OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, sb,
48
// 128, ref error);
49
50
// if (error == ETrackedPropertyError.TrackedProp_Success)
51
// {
52
// if (sb.ToString().Contains("cosmos"))
53
// {
54
// isCosmos = true;
55
// return;
56
// }
57
// }
58
// }
59
// }
60
61
// public static string GetHmdTypeSteamVRToString()
62
// {
63
// if (SteamVR.initializedState == SteamVR.InitializedStates.InitializeSuccess)
64
// return Valve.VR.SteamVR.instance.hmd_ModelNumber;
65
66
// return "";
67
// }
68
69
// public void LeapHandFound()
70
// {
71
// useLeap = true;
72
// }
73
74
// public void LeapHandLost()
75
// {
76
// leapOrHand = 0.0f;
77
// useLeap = false;
78
// }
79
80
// void Update()
81
// {
82
// if (!hand) return;
83
// Vector3 screenPos = VRCam.WorldToScreenPoint(hand.transform.position);
84
// var left = -VRCam.transform.right;
85
// var right = VRCam.transform.right;
86
// var up = VRCam.transform.up;
87
// var down = -VRCam.transform.up;
88
// var back = -VRCam.transform.forward;
89
// var distanceMultiplier = Mathf.Min(Mathf.Max((screenPos.z * 2.2f), 0), 1);
90
// var deadZone = 100;
91
// hand.offset = Vector3.zero;
92
// ModelRenderer.offset = Vector3.zero;
93
//#if USE_LEAP
94
// if (useLeap)
95
// {
96
// var hand1Dist = Vector3.Distance(LeapHands[0].palm.position, ModelRenderer.transform.position);
97
// var hand2Dist = Vector3.Distance(LeapHands[1].palm.position, ModelRenderer.transform.position);
98
99
// ModelRenderer.leapHand = hand1Dist < hand2Dist ? LeapHands[0].palm : LeapHands[1].palm;
100
101
// //leapOrHand = LeapHand.GetLeapHand().Confidence; //nem jó, mindíg 1 vagy 0
102
// //ModelRenderer.leapPercent = LeapHand.GetLeapHand().Confidence;
103
104
// var dist1 = 0f;
105
// var dist2 = 0f;
106
107
// if (Vector3.Distance(leapZone1.position, ModelRenderer.leapHand.position) <= leapZone1.localScale.x)
108
// {
109
// var dist = Vector3.Distance(leapZone1.position, ModelRenderer.leapHand.position);
110
// dist1 = Mathf.Abs(1 - (dist / leapZone1.localScale.x));
111
// }
112
113
// if (Vector3.Distance(leapZone2.position, ModelRenderer.leapHand.position) <= leapZone2.localScale.x)
114
// {
115
// var dist = Vector3.Distance(leapZone2.position, ModelRenderer.leapHand.position);
116
// dist2 = Mathf.Abs(1 - (dist / leapZone2.localScale.x));
117
// }
118
119
// leapOrHand = dist1 > dist2 ? dist1 : dist2;
120
// ModelRenderer.leapPercent = leapOrHand;
121
122
// }
123
// else
124
//#endif
125
// {
126
// ModelRenderer.leapPercent = 0;
127
// }
128
129
// if (isCosmos)
130
// {
131
// return;
132
// }
133
// if (VRCam.pixelWidth / 2 - deadZone > screenPos.x)
134
// {
135
// hand.offset += left * (Mathf.Abs(VRCam.pixelWidth / 2 - deadZone - Mathf.Min(Mathf.Max(0, screenPos.x), VRCam.pixelWidth / 2 - deadZone)) * multiplierX);
136
// ModelRenderer.offset += left * (Mathf.Abs(VRCam.pixelWidth / 2 - deadZone - Mathf.Min(Mathf.Max(0, screenPos.x), VRCam.pixelWidth / 2 - deadZone)) * multiplierX);
137
// }
138
139
// if (VRCam.pixelWidth / 2 + deadZone < screenPos.x)
140
// {
141
// hand.offset += right * (Mathf.Abs(VRCam.pixelWidth / 2 + deadZone - Mathf.Min(Mathf.Max(VRCam.pixelWidth / 2 + deadZone, screenPos.x), VRCam.pixelWidth)) * multiplierX);
142
// ModelRenderer.offset += right * (Mathf.Abs(VRCam.pixelWidth / 2 + deadZone - Mathf.Min(Mathf.Max(VRCam.pixelWidth / 2 + deadZone, screenPos.x), VRCam.pixelWidth)) * multiplierX);
143
// }
144
145
// if (VRCam.pixelHeight / 2 - deadZone > screenPos.y)
146
// {
147
// hand.offset += down * (Mathf.Abs(VRCam.pixelHeight / 2 - deadZone - Mathf.Min(Mathf.Max(0, screenPos.y), VRCam.pixelHeight / 2 - deadZone)) * multiplierY);
148
// ModelRenderer.offset += down * (Mathf.Abs(VRCam.pixelHeight / 2 - deadZone - Mathf.Min(Mathf.Max(0, screenPos.y), VRCam.pixelHeight / 2 - deadZone)) * multiplierY);
149
// }
150
151
// if (VRCam.pixelHeight / 2 + deadZone < screenPos.y)
152
// {
153
// hand.offset += up * (Mathf.Abs(VRCam.pixelHeight / 2 + deadZone - Mathf.Min(Mathf.Max(VRCam.pixelHeight / 2 + deadZone, screenPos.y), VRCam.pixelHeight)) * multiplierY);
154
// ModelRenderer.offset += up * (Mathf.Abs(VRCam.pixelHeight / 2 + deadZone - Mathf.Min(Mathf.Max(VRCam.pixelHeight / 2 + deadZone, screenPos.y), VRCam.pixelHeight)) * multiplierY);
155
// }
156
157
// //Debug.Log("Distance: " + screenPos.z); //max ~0.5
158
159
// hand.offset += back * (Mathf.Max(0, distanceMultiplier - 0.5f) / 10);
160
// ModelRenderer.offset += back * (Mathf.Max(0, distanceMultiplier - 0.5f) / 10);
161
162
// hand.offset *= distanceMultiplier;
163
// ModelRenderer.offset *= distanceMultiplier;
164
// }
165
//#endif
166
}
HandOffsetter
Definition:
HandOffsetter.cs:15
Leap.Unity
Definition:
AssetFolderPropertyDrawer.cs:15
Leap
Definition:
AssetFolderPropertyDrawer.cs:15
UnityEngine
Definition:
HSVPicker/UtilityScripts/BoxSlider.cs:7
Source
Assets
Scripts
HandOffsetter.cs
Generated by
1.9.3