コード例 #1
0
        /// <summary>
        /// A VERY random effect. More just for showing haptic varion
        /// </summary>
        /// <param name="randSeed"></param>
        /// <returns></returns>
        public static CodeSequence VeryRandomEffect(int randSeed)
        {
            //Debug.Log(randSeed + "\n");
            System.Random rand = new System.Random(randSeed);

            CodeSequence seq = new CodeSequence();

            int effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length);

            float      dur    = ((float)rand.Next(0, 6)) / 3;
            float      delay  = 0;
            float      offset = 0;
            CodeEffect eff    = null;

            int HowManyEffects = rand.Next(2, 11);

            //Debug.Log("How many effects: " + HowManyEffects + "\n");
            for (int i = 0; i < HowManyEffects; i++)
            {
                effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length);
                dur      = ((float)rand.Next(0, 6)) / 3;
                delay    = ((float)rand.Next(0, 8)) / 20;
                eff      = new CodeEffect(SuitImpulseDemo.effectOptions[effIndex], dur, ((float)rand.Next(0, 10)) / 10);
                seq.AddEffect(offset + delay, eff);
                offset = dur;
            }

            return(seq);
        }
コード例 #2
0
        /// <summary>
        /// Creates an array of RmtItems from a Pronto code.
        /// </summary>
        /// <param name="code">A string containing the Pronto code</param>
        /// <param name="sequence">The code sequence to return. Defaults to <c>Once</c>.</param>
        /// <param name="clockDivider">The RMT clock divider, used to determine the number of RMT ticks per microsecond. Defaults to 80.</param>
        /// <returns></returns>
        public static RmtItem[] Pronto2RmtItems(string code, CodeSequence sequence = CodeSequence.Once, byte clockDivider = 80)
        {
            if (string.IsNullOrEmpty(code))
            {
                throw new ArgumentNullException("code");
            }

            int clockFrequency = 80_000_000;


            var ticksPerMicroSecond = clockFrequency / clockDivider / 1_000_000;

            var pronto = new ProntoCode(code);

            RmtItem[] returnArray = null;

            switch (sequence)
            {
            case CodeSequence.Once:
                returnArray = getRmtItems(pronto.OnceSequenceBurstPairs, pronto.OnceSequence, ticksPerMicroSecond);
                break;

            case CodeSequence.Repeat:
                returnArray = getRmtItems(pronto.RepeatSequenceBurstPairs, pronto.RepeatSequence, ticksPerMicroSecond);
                break;
            }

            return(returnArray);
        }
コード例 #3
0
        /// <summary>
        /// Creating a randomized code sequence is totally doable.
        /// This is a less than ideal approach (because static method)
        /// In your code you shouldn't use a static method like this (Do as I say, not as I do)
        /// </summary>
        /// <param name="randSeed">Hand in a random seed (or better yet, don't use random in static functions</param>
        /// <returns>A CodeSequence reference for use in Impulses</returns>
        public static CodeSequence RandomPulses(int randSeed)
        {
            //Debug.Log(randSeed + "\n");
            System.Random rand = new System.Random(randSeed);

            CodeSequence seq = new CodeSequence();

            float      dur   = ((float)rand.Next(0, 15)) / 10;
            float      delay = ((float)rand.Next(0, 10)) / 20;
            CodeEffect eff   = new CodeEffect("pulse", dur, ((float)rand.Next(0, 10)) / 10);

            seq.AddEffect(0.0, eff);
            float offset = dur;

            dur   = ((float)rand.Next(0, 15)) / 20;
            delay = ((float)rand.Next(0, 8)) / 20;
            //Debug.Log(dur + "\n");
            eff = new CodeEffect("pulse", dur, ((float)rand.Next(0, 10)) / 10);
            seq.AddEffect(offset + delay, eff);
            offset = dur;

            dur   = ((float)rand.Next(0, 15)) / 20;
            delay = ((float)rand.Next(0, 8)) / 20;
            //Debug.Log(dur + "\n");
            eff = new CodeEffect("pulse", dur, ((float)rand.Next(0, 10)) / 10);
            seq.AddEffect(offset + delay, eff);

            return(seq);
        }
