-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonInputs.cs
157 lines (146 loc) · 4.32 KB
/
ButtonInputs.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class ButtonInputs : MonoBehaviour
{
SteamVR_TrackedObject trackedObject;
SteamVR_Controller.Device device;
private float h;
private float v;
private float Z;
private float speed;
void Start()
{
trackedObject = GetComponent<SteamVR_TrackedObject>();
device = SteamVR_Controller.Input((int)trackedObject.index);
}
public void Initialization(float _speed)
{
speed = _speed;
}
public void MoveUp()
{
v = 1;
CheckVirtualRealityOutOfBounds();
}
public void MoveDown()
{
v = -1;
CheckVirtualRealityOutOfBounds();
}
public void MoveLeft()
{
h = -1;
CheckVirtualRealityOutOfBounds();
}
public void MoveRight()
{
h = 1;
CheckVirtualRealityOutOfBounds();
}
public void StopMoving()
{
v = 0;
h = 0;
Z = 0;
CheckVirtualRealityOutOfBounds();
}
private void CheckVirtualRealityOutOfBounds()
{
//z == (-2.66 _ 2.66) , y == (-1.2 _ 1.2) , x == (-3.6 _ 4.18)
if (transform.position.x < -3.60f)
{
Vector3 pos = transform.position;
pos.x = -3.60f;
transform.position = pos;
}
if (transform.position.x > 4.18f)
{
Vector3 pos = transform.position;
pos.x = 4.18f;
transform.position = pos;
}
if (transform.position.y > 1.20f)
{
Vector3 pos = transform.position;
pos.y = 1.20f;
transform.position = pos;
}
if(transform.position.y < -1.20f)
{
Vector3 pos = transform.position;
pos.y = -1.20f;
transform.position = pos;
}
if(transform.position.z < -2.66f)
{
Vector3 pos = transform.position;
pos.z = -2.66f;
transform.position = pos;
}
if(transform.position.z > 2.66f)
{
Vector3 pos = transform.position;
pos.z = 2.66f;
transform.position = pos;
}
}
void FixedUpdate()
{
if ((SteamVR_Controller.Input((int)trackedObject.index) != null))
{
virtualRealityController();
}
else
{
Checkkeyboard_PUSH_VirtualRealityController();
}
Vector3 moving = new Vector3(speed * h * Time.deltaTime , speed * v * Time.deltaTime ,
speed * Z * Time.deltaTime);
transform.position += moving;
CheckVirtualRealityOutOfBounds();
}
private void virtualRealityController()
{
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger) == true)
{
Debug.Log("Trigger Touch...!!!");
}
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger) == true)
{
Debug.Log("Trigger touch down...!!!");
}
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger) == true)
{
Debug.Log("Trigger touch up...!!!");
}
}
private void Checkkeyboard_PUSH_VirtualRealityController()
{
if(Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
{
MoveLeft();
}else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
{
MoveRight();
}else if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
{
MoveDown();
}else if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
{
MoveUp();
}
CheckKeyboard_PULL_VirtualRealityController();
}
private void CheckKeyboard_PULL_VirtualRealityController()
{
if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.A)
|| Input.GetKeyUp(KeyCode.RightArrow) || Input.GetKeyUp(KeyCode.D)
|| Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.W)
|| Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.S))
{
StopMoving();
}
}
}