-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrabbableMuteButton.cs
220 lines (160 loc) · 6.51 KB
/
GrabbableMuteButton.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrabbableMuteButton : MonoBehaviour
{
public bool MuteButtonActivated;
//*** Grabbable object properties
private OVRGrabbable grabbablePowerup;
private const string grabberLeftName = "DistanceGrabHandLeft";
private const string grabberRightName = "DistanceGrabHandRight";
private bool firstgrabbed;
private float firingRateTimer;
private float firingRate = .1f;
private float YRotation;
private Vector3 YRotAngle;
private bool rightHandGrab;
private Vector3 LeftGrabRotation;
public GameObject highLightParticle;
public List<AudioSource> additionalAudioSources;
// Start is called before the first frame update
void Start()
{
grabbablePowerup = this.gameObject.GetComponent<OVRGrabbable>();
//*** Set gun data with brief delay based on weapons database parameters
Invoke("InitializePowerupType", .15f);
}
public void InitializePowerupType()
{
}
// Update is called once per frame
void Update()
{
if (grabbablePowerup != null)
{
if (grabbablePowerup.isGrabbed)
{
if (highLightParticle != null)
{
if (highLightParticle.active)
highLightParticle.SetActive(false);
}
grabbablePowerup.transform.position = grabbablePowerup.grabbedBy.gameObject.transform.position;
// Change the scale of the game object grabbed to appear more to scale with the player.
gameObject.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
//grabbbleWeapon.transform.localEulerAngles = defaultGrabRotation;
//*** Check if Right hand grabbed blaster
rightHandGrab = (grabbablePowerup.grabbedBy.gameObject.name == grabberRightName);
if (rightHandGrab)
{
grabbablePowerup.transform.rotation = grabbablePowerup.grabbedBy.gameObject.transform.rotation;
}
else
{
/*LeftGrabRotation = new Quaternion(
grabbbleWeapon.grabbedBy.gameObject.transform.rotation.x,
grabbbleWeapon.grabbedBy.gameObject.transform.rotation.y,
grabbbleWeapon.grabbedBy.gameObject.transform.rotation.z * -1,
grabbbleWeapon.grabbedBy.gameObject.transform.rotation.w);*/
LeftGrabRotation = new Vector3(
grabbablePowerup.grabbedBy.gameObject.transform.eulerAngles.x,
grabbablePowerup.grabbedBy.gameObject.transform.eulerAngles.y,
grabbablePowerup.grabbedBy.gameObject.transform.eulerAngles.z + 180);
grabbablePowerup.transform.eulerAngles = LeftGrabRotation;
}
/* grabbbleWeapon.transform.position = grabbbleWeapon.grabbedBy.gameObject.transform.position;
grabbbleWeapon.transform.rotation = grabbbleWeapon.grabbedBy.gameObject.transform.rotation;*/
EvaluateTriggerPull(rightHandGrab);
}
}
}
public void EvaluateTriggerPull(bool pIsrightHand)
{
//*** Left Trigger Pull
//OVRInput.Get(OVRInput.RawButton.LHandTrigger)
if (pIsrightHand == false)
{
if (grabbablePowerup.grabbedBy.name == grabberLeftName)
{
if (OVRInput.Get(OVRInput.RawButton.LIndexTrigger) == false)
{
//*** Weapon not fired
MuteButtonActivated = false;
StopAllCoroutines();
}
//*** Fire Left hand weapon
if (OVRInput.Get(OVRInput.RawButton.LIndexTrigger) == true && MuteButtonActivated == false)
{
MuteButtonActivated = true;
OVRInput.SetControllerVibration(1f, 1f, OVRInput.Controller.LTouch);
StopControllerVibration(true, .2f);
ActivateMutebutton();
}
/*if (OVRInput.Get(OVRInput.RawButton.LIndexTrigger) == true
&& firedWeapon == true)
{
firedWeapon = false;
FireLaser();
}*/
}
}
else
{
//*** Right Trigger Pull
if (grabbablePowerup.grabbedBy.name == grabberRightName)
{
if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger) == false)
{
//*** Weapon not fired
MuteButtonActivated = false;
StopAllCoroutines();
//StopCoroutine(FireNextShell(0f));
}
//*** Fire right hand weapon
if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger) == true && MuteButtonActivated == false)
{
OVRInput.SetControllerVibration(1f, 1f, OVRInput.Controller.RTouch);
StopControllerVibration(false, .2f);
MuteButtonActivated = true;
ActivateMutebutton();
}
/*if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger) == true && firedWeapon == true)
{
firedWeapon = false;
FireLaser();
}*/
}
}
}
//*** Weapon fire Functions
public void ActivateMutebutton()
{
AudioManager.instance.PlayAudio(AudioData.audioClipType.Confirm_Click,this.gameObject.transform,0f,1f);
//*** Increment Kill count
AudioManager.instance.MuteAllMusicObjects();
for(int i = 0; i < additionalAudioSources.Count; i++)
{
additionalAudioSources[i].volume = 0f;
}
}
//**** Weapon Vibration functions
public void StopControllerVibration(bool pIsLeftcontroller, float ptimeDelay = 0f)
{
if (pIsLeftcontroller)
{
Invoke("StopControllerVibrationLeft", ptimeDelay);
}
else
{
Invoke("StopControllerVibrationRight", ptimeDelay);
}
}
public void StopControllerVibrationLeft()
{
OVRInput.SetControllerVibration(0f, 0f, OVRInput.Controller.LTouch);
}
public void StopControllerVibrationRight()
{
OVRInput.SetControllerVibration(0f, 0f, OVRInput.Controller.RTouch);
}
}