private HapticHandle CreateHandle(SideOfHaptic side) { HapticHandle handle = null; if (TypeOfPlayable == PlayableType.Sequence) { HapticSequence seq = new HapticSequence(); seq.LoadFromAsset(PlayableResourceName); var areaFlag = side == SideOfHaptic.Left ? Where.Mirror() : Where; handle = seq.CreateHandle(areaFlag); } else if (TypeOfPlayable == PlayableType.Pattern) { HapticPattern pat = new HapticPattern(); pat.LoadFromAsset(PlayableResourceName); handle = pat.CreateHandle(); } else if (TypeOfPlayable == PlayableType.Experience) { HapticExperience exp = new HapticExperience(); exp.LoadFromAsset(PlayableResourceName); handle = exp.CreateHandle(); } else if (TypeOfPlayable == PlayableType.Impulse) { return(CreateImpulseHandle(side)); } return(handle); }
// IEnumerator ShockPlayer() { //This serves as the 'Is Coroutine Running' variable CurrentlyShocking = true; //This is a construct for our repetition of the traversal effect. float delay = .4f; //Prevent the loop/effect from running forever. int breakout = 0; //A handle for canceling the shock when the condition is no longer true. HapticHandle shockHandle = null; //This is the loop that will re-start the impulse //Remember that CurrentShocking is a bool from outside this function. Meaning it can be turned off and then we leave the loop. while (CurrentlyShocking && breakout < 25) { //Finally, don't forget to play the effect. shockHandle = shockImpulse.Play(); //Wait before the next zap yield return(new WaitForSeconds(delay)); //Max of X Zaps. breakout++; } //If we stop shocking the player, we want to clean up the last effect played. This means when the player stops touching the outlet, they stop getting shocked. shockHandle.Stop(); //Mark that we aren't shocking the player. CurrentlyShocking = false; }
private void BowFullyDrawnHaptic() { if (HapticEffectWhenDrawAndReleased) { if (currentPull > maxPullDistance * pulledHapticPullThreshold && !pulled) { pulled = true; var impulse = ImpulseGenerator.BeginEmanatingEffect(WhichSide, 2); impulse.WithEffect(hapticOnDrawback).WithDuration(.25f).WithAttenuation(.5f); pulledHandle = impulse.Play(); } else if (currentPull > maxPullDistance * pulledHapticPullThreshold && pulled) { pulledHapticCounter += Time.deltaTime; if (pulledHapticCounter > .25f) { pulledHapticCounter = 0; pulledHandle.Replay(); } } else if (currentPull < maxPullDistance * pulledHapticPullThreshold * .5f) { pulled = false; } } }
public void Play() { if (ReadyToPlay) { handle = MyHaptic.TryToPlayPlay(SideOfHaptic.Right); ResetDelayBetweenPlay(); } }
public void Play(SideOfHaptic side) { if (ReadyToPlay) { //Debug.Log(side.ToString() + "\n", this); handle = MyHaptic.TryToPlayPlay(side); ResetDelayBetweenPlay(); } }
public static void RemoveAllRepeatedHaptic(GameObject target, HapticHandle handle) { RepeatedHaptic repeatHaptic = target.GetComponent <RepeatedHaptic>(); if (repeatHaptic != null) { Destroy(repeatHaptic); } }
void Start() { myRB = GameObject.Find("Haptic Trigger").GetComponent <Rigidbody>(); //var a = new Sequence("ns.basic.click_click_click"); //a.CreateHandle(AreaFlag.All_Areas).Play(); clicker = new Sequence("ns.demos.five_second_hum"); clickerHandle = clicker.CreateHandle(AreaFlag.All_Areas); //clicker.CreateHandle(AreaFlag.All_Areas).Play(); }
private void Start() { hapticOnDrawback.LoadFromAsset(drawHaptic); hapticOnRelease.LoadFromAsset(releaseHaptic); hapticwhilePulled.LoadFromAsset(pulledHapticName); pulledHandle = hapticwhilePulled.CreateHandle(); bowAnimation = GetComponent <BowAnimation>(); handle = GetComponentInChildren <BowHandle>(); interact = GetComponent <VRTK_InteractableObject>(); interact.InteractableObjectGrabbed += new InteractableObjectEventHandler(DoObjectGrab); }
//Make this return a bool and it'll mark the LibraryElement as broken. public bool ExecuteLibraryElement() { if (FileHasBeenModified()) { MarkElementChanged(); } //Debug.Log("File has been modified since load: [" + FileHasBeenModified() + "]\n"); try { HapticHandle newHandle = null; if (LibraryManager.Inst.LastPlayed != null && LibraryManager.Inst.StopLastPlaying) { LibraryManager.Inst.LastPlayed.Pause(); LibraryManager.Inst.LastPlayed.Dispose(); } //Get the file path //Debug.Log("[" + myNamespace + "] [" + fileName + "]\n" + myNamespace + "" + fileName); if (myType == LibraryElementType.Sequence) { //If sequence, use the specific pads selected (unsupported atm) AreaFlag flag = LibraryManager.Inst.GetActiveAreas(); newHandle = new Sequence(myNamespace + fileName).CreateHandle(flag); LibraryManager.Inst.SetTriggerSequence(myNamespace + fileName); } if (myType == LibraryElementType.Pattern) { newHandle = new Pattern(myNamespace + fileName).CreateHandle(); } if (myType == LibraryElementType.Experience) { newHandle = new Experience(myNamespace + fileName).CreateHandle(); } LibraryManager.Inst.LastPlayed = newHandle; if (LibraryManager.Inst.LastPlayed != null) { LibraryManager.Inst.LastPlayed.Play(); } } catch (Exception e) { Debug.LogError("Failed to play haptic [" + fullFilePath + "]" + "\n" + e.Message); return(false); } return(true); }
public static RepeatedHaptic AddRepeatedHaptic(GameObject target, HapticHandle handle) { RepeatedHaptic repeatHaptic = target.AddComponent <RepeatedHaptic>(); return(repeatHaptic); }
//Make this return a bool and it'll mark the LibraryElement as broken. public bool ExecuteLibraryElement() { if (FileHasBeenModified()) { MarkElementChanged(); } //Debug.Log("File has been modified since load: [" + FileHasBeenModified() + "]\n"); try { HapticHandle newHandle = null; if (LibraryManager.Inst.LastPlayed != null && LibraryManager.Inst.StopLastPlaying) { LibraryManager.Inst.LastPlayed.Stop(); //Todo: implement dispose again // LibraryManager.Inst.LastPlayed } Action <HapticHandle> playHandleAndSetLastPlayed = delegate(HapticHandle h) { LibraryManager.Inst.LastPlayed = h; if (LibraryManager.Inst.LastPlayed != null) { LibraryManager.Inst.LastPlayed.Play(); } }; //Get the file path //Debug.Log("[" + myNamespace + "] [" + fileName + "]\n" + myNamespace + "" + fileName); if (myType == LibraryElementType.Sequence) { GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf) { var seq = CodeHapticFactory.CreateSequence(hdf.rootEffect.name, hdf); //If sequence, use the specific pads selected (unsupported atm) AreaFlag flag = LibraryManager.Inst.GetActiveAreas(); LibraryManager.Inst.SetTriggerSequence(myNamespace + fileName); playHandleAndSetLastPlayed(seq.CreateHandle(flag)); }); } if (myType == LibraryElementType.Pattern) { GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf) { var pat = CodeHapticFactory.CreatePattern(hdf.rootEffect.name, hdf); playHandleAndSetLastPlayed(pat.CreateHandle()); }); } if (myType == LibraryElementType.Experience) { GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf) { var exp = CodeHapticFactory.CreateExperience(hdf.rootEffect.name, hdf); playHandleAndSetLastPlayed(exp.CreateHandle()); }); } } catch (Exception e) { Debug.LogError("Failed to play haptic [" + fullFilePath + "]" + "\n" + e.Message); return(false); } return(true); }