Exemple #1
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);
        }
Exemple #2
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));
     }
 }
Exemple #3
0
 public static void EnsurePatternIsRemembered(string key, HapticPattern pattern)
 {
     key = HapticResources.CleanName(key);
     if (!LoadedPatterns.ContainsKey(key) && pattern != null)
     {
         LoadedPatterns.Add(key, new PatternImportData(pattern, key));
     }
 }
Exemple #4
0
        /// <summary>
        /// Create a HapticExperience from a HapticDefinitionFile
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hdf"></param>
        /// <returns></returns>
        public static HapticExperience CreateExperienceFromHDF(string key, HapticDefinitionFile hdf)
        {
            string cleanedKey = HapticResources.CleanName(key);

            HapticExperience exp     = ScriptableObject.CreateInstance <HapticExperience>();
            var experience_def_array = hdf.experience_definitions[key];

            foreach (var element in experience_def_array)
            {
                HapticPattern thisPat = CreatePatternFromHDF(element.pattern, hdf);
                thisPat.name = element.pattern;

                ParameterizedPattern paraPat = new ParameterizedPattern(thisPat, element.time, element.strength);
                exp.AddPattern(paraPat);
            }

            return(exp);
        }
Exemple #5
0
        /// <summary>
        /// Create a HapticSequence 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 HapticSequence CreateSequenceFromHDF(string key, HapticDefinitionFile hdf)
        {
            string cleanedKey = HapticResources.CleanName(key);

            if (LoadedSequences.ContainsKey(cleanedKey))
            {
                //Debug.Log("Sequence: " + cleanedKey + " already exists, returning it instead of needless reconstruction\n");
                return(LoadedSequences[cleanedKey].Sequence);
            }
            //Debug.Log("Sequence: " + cleanedKey + " DOES NOT exist, creating a new one\n");

            HapticSequence seq = ScriptableObject.CreateInstance <HapticSequence>();
            var            sequence_def_array = hdf.sequence_definitions[key];

            foreach (var effect in sequence_def_array)
            {
                seq.AddEffect(new HapticEffect(effect.ParseEffect(), effect.time, effect.duration, effect.strength));
            }
            EnsureSequenceIsRemembered(cleanedKey, seq);
            return(seq);
        }