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 void Load(HapticDefinitionFile other)
 {
     this.root_effect            = other.root_effect;
     this.pattern_definitions    = other.pattern_definitions;
     this.sequence_definitions   = other.sequence_definitions;
     this.experience_definitions = other.experience_definitions;
 }
        /// <summary>
        /// Given a path to the raw haptic asset, generate a HapticDefinitionFile
        /// </summary>
        /// <param name="path">Path to haptic asset. Ex: C:\Haptics\my\patterns\test.pattern</param>
        /// <returns></returns>
        public HapticDefinitionFile GetHapticDefinitionFile(string path)
        {
            var result = executeToolAndWaitForResult(
                new ArgList()
                .Add("root-path", _rootPath)
                .Add("generate-asset", path)
                .Add("json")
                );

            HapticDefinitionFile hdf = new HapticDefinitionFile();

            try
            {
                object x = MiniJSON.Json.Deserialize(result);
                hdf.Deserialize(x as IDictionary <string, object>);
                return(hdf);
            }
            catch (Exception e)
            {
#if UNITY_EDITOR
                UnityEngine.Debug.LogException(e);
#else
                Console.WriteLine(e);
#endif
                throw new HapticsLoadingException("[HLVR] Couldn't deserialize the json response for the request file path [" + path + "]");
            }
        }
Exemple #4
0
        internal static HapticExperience LoadExperienceFromJson(string jsonPath)
        {
            HapticDefinitionFile hdf = LoadHDFFromJson(jsonPath);

            if (hdf.root_effect.type == "experience")
            {
                var exp = CodeHapticFactory.CreateExperienceFromHDF(hdf.root_effect.name, hdf);
                return(exp);
            }
            else
            {
                Debug.LogError("Error in LoadExperienceFromJson - likely an invalid path was provided\n\t" + hdf.root_effect.name + " is of type " + hdf.root_effect.type + "\n");
                return(HapticExperience.CreateNew());
                //throw new InvalidOperationException("Unable to load " + hdf.root_effect.name + " as a HapticExperience because it is a " + hdf.root_effect.type);
            }
        }
Exemple #5
0
        public static HapticDefinitionFile ParseHDF(string path)
        {
            try
            {
                var json = File.ReadAllText(path);

                IDictionary <string, object> obj = MiniJSON.Json.Deserialize(json) as IDictionary <string, object>;

                HapticDefinitionFile file = new HapticDefinitionFile();
                file.Deserialize(obj);
                return(file);
            }
            catch (IOException e)
            {
                throw new HapticsLoadingException("Couldn't read the haptics asset at " + path, e);
            }
        }
Exemple #6
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 #7
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);
        }