예제 #1
0
        public static HapticSequence ClickStorm()
        {
            HapticSequence seq = new HapticSequence();

            HapticEffect eff = new HapticEffect(Effect.Double_Click, .0f);

            seq.AddEffect(0, eff);

            eff = new HapticEffect(Effect.Click, .0f);
            seq.AddEffect(0.1, eff);

            eff = new HapticEffect(Effect.Click, .0f);
            seq.AddEffect(0.2, eff);

            eff = new HapticEffect(Effect.Double_Click, .0f);
            seq.AddEffect(0.3, eff);

            eff = new HapticEffect(Effect.Triple_Click, .0f);
            seq.AddEffect(0.4, eff);

            eff = new HapticEffect(Effect.Double_Click, .0f);
            seq.AddEffect(0.5, eff);

            eff = new HapticEffect(Effect.Click, .0f);
            seq.AddEffect(0.6, eff);

            eff = new HapticEffect(Effect.Triple_Click, .0f);
            seq.AddEffect(0.7, eff);

            return(seq);
        }
예제 #2
0
 public void SetTriggerSequence(HapticSequence sequence, string labelName)
 {
     LastSequence = sequence;
     greenBox.SetSequence(sequence);
     LastSequenceName = labelName;
     //Debug.Log("Set Last Sequence! \t" + (LastSequence != null) + "\n");
 }
예제 #3
0
        IEnumerator StomacheRumble()
        {
            gulpSource.volume = .85f;

            List <AreaFlag> locs = new List <AreaFlag>();

            locs.Add(AreaFlag.Lower_Ab_Left);
            locs.Add(AreaFlag.Lower_Ab_Right);
            locs.Add(AreaFlag.Mid_Ab_Left);
            locs.Add(AreaFlag.Mid_Ab_Right);

            while (true)
            {
                AreaFlag loc  = locs[Random.Range(0, locs.Count)];
                string   file = Random.Range(0, 1.0f) > .8f ? "Haptics/StomachRumbleHeavy" : "Haptics/StomachRumble";

                HapticSequence seq = new HapticSequence();
                seq.LoadFromAsset(file);
                seq.CreateHandle(loc).Play();

                float waitDur = Random.Range(.05f, .15f);

                yield return(new WaitForSeconds(waitDur));
            }
        }
예제 #4
0
        /// <summary>
        /// A VERY random effect. More just for showing haptic varion
        /// </summary>
        /// <param name="randSeed"></param>
        /// <returns></returns>
        public static HapticSequence VeryRandomEffect(int randSeed)
        {
            //Debug.Log(randSeed + "\n");
            System.Random rand = new System.Random(randSeed);

            HapticSequence seq = new HapticSequence();

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

            float        dur    = ((float)rand.Next(0, 6)) / 3;
            float        delay  = 0;
            float        offset = 0;
            HapticEffect 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 HapticEffect(SuitImpulseDemo.effectOptions[effIndex], dur);
                seq.AddEffect(offset + delay, ((float)rand.Next(0, 10)) / 10, eff);
                offset = dur;
            }

            return(seq);
        }
예제 #5
0
        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);
        }
예제 #6
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 HapticSequence reference for use in Impulses</returns>
        public static HapticSequence RandomPulses(int randSeed)
        {
            //Debug.Log(randSeed + "\n");
            System.Random rand = new System.Random(randSeed);

            HapticSequence seq = new HapticSequence();

            float        dur   = ((float)rand.Next(0, 15)) / 10;
            float        delay = ((float)rand.Next(0, 10)) / 20;
            HapticEffect eff   = new HapticEffect(Effect.Pulse, dur);

            seq.AddEffect(0.0, ((float)rand.Next(0, 10)) / 10, eff);
            float offset = dur;

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

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

            return(seq);
        }
