Skip to content

Commit

Permalink
Revert "Update VibrationTest.cs"
Browse files Browse the repository at this point in the history
This reverts commit ff6343f.
  • Loading branch information
PauFusco committed Jun 4, 2024
1 parent 148076e commit 7579db0
Showing 1 changed file with 18 additions and 128 deletions.
146 changes: 18 additions & 128 deletions Assets/Resources/Scripts/ScalePuzzle/VibrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,17 @@

public class VibrationTest : MonoBehaviour
{
[Range(0,1)]
public float intensity;
public float duration;

XRBaseController controller;
XRDirectInteractor controllerInteractor;

enum PulseState
{
D1,
E,
A,
D2,
}

PulseState pulseState;

float pulseTimer;
float timeBetween;
float pulseStrength;
float longPulseDuration;
float shortPulseDuration;

private void Start()
{
GetComponent<XRGrabInteractable>().selectEntered.AddListener(OnSelectEntered);
GetComponent<XRGrabInteractable>().selectExited.AddListener(OnSelectExited);

pulseTimer = 0;
timeBetween = 0.2f;
pulseStrength = 0.5f;
longPulseDuration = 0.8f;
shortPulseDuration = 0.2f;

pulseState = PulseState.D1;
}

private void OnSelectEntered(SelectEnterEventArgs args)
Expand All @@ -46,10 +26,9 @@ private void OnSelectExited(SelectExitEventArgs args)
{
controller = null;
controllerInteractor = null;

pulseState = PulseState.D1;
}

float timer = 0.0f;
private void Update()
{
if (controllerInteractor.IsSelecting(GetComponent<XRBaseInteractable>()))
Expand All @@ -60,115 +39,26 @@ private void Update()

void DoPulses()
{
switch (pulseState)
{
case PulseState.D1:
LetterD1Code();
break;
case PulseState.E:
LetterECode();
break;
case PulseState.A:
LetterACode();
break;
case PulseState.D2:
LetterD2Code();
break;
}
}

void LetterD1Code()
{
pulseTimer += Time.deltaTime;
timer += Time.deltaTime;

if (pulseTimer < longPulseDuration)
{
LongHaptic();
}

if (pulseTimer < longPulseDuration + shortPulseDuration + timeBetween && pulseTimer > longPulseDuration + timeBetween)
{
ShortHaptic();
}

if (pulseTimer < longPulseDuration + shortPulseDuration + shortPulseDuration + timeBetween * 2 && pulseTimer > longPulseDuration + shortPulseDuration + timeBetween * 2)
{
ShortHaptic();
}
else
{
pulseState = PulseState.E;
pulseTimer = 0;
}
}
if (timer > 0.5f) { TriggerHaptic(controller); }

void LetterECode()
{
pulseTimer += Time.deltaTime;

if (pulseTimer < shortPulseDuration)
{
ShortHaptic();
}
else
{
pulseState = PulseState.A;
pulseTimer = 0;
}
if (timer > 1.0f) { timer -= 1.0f; }
}

void LetterACode()
{
pulseTimer += Time.deltaTime;

if (pulseTimer < shortPulseDuration)
{
ShortHaptic();
}

if (pulseTimer < longPulseDuration + shortPulseDuration + timeBetween && pulseTimer > shortPulseDuration + timeBetween)
{
LongHaptic();
}
else
{
pulseState = PulseState.D2;
pulseTimer = 0;
}
}
//void TriggerHaptic(BaseInteractionEventArgs eventArgs)
//{
// if (eventArgs.interactorObject is XRBaseControllerInteractor controllerInteractor)
// {
// TriggerHaptic(controllerInteractor.xrController);
// }
//}

void LetterD2Code()
void TriggerHaptic(XRBaseController controller)
{
pulseTimer += Time.deltaTime;

if (pulseTimer < longPulseDuration)
if (intensity > 0)
{
LongHaptic();
controller.SendHapticImpulse(intensity, duration);
}

if (pulseTimer < longPulseDuration + shortPulseDuration && pulseTimer > longPulseDuration)
{
ShortHaptic();
}

if (pulseTimer < longPulseDuration + shortPulseDuration + shortPulseDuration && pulseTimer > longPulseDuration + shortPulseDuration)
{
ShortHaptic();
}
else
{
pulseState = PulseState.D1;
pulseTimer = 0;
}
}

void ShortHaptic()
{
controller.SendHapticImpulse(pulseStrength, shortPulseDuration);
}

void LongHaptic()
{
controller.SendHapticImpulse(pulseStrength, longPulseDuration);
}
}

0 comments on commit 7579db0

Please sign in to comment.