コード例 #4
0
        public static CodeSequence ClickStorm()
        {
            CodeSequence seq = new CodeSequence();

            CodeEffect eff = new CodeEffect("double_click", .0f, 1.0f);

            seq.AddEffect(0, eff);

            eff = new CodeEffect("click", .0f, 1.0f);
            seq.AddEffect(0.1, eff);

            eff = new CodeEffect("long_double_sharp_tick", .0f, 1.0f);
            seq.AddEffect(0.2, eff);

            eff = new CodeEffect("sharp_click", .0f, 1.0f);
            seq.AddEffect(0.3, eff);

            eff = new CodeEffect("sharp_tick", .0f, 1.0f);
            seq.AddEffect(0.4, eff);

            eff = new CodeEffect("short_double_click", .0f, 1.0f);
            seq.AddEffect(0.5, eff);

            eff = new CodeEffect("short_double_sharp_tick", .0f, 1.0f);
            seq.AddEffect(0.6, eff);

            eff = new CodeEffect("triple_click", .0f, 1.0f);
            seq.AddEffect(0.7, eff);

            return(seq);
        }
コード例 #5
0
    void OnCollisionEnter(Collision collision)
    {
        var seq = new CodeSequence();

        //  seq.AddEffect(0.0, new CodeEffect("double_click", 1 - (playerHealth / playerMaxHealth), (playerMaxHealth / playerHealth)));
        seq.AddEffect(0.0, new CodeEffect("double_click", 0.9f));
        seq.Play(AreaFlag.All_Areas);
    }
コード例 #6
0
 /// <summary>
 /// Sets and overwrites this Impulse's current Sequence
 /// </summary>
 /// <param name="seq"></param>
 /// <returns></returns>
 public Impulse WithEffect(CodeSequence seq)
 {
     if (seq == null)
     {
         throw new ArgumentException("Attempted to assign a null CodeSequence seq - retaining previous CodeSequence", "seq");
     }
     this.seq = seq;
     return(this);
 }
コード例 #7
0
        public static CodeSequence ClickHum()
        {
            CodeSequence seq = new CodeSequence();
            CodeEffect   eff = new CodeEffect("click", 0.0f, 1.0f);

            seq.AddEffect(0, eff);
            eff = new CodeEffect("hum", .2f, .5f);
            seq.AddEffect(.15, eff);
            return(seq);
        }
コード例 #8
0
        public static CodeSequence ThockClunk()
        {
            CodeSequence seq = new CodeSequence();
            CodeEffect   eff = new CodeEffect("sharp_click", 0.15f, 1.0f);

            seq.AddEffect(0, eff);
            eff = new CodeEffect("fuzz", .2f, 1.0f);
            seq.AddEffect(.15, eff);
            return(seq);
        }
コード例 #9
0
    IEnumerator MyHeartbeat()
    {
        IsHeartBeating = true;
        var seq = new CodeSequence();

        //seq.AddEffect(0.0, new CodeEffect("double_click", 1 - (playerHealth / playerMaxHealth), (playerMaxHealth / playerHealth)));
        seq.AddEffect(0.0, new CodeEffect("double_click", 0.6f));
        while (IsHeartBeating)
        {
            seq.Play(AreaFlag.Chest_Left);
            yield return(new WaitForSeconds(1.0f));
            //yield return new WaitForSeconds((playerHealth / playerMaxHealth));
        }
    }
コード例 #10
0
        public static CodeSequence DoubleClickImpact()
        {
            CodeSequence seq = new CodeSequence();
            CodeEffect   eff = new CodeEffect("double_click", 0.00f, 1.0f);

            seq.AddEffect(0, eff);
            eff = new CodeEffect("buzz", .05f, 1.0f);
            seq.AddEffect(.05, eff);
            eff = new CodeEffect("buzz", .10f, .6f);
            seq.AddEffect(.10, eff);
            eff = new CodeEffect("buzz", .15f, .2f);
            seq.AddEffect(.2, eff);

            return(seq);
        }