예제 #7
0
        private HapticHandle CreateImpulseHandle(SideOfHaptic side)
        {
            if (TypeOfImpulse == ImpulseType.None)
            {
                return(null);
            }
            else if (TypeOfImpulse == ImpulseType.Emanation)
            {
                bool mirror  = side == SideOfHaptic.Left;
                var  impulse = ImpulseGenerator.BeginEmanatingEffect(mirror ? StartLocation.Mirror() : StartLocation, depth);

                HapticSequence seq = new HapticSequence();
                seq.LoadFromAsset(HapticSequence);

                impulse.WithEffect(seq).WithAttenuation(attenuationPercentage).WithDuration(Duration);

                return(impulse.Play());
            }
            else if (TypeOfImpulse == ImpulseType.Traversal)
            {
                bool mirror  = side == SideOfHaptic.Left;
                var  impulse = ImpulseGenerator.BeginTraversingImpulse(
                    mirror ? StartLocation.Mirror() : StartLocation,
                    mirror ? EndLocation.Mirror() : EndLocation);

                HapticSequence seq = new HapticSequence();
                seq.LoadFromAsset(HapticSequence);

                impulse.WithEffect(seq).WithAttenuation(attenuationPercentage).WithDuration(Duration);

                return(impulse.Play());
            }
            return(null);
        }
예제 #8
0
        /// <summary>
        /// Create a HapticPattern from a HapticDefinitionFile
        /// </summary>
        /// <param name="key">Name of the root effect</param>
        /// <param name="hdf">A HapticDefinitionFile containing the root effect</param>
        /// <returns></returns>
        public static HapticPattern CreatePatternFromHDF(string key, HapticDefinitionFile hdf)
        {
            string cleanedKey = HapticResources.CleanName(key);

            if (LoadedPatterns.ContainsKey(cleanedKey))
            {
                //Debug.Log("Pattern: " + cleanedKey + " already exists, returning it instead of needless reconstruction\n");
                return(LoadedPatterns[cleanedKey].Pattern);
            }

            HapticPattern pat = ScriptableObject.CreateInstance <HapticPattern>();
            var           pattern_def_array = hdf.pattern_definitions[key];

            foreach (var element in pattern_def_array)
            {
                //Debug.Log("Pattern Def Array: " + key + "  " + element.sequence + "\n");
                HapticSequence thisSeq = CreateSequenceFromHDF(element.sequence, hdf);
                thisSeq.name = element.sequence;

                ParameterizedSequence paraSeq = new ParameterizedSequence(thisSeq, element.ParseAreaFlag(), element.time, element.strength);
                pat.AddSequence(paraSeq);
            }

            EnsurePatternIsRemembered(cleanedKey, pat);
            return(pat);
        }
예제 #9
0
        /// <summary>
        /// [Helper function] Looks for a haptic sequence File - "Resources/Haptics/" + filename
        /// Identical to making a new HapticSequence and calling it's LoadFromAsset("Haptics/" + filename) function
        /// </summary>
        /// <param name="sequenceFile"></param>
        /// <returns></returns>
        public HapticSequence GetSequence(string sequenceFile)
        {
            HapticSequence seq = new HapticSequence();

            seq.LoadFromAsset("Haptics/" + sequenceFile);
            return(seq);
        }
예제 #10
0
        /// <summary>
        /// Attempts to create a haptic sequence from the provided json path
        /// It will create a HDF and then turn the hdf into a HapticSequence.
        /// </summary>
        /// <param name="jsonPath">Ex: StreamingAssets/Haptics/NS Demos/sequences/click.sequence</param>
        public static HapticSequence CreateSequence(string jsonPath)
        {
            var fileName = Path.GetFileNameWithoutExtension(jsonPath);

            ////If we don't replace . with _, then Unity has serious trouble locating the file
            HapticSequence seq = null;

            bool isSeq = IsSequence(jsonPath);
            bool isPat = IsPattern(jsonPath);
            bool isExp = IsExperience(jsonPath);

            //Debug.Log("Attemtping haptic asset import: " + jsonPath + " " + isSeq + "\n" + fileName + "\n\n" + "\n");

            if (isSeq)
            {
                seq      = LoadSequenceFromJson(jsonPath);
                seq.name = CleanName(fileName);
            }
            else if (isPat)
            {
                Debug.LogError("Attempted to run a HapticResources.CreatePattern while providing a pattern at path: " + jsonPath + "\n\t");
            }
            else if (isExp)
            {
                Debug.LogError("Attempted to run a HapticResources.CreateSequence while providing a experience at path: " + jsonPath + "\n\t");
            }

            return(seq);
        }
