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)); } }
public static bool SequenceExists(string key) { if (LoadedSequences.ContainsKey(key) && LoadedSequences[key].Sequence != null) { return(true); } LoadedSequences.Remove(key); return(false); }
/// <summary> /// This method loads new sequences from a file. /// </summary> private void OnLoadFile() { string filterString = "All Supported Formats|" + string.Join(";", SequenceParsers.All.Select(parser => parser.SupportedFileTypes.Replace(',', ';').Replace(".", "*."))) + "|" + string.Join("|", SequenceParsers.All.Select(parser => string.Format("{0}|{1}", parser.Name, parser.SupportedFileTypes.Replace(',', ';').Replace(".", "*.")))); OpenFileDialog openFileDialog = new OpenFileDialog { CheckFileExists = true, Filter = filterString }; // Prompt the user for the filename if (openFileDialog.ShowDialog() == true) { // See if we can auto-locate the parser ISequenceParser parser = SequenceParsers.FindParserByFileName(openFileDialog.FileName); if (parser == null) { // Use the extension string fileExtension = Path.GetExtension(openFileDialog.FileName); parser = SequenceParsers.All.FirstOrDefault(sp => sp.SupportedFileTypes.Contains(fileExtension)); } // Cannot parse this file. if (parser == null) { MessageBox.Show(string.Format("Cannot locate a sequence parser for {0}", openFileDialog.FileName), "Cannot Parse File"); return; } // Parse the file - open it read-only as we will not be writing the sequences back out. try { foreach (var sequence in parser.Parse()) { LoadedSequences.Add(new SequenceViewModel(this, sequence)); } } catch (Exception ex) { ShowError("Cannot Parse File", "Failed to open " + openFileDialog.FileName, ex); } finally { parser.Close(); } } }
/// <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); }