コード例 #11
0
        public static CodeSequence TripleClickFuzzFalloff()
        {
            CodeSequence seq = new CodeSequence();

            CodeEffect eff = new CodeEffect("triple_click", 0.20f, 0.7f);

            seq.AddEffect(0.0, eff);

            eff = new CodeEffect("fuzz", .20f, 1.0f);
            seq.AddEffect(0.2, eff);

            eff = new CodeEffect("fuzz", .20f, 0.5f);
            seq.AddEffect(0.4, eff);

            return(seq);
        }
コード例 #12
0
        public static CodeSequence PulseBumpPulse()
        {
            CodeSequence seq = new CodeSequence();

            CodeEffect eff = new CodeEffect("pulse", 0.40f, 0.7f);

            seq.AddEffect(0.0, eff);

            eff = new CodeEffect("bump", .0f, 1.0f);
            seq.AddEffect(0.40, eff);

            eff = new CodeEffect("pulse", 0.0f, 0.2f);
            seq.AddEffect(0.55, eff);

            return(seq);
        }
コード例 #13
0
        public static CodeSequence ClickHumDoubleClick()
        {
            CodeSequence seq = new CodeSequence();

            CodeEffect eff = new CodeEffect("click", 0.0f, 1.0f);

            seq.AddEffect(0, eff);

            eff = new CodeEffect("transition_hum", .50f, 1.0f);
            seq.AddEffect(0.10, eff);

            eff = new CodeEffect("double_click", .0f, 1.0f);
            seq.AddEffect(0.6, eff);

            return(seq);
        }
コード例 #14
0
        /// <summary>
        /// Shoots the player body somewhere with a simple buzz emanation impulse.
        /// </summary>
        /// <param name="ShotWhere">Self explanator. 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 DesertOfDangerShot(AreaFlag ShotWhere = AreaFlag.Chest_Right)
        {
            CodeSequence seq = new CodeSequence();

            //This will be slightly different then the default "buzz" effect Impulse. If you ask for an effect with a duration of 0, it'll play the natural duration.
            //Natural durations range from .05s (click, buzz, etc) to .25s (the multiple click families)
            //So by providing a duration of .1, this will be slightly different than the line:
            //		CodeEffect eff = new CodeEffect("buzz", 0.00f, 1.0f);

            CodeEffect eff = new CodeEffect("buzz", 0.10f, 1.0f);

            seq.AddEffect(0, eff);

            //The Desert of Danger demo set the entire impulse duration to .25s,
            //this means that it emanated out from where the playerwas hit.
            return(ImpulseGenerator.BeginEmanatingEffect(ShotWhere)
                   .WithEffect(seq)
                   .WithDuration(.25f));
        }
コード例 #15
0
        /// <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));
        }
コード例 #16
0
        public HapticHandle CreateCodeHaptic()
        {
            //Debug.Log("Hit\n");
            CodeSequence seq = new CodeSequence();

            seq.AddEffect(0.0f, new CodeEffect("buzz", .2f));
            seq.AddEffect(0.3f, new CodeEffect("click", 0.0f));
            //seq.Play(AreaFlag.All_Areas);

            CodePattern pat = new CodePattern();

            pat.AddSequence(0.5f, AreaFlag.Lower_Ab_Both, seq);
            pat.AddSequence(1.0f, AreaFlag.Mid_Ab_Both, seq);
            pat.AddSequence(1.5f, AreaFlag.Upper_Ab_Both, seq);
            pat.AddSequence(2.0f, AreaFlag.Chest_Both, seq);
            pat.AddSequence(2.5f, AreaFlag.Shoulder_Both, seq);
            pat.AddSequence(2.5f, AreaFlag.Back_Both, seq);
            pat.AddSequence(3.0f, AreaFlag.Upper_Arm_Both, seq);
            pat.AddSequence(3.5f, AreaFlag.Forearm_Both, seq);
            return(pat.Play());
        }