예제 #11
0
 void Start()
 {
     seq = new HapticSequence();
     //By using a double click we can distinctly hear the difference.
     seq.LoadFromAsset("Haptics/double_click");
     //Play it on load to make sure it loaded.
     seq.Play(AreaFlag.All_Areas);
 }
예제 #12
0
 public static void EnsureSequenceIsRemembered(string key, HapticSequence sequence)
 {
     key = HapticResources.CleanName(key);
     if (!LoadedSequences.ContainsKey(key) && sequence != null)
     {
         LoadedSequences.Add(key, new SequenceImportData(sequence, key));
     }
 }
예제 #13
0
    void Thing()
    {
        HapticSequence seq = new HapticSequence();
        //seq.Play(AreaFlag.

        //We want an AreaFlag like object.
        //It needs to be enum-like or classlike in behavior?
    }
예제 #14
0
 /// <summary>
 /// Sets and overwrites this Impulse's current Sequence
 /// </summary>
 /// <param name="seq"></param>
 /// <returns></returns>
 public Impulse WithEffect(HapticSequence seq)
 {
     if (seq == null)
     {
         throw new ArgumentException("Attempted to assign a null HapticSequence seq - retaining previous HapticSequence", "seq");
     }
     this.seq = seq;
     return(this);
 }
예제 #15
0
        public static HapticSequence ClickHum()
        {
            HapticSequence seq = new HapticSequence();
            HapticEffect   eff = new HapticEffect(Effect.Click, 0.0f);

            seq.AddEffect(0, eff);
            eff = new HapticEffect(Effect.Hum, .2f);
            seq.AddEffect(.15, 0.5f, eff);
            return(seq);
        }
예제 #16
0
        public static HapticSequence ThockClunk()
        {
            HapticSequence seq = new HapticSequence();
            HapticEffect   eff = new HapticEffect(Effect.Click, 0.15f);

            seq.AddEffect(0, eff);
            eff = new HapticEffect(Effect.Fuzz, .2f);
            seq.AddEffect(.15, eff);
            return(seq);
        }
        public void CollideWithBody(HardlightSuit body, Collider col, Vector3 where)
        {
            //Default sequence, gets reassigned
            HapticSequence seq = body.GetSequence("pulse");

            //Depending on the type of projectile that we are.
            switch (typeOfCollision)
            {
            case CollisionType.MinorCoinHit:

                //Hit the body with a simple effect name - which should be in "Resources/Haptics/<Name>"
                body.HitNearest(lastPosition, "click");

                break;

            case CollisionType.SharpImpact:

                body.FindNearbyLocation(lastPosition);
                body.HitImpulse(lastPosition, body.GetSequence("pain_short"), .1f, 1, 0);
                //body.HitImpulse(lastPosition, Effect.Pulse, .2f, .35f, 1, 2);

                break;

            case CollisionType.ThudImpact:

                //This plays an effect across all found pads within a range.
                body.HitNearby(lastPosition, "click", BigImpactArea);

                break;

            case CollisionType.MediumCashPackHit:

                body.HitNearest(lastPosition, "pulse");

                break;

            case CollisionType.SackOfGoldhit:

                //More helper function usage. This asset is from the Death and Dying pack (which is a very intense effect)
                seq = body.GetSequence("pain_short");

                //This makes use of the other HitImpulse which allows for repeated effects.
                body.HitImpulse(lastPosition, seq, .2f, 2, 3, .15f, 1.0f);

                break;

            case CollisionType.MudBlob:

                seq = body.GetSequence("pulse");

                body.HitImpulse(lastPosition, seq, .02f, 5, 3, .15f, 1.0f);

                break;
            }
        }
