private void ClickedSuitInTraversalMode(SuitBodyCollider clicked, RaycastHit hit) { //None are currently selected if (ImpulseOrigin == null) { //Select first ImpulseOrigin = clicked; //Mark it as selected ColorSuit(clicked, OriginColor); } //First one is already selected else { //If we click back on the first node. if (ImpulseOrigin == clicked) { //Unselect First ColorSuit(clicked, unselectedColor); ImpulseOrigin = null; //If we had a destination if (ImpulseDestination != null) { //Clear it. ColorSuit(ImpulseDestination, unselectedColor); ImpulseDestination = null; } } else { //If we had a destination (from last play) if (ImpulseDestination != null) { //Clear it to avoid leaving unnecessary colored nodes ColorSuit(ImpulseDestination, unselectedColor); ImpulseDestination = null; } //Set our destination ImpulseDestination = clicked; ColorSuit(clicked, OriginColor); //Leftover log to see that we're playing from the start to end. //Debug.Log((int)TraversalOrigin.regionID + "\t " + (int)suit.regionID); //Play Impulse from the origin to our brand new destination. ImpulseGenerator.Impulse imp = ImpulseGenerator.BeginTraversingImpulse(ImpulseOrigin.regionID, clicked.regionID); //Then play it ConfigureAndPlayImpulse(imp); } } }
private void Start() { Effect whichEffect = Effect.Pulse; //What's more electrical than pulses. float totalImpulseDuration = .35f; //How long does the shock take to traverse to the heart. float effectDuration = 0.0f; //0.0 defaults to the natural duration of the pulse effect. float effectStrength = 1; //How strong is the pulse effect //Create the Impulse object (which can be told to play, which instantiates what it 'is') shockImpulse = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Forearm_Right, AreaFlag.Chest_Left); // This sets the duration to be .25 seconds shockImpulse.WithDuration(totalImpulseDuration); //This defines the base effect (which needs an effect name, a strength and a duration) shockImpulse.WithEffect(whichEffect, effectDuration, effectStrength); }
/// <summary> /// This is a simple handful of lines. This plays when Walter (the giant red scorpion of player murdering) lands on the ground. /// This sample DOES work. /// The intention is to give an effect that goes up the body. /// It has been slightly adapted to take different effect families (click, double-click, hum, etc) /// </summary> public static void GiantScorpionLanding(string effect = "buzz") { //TWo different Impulses are used here even though the same one could be re-assigned. Two variables are more readable at neglible CPU cost. ImpulseGenerator.Impulse leftUp = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Lower_Ab_Left, AreaFlag.Forearm_Left) .WithDuration(0.5f) .WithEffect(effect, 0.1f, 1.0f); ImpulseGenerator.Impulse rightUp = ImpulseGenerator.BeginTraversingImpulse(AreaFlag.Lower_Ab_Right, AreaFlag.Forearm_Right) .WithDuration(0.5f) .WithEffect(effect, 0.1f, 1.0f); //Don't forget to play the effects leftUp.Play(); rightUp.Play(); //We could HapticHandle[] if we wanted to stop these prematurely - however they're very short effects, so it's unlikely that will be needed. //HapticHandle's can be Stopped or restarted until they (Finish playing AND go out of scope), after that they're gone. }
/// <summary> /// This is the Impulse that was used for the Desert of Danger recoil effect. /// It is imperfect in the implementation because it doesn't allow for flexibility to pick the effect. /// It could also take a more flexible Duration component but the core here is to give you what we used. /// Use ImpulseGenerator.CreateImpulse() function instead of modifying this. /// This sample does work. /// </summary> /// <param name="StartLocation">Pick the location to begin. DO NOT PROVIDE MULTIPLE AREAS.</param> /// <param name="EndLocation">Pick the destination to reach. DO NOT PROVIDE MULTIPLE AREAS.</param> /// <returns>Don't forget to call .Play() on the returned Impulse to create an instance of the haptic effect it defines.</returns> public static ImpulseGenerator.Impulse DesertOfDangerRecoil(AreaFlag StartLocation = AreaFlag.Forearm_Left, AreaFlag EndLocation = AreaFlag.Upper_Arm_Left) { //A simple code sequence CodeSequence seq = new CodeSequence(); //The elements we will add CodeEffect eff = new CodeEffect("buzz", 0.00f, 1.0f); CodeEffect eff2 = new CodeEffect("buzz", 0.15f, 0.5f); //The time stamps of the different effects. seq.AddEffect(0, eff); seq.AddEffect(.1, eff2); //In Desert of Danger, we used a duration of .1 seconds. This means the recoil effect took .1 seconds to hit ALL pads it aimed to. If you hand in different pads, it'll likely want a longer duration. //Since we only used the forearm and the upper arm, .1s is more than sufficient. //We could've used a file for this, but this was right as we were conceptualizing and beginning the usage of the ImpulseGenerator. return(ImpulseGenerator.BeginTraversingImpulse(StartLocation, EndLocation) .WithDuration(.10f) .WithEffect(seq)); }