コード例 #17
0
        public static CodeSequence Shimmer()
        {
            CodeSequence seq = new CodeSequence();
            CodeEffect   eff = new CodeEffect("double_click", 0.00f, 1.0f);

            //This is from the NS.DoD.Shimmer.sequence reimplemented as CodeSequence. this is because we don't yet have CodeSequence+File Sequence cross use.
            //{ "time" : 0.0, "effect" : "transition_hum", "strength" : 0.1, "duration" : 0.05},
            //{ "time" : 0.05, "effect" : "hum", "strength" : 0.1, "duration" : 0.1},
            //{ "time" : 0.15, "effect" : "hum", "strength" : 0.5, "duration" : 0.1},
            //{ "time" : 0.25, "effect" : "hum", "strength" : 0.1, "duration" : 0.1}

            seq.AddEffect(0, eff);
            eff = new CodeEffect("transition_hum", 0.05f, 0.1f);
            seq.AddEffect(.05, eff);
            eff = new CodeEffect("hum", .1f, .1f);
            seq.AddEffect(.15, eff);
            eff = new CodeEffect("hum", .1f, .5f);
            seq.AddEffect(.25, eff);
            eff = new CodeEffect("hum", .1f, .1f);

            return(seq);
        }
コード例 #18
0
            /// <summary>
            /// Creates a new CodeSequence and overwrites this Impulse's current Sequence.
            /// </summary>
            /// <param name="effect">The effect family to play.</param>
            /// <param name="duration">The duration of the sequence.</param>
            /// <param name="strength">The strength of the effect (which selects the corresponding family member under the hood)</param>
            /// <returns>The Impulse that you can call .Play() on to play a create a HapticHandle referencing that Haptic</returns>
            public Impulse WithEffect(string effect, float duration = 0.0f, float strength = 1.0f)
            {
                if (duration < 0.0f)
                {
                    throw new ArgumentException("Attempted to assign a negative duration for Impulse's WithEffect(). How would that even work?", "duration");
                }
                if (strength < 0.0f)
                {
                    Debug.LogWarning("[ImpulseGenerator] was provided a negative effect strength. Clamped to 0.0f");
                    strength = 0.0f;
                }

                CodeSequence seq = new CodeSequence();

                seq.AddEffect(0.0f, new CodeEffect(effect, duration, strength));
                if (seq == null)
                {
                    throw new ArgumentException("Attempted to assign a null CodeSequence seq - retaining previous CodeSequence", "seq");
                }
                this.seq = seq;
                return(this);
            }
コード例 #19
0
        /// <summary>
        /// Creating a randomized code sequence is totally doable.
        /// This is a less than ideal approach (because static method)
        /// In your code you shouldn't use a static method like this (Do as I say, not as I do)
        /// This one is about picking three effects at random (with random strength levels as well)
        /// </summary>
        /// <param name="randSeed">Hand in a random seed (or better yet, don't use random in static functions</param>
        /// <returns>A CodeSequence reference for use in Impulses</returns>
        public static CodeSequence ThreeRandomEffects(int randSeed)
        {
            //Debug.Log(randSeed + "\n");
            System.Random rand = new System.Random(randSeed);

            CodeSequence seq = new CodeSequence();

            int effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length);

            CodeEffect eff = new CodeEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f, ((float)rand.Next(2, 10)) / 10);

            seq.AddEffect(0.0, eff);

            effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length);
            eff      = new CodeEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f, ((float)rand.Next(2, 10)) / 10);
            seq.AddEffect(.20f, eff);

            effIndex = rand.Next(0, SuitImpulseDemo.effectOptions.Length);
            eff      = new CodeEffect(SuitImpulseDemo.effectOptions[effIndex], 0.0f, ((float)rand.Next(2, 10)) / 10);
            seq.AddEffect(.4f, eff);

            return(seq);
        }
コード例 #20
0
 /// <summary>
 /// Provide a CodeSequence and then Play the impulse.
 /// Each Play() creates a new HapticHandle instance for that individual played effect.
 /// A helper function for WithEffect(sequence).Play()
 /// </summary>
 /// <param name="sequence">A valid CodeSequence</param>
 /// <returns>The HapticHandle for resetting, pausing or stopping the haptic effect</returns>
 public HapticHandle Play(CodeSequence sequence)
 {
     return(WithEffect(sequence).Play());
 }