예제 #18
0
        /// <summary>
        /// Plays the sequence on the single nearest HapticLocation
        /// Note: A HapticLocation can have an AreaFlag with multiple pads selected.
        /// </summary>
        /// <param name="point">A point in world space to compare</param>
        /// <param name="sequence">The sequence to play on the nearest location</param>
        /// <param name="maxDistance">The max distance the point can be from any HapticLocations</param>
        public AreaFlag HitNearest(Vector3 point, HapticSequence sequence, float maxDistance = 5.0f)
        {
            AreaFlag Where = FindNearestFlag(point, maxDistance);

            if (Where != AreaFlag.None)
            {
                sequence.CreateHandle(Where).Play();
            }
            else
            {
                Debug.Log("Projectile hit the HardlightSuit but found no objects hit. Perhaps the maxDistance (" + maxDistance + ") is too small?\n\tOr the suit/prefab wasn't configured correctly.\n");
            }
            return(Where);
        }
예제 #19
0
 void Start()
 {
     if (hapticFilesToPlay == null)
     {
         hapticFilesToPlay = new string[0];
     }
     sequences = new HapticSequence[hapticFilesToPlay.Length];
     for (int i = 0; i < hapticFilesToPlay.Length; i++)
     {
         HapticSequence seq = new HapticSequence();
         seq.LoadFromAsset(hapticFilesToPlay[i]);
         sequences[i] = seq;
     }
 }
예제 #20
0
        public static HapticSequence DoubleClickImpact()
        {
            HapticSequence seq = new HapticSequence();
            HapticEffect   eff = new HapticEffect(Effect.Double_Click, 0.00f);

            seq.AddEffect(0, eff);
            eff = new HapticEffect(Effect.Buzz, .05f);
            seq.AddEffect(.05, eff);
            eff = new HapticEffect(Effect.Buzz, .10f);
            seq.AddEffect(.10, 0.6f, eff);
            eff = new HapticEffect(Effect.Buzz, .15f);
            seq.AddEffect(.2, 0.2f, eff);

            return(seq);
        }
예제 #21
0
        /// <summary>
        /// Plays the sequence on all HapticLocations within a certain radius of the provided point.
        /// </summary>
        /// <param name="point">A point in world space to compare</param>
        /// <param name="sequence">The sequence to play on the nearby locations</param>
        /// <param name="impactRadius">The body is about .6 wide, .72 tall and .25 deep</param>
        public AreaFlag HitNearby(Vector3 point, HapticSequence sequence, float impactRadius = .35f)
        {
            AreaFlag Where = FindAllFlagsWithinRange(point, impactRadius, true);

            if (Where != AreaFlag.None)
            {
                sequence.CreateHandle(Where).Play();
            }
            else
            {
                Debug.Log("Projectile hit the HardlightSuit but found no objects hit. Perhaps the impactRadius (" + impactRadius + ") is too small?\n\tOr the suit/prefab wasn't configured correctly.\n");
            }

            return(Where);
        }
예제 #22
0
        //todo: reimplement all these as assets
        public static HapticSequence ClickHumDoubleClick()
        {
            HapticSequence seq = new HapticSequence();

            HapticEffect eff = new HapticEffect(Effect.Click);

            seq.AddEffect(0, eff);

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

            eff = new HapticEffect(Effect.Double_Click);
            seq.AddEffect(0.6, eff);

            return(seq);
        }
예제 #23
0
        public static HapticSequence PulseBumpPulse()
        {
            HapticSequence seq = new HapticSequence();

            HapticEffect eff = new HapticEffect(Effect.Pulse, 0.40f);

            seq.AddEffect(0.0, 0.7f, eff);

            eff = new HapticEffect(Effect.Bump, .0f);
            seq.AddEffect(0.40, eff);

            eff = new HapticEffect(Effect.Pulse, 0.0f);
            seq.AddEffect(0.55, 0.2f, eff);

            return(seq);
        }
예제 #24
0
        internal static HapticSequence LoadSequenceFromJson(string jsonPath)
        {
            HapticDefinitionFile hdf = LoadHDFFromJson(jsonPath);

            if (hdf.root_effect.type == "sequence")
            {
                var seq = CodeHapticFactory.CreateSequenceFromHDF(hdf.root_effect.name, hdf);
                return(seq);
            }
            else
            {
                Debug.LogError("Error in LoadSequenceFromJson - likely an invalid path was provided\n\t" + hdf.root_effect.name + " is of type " + hdf.root_effect.type + "\n");
                return(HapticSequence.CreateNew());
                //throw new InvalidOperationException("Unable to load " + hdf.root_effect.name + " as a HapticSequence because it is a " + hdf.root_effect.type);
            }
        }
예제 #25
0
        public static HapticSequence TripleClickFuzzFalloff()
        {
            HapticSequence seq = new HapticSequence();

            HapticEffect eff = new HapticEffect(Effect.Triple_Click, 0.20f);

            seq.AddEffect(0.0, 0.7f, eff);

            eff = new HapticEffect(Effect.Fuzz, .20f);
            seq.AddEffect(0.2, eff);

            eff = new HapticEffect(Effect.Fuzz, .20f);
            seq.AddEffect(0.4, 0.5f, eff);

            return(seq);
        }
예제 #26
0
        void Update()
        {
            //IF we should shock and we aren't currently
            if (ShouldShock && !CurrentlyShocking)
            {
                //Start the coroutine!
                StartCoroutine(ShockPlayer());
                ShouldShock = false;
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                HapticSequence seq = new HapticSequence();
                seq.LoadFromAsset("Haptics/pulse");
                seq.Play(AreaFlag.Left_All);
            }
        }
예제 #27
0
        void Update()
        {
            bool  moving = false;
            float velVal = 350;

            #region Direction Controls
            if (Input.GetKey(KeyCode.LeftArrow) && myRB.transform.position.x > -8)
            {
                myRB.AddForce(Vector3.left * velVal);
            }
            if (Input.GetKey(KeyCode.RightArrow) && myRB.transform.position.x < 8)
            {
                myRB.AddForce(Vector3.right * velVal);
            }
            if (Input.GetKey(KeyCode.UpArrow) && myRB.transform.position.y < 8)
            {
                myRB.AddForce(Vector3.up * velVal);
            }
            if (Input.GetKey(KeyCode.DownArrow) && myRB.transform.position.y > -8)
            {
                myRB.AddForce(Vector3.down * velVal);
            }

            if (!moving)
            {
                myRB.velocity = Vector3.zero;
            }
            #endregion

            #region Application Quit Code
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
            #endregion

            if (Input.GetKeyDown(KeyCode.T))
            {
                var s = new HapticSequence();
                s.AddEffect(0.0, new HapticEffect(Effect.Click));
                s.Play(AreaFlag.Left_All);
                long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                Debug.Log("Milliseconds: " + milliseconds);
            }
        }
예제 #28
0
        public void Dig()
        {
            //Debug.Log("Attempted Dig\n", this);
            //Are we held.
            //if (IsGrabbed())
            //{
            HapticSequence seq = new HapticSequence();

            seq.AddEffect(.25f, new HapticEffect(Effect.Buzz));
            AreaFlag Where = PrimaryLeft ? AreaFlag.Forearm_Left : AreaFlag.Forearm_Right;

            seq.Play(Where);
            //}
            Digged = true;

            leftActions.TriggerDecayingHapticPulse(1f, .5f, .02f, .8f);
            rightActions.TriggerDecayingHapticPulse(1f, .5f, .02f, .8f);
        }
        /// <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)
        {
            HapticSequence seq = new HapticSequence();

            //This will be slightly different then the default Effect.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:
            //		HapticEffect eff = new HapticEffect(Effect.Buzz, 0.00f, 1.0f);

            HapticEffect eff = new HapticEffect(Effect.Buzz, 0.10f);

            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));
        }
예제 #30
0
 public void SetTriggerSequence(string sequenceName, string visibleName)
 {
     //HapticSequence newSeq = new HapticSequence();
     try
     {
         LastSequence = new HapticSequence();
         LastSequence.LoadFromAsset(sequenceName);
         greenBox.SetSequence(LastSequence);
     }
     catch (HapticsAssetException hExcept)
     {
         Debug.LogError("[Library Manager - Haptics Asset Exception]   Exception while loading sequence - " + sequenceName + "\n\t" + hExcept.Message);
     }
     catch (System.Exception e)
     {
         Debug.LogError("[Exception]   \n\tLoad failed and set was disallowed\n" + e.Message);
     }
     LastSequenceName  = visibleName;
     greenBoxText.text = visibleName;
 }