Ejemplo n.º 1
0
        /// <summary>
        /// Takes an impulse and plays it with the ImpulseDemo's parameters.
        /// This takes an impulse so you don't need to instantiate one every time.
        /// If you're doing the same impulse regularly, it saves traversal/breadth first searching
        /// </summary>
        /// <param name="imp">A constructed impulse of the emanation or traversal</param>
        private void ConfigureAndPlayImpulse(ImpulseGenerator.Impulse imp)
        {
            if (CurrentMode == ImpulseType.Emanating)
            {
                StartCoroutine(ColorSuitForEmanation());
            }
            else
            {
                StartCoroutine(ColorSuitForTraversal());
            }

            //To support CodeSequence Samples
            if (SelectedCodeSequence < 0)
            {
                //These are broken up by lines for readability
                imp.WithDuration(ImpulseDuration);
                imp.WithAttenuation(Attenuation);
                imp.WithEffect(effectOptions[currentEffect], EffectDuration, EffectStrength);
                imp.Play();

                //You can do something like:
                //i.WithAttenuation(Attenuation).WithDuration(ImpulseDuration).WithEffect(effectOptions[CurrentEffect], EffectDuration, EffectStrength).Play();
                //Chaining and Functional Programming!
            }
            else
            {
                //These are broken up by lines for readability
                imp.WithDuration(ImpulseDuration);
                imp.WithAttenuation(Attenuation);
                imp.WithEffect(GetCodeSequence());
                imp.Play();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Repeatedly calls impulse.Play after X delay Y times.
        /// This sample DOES work. It will get baked into the Impulse's functionality later.
        /// </summary>
        /// <param name="impulse">The impulse to repeat</param>
        /// <param name="delay">How long AFTER the previous one do you want to start the next one</param>
        /// <param name="count">How many times you want to play it. (Ideally you should call .Play before you call RepeatedEmanations, otherwise it won't start when you start this coroutine.)</param>
        /// <returns></returns>
        IEnumerator RepeatedEmanations(ImpulseGenerator.Impulse impulse, float delay, int count)
        {
            impulse.Play();
            for (int i = 0; i < count - 1; i++)
            {
                yield return(new WaitForSeconds(delay));

                impulse.Play();
            }
        }
Ejemplo n.º 3
0
        //
        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;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Takes an impulse and plays it with the ImpulseDemo's parameters.
        /// This takes an impulse so you don't need to instantiate one every time.
        /// If you're doing the same impulse regularly, it saves traversal/breadth first searching
        /// </summary>
        /// <param name="imp">A constructed impulse of the emanation or traversal</param>
        private void ConfigureAndPlayImpulse(ImpulseGenerator.Impulse imp)
        {
            if (CurrentMode == ImpulseType.Emanating)
            {
                StartCoroutine(ColorSuitForEmanation());
            }
            else
            {
                StartCoroutine(ColorSuitForTraversal());
            }

            //To support HapticSequence Samples
            if (UseEffectSelectorSlider)
            {
                //Prevent array index out of bounds errors.
                Effect whichEffect = effectOptions[Mathf.Clamp(currentEffect, 0, effectOptions.Length - 1)];

                //These are broken up by lines for readability
                imp.WithDuration(ImpulseDuration);
                imp.WithAttenuation(Attenuation);
                imp.WithEffect(whichEffect, EffectDuration, EffectStrength);
                imp.Play();

                //You can do something like:
                //i.WithAttenuation(Attenuation).WithDuration(ImpulseDuration).WithEffect(effectOptions[CurrentEffect], EffectDuration, EffectStrength).Play();
                //Chaining and Functional Programming!
            }
            else
            {
                //These are broken up by lines for readability
                imp.WithDuration(ImpulseDuration);
                imp.WithAttenuation(Attenuation);
                imp.WithEffect(GetHapticSequence());
                imp.Play();
            }
        }
Ejemplo n.º 5
0
        /// <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.
        }