private void LoadAudioConfiguration() { // Default settings fadeTime = 0; fadeOn = false; if (!File.Exists(AudioConstants.GetResourcesPath())) { return; } XmlDocument xmlDocument = XmlParser.LoadFromResources(AudioConstants.GetReadableRuntimeResourcesPath()); XmlNode rootNode = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData"); if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioConfiguration")) { return; } XmlNode configNode = XmlDataParser.FindUniqueTagInChild(rootNode, "AudioConfiguration"); _generalAudioSettings.Load(configNode); fadeTime = float.Parse(configNode.Attributes ["fade"].Value); fadeOn = bool.Parse(configNode.Attributes ["fadeOn"].Value); }
public bool LoadAudioBlock(string blockName) { if (audioBlock.name == blockName) { return(false); } XmlDocument xmlDocument = XmlParser.LoadFromResources(AudioConstants.GetReadableRuntimeResourcesPath()); XmlNode rootNode = XmlParser.GetRootTag(xmlDocument, AudioConstants.XML_ROOT); if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioBlock")) { return(false); } foreach (XmlNode item in XmlDataParser.FindAllTagsInChild(rootNode, "AudioBlock")) { if (blockName == item.Attributes ["Name"].Value) { audioBlock.LoadFromXml(item); audioBlock.LoadAudioResources(); break; } } return(true); }
public void Save(XmlDocument xmlDocument) { string path = Path.GetDirectoryName(AudioConstants.GetResourcesPath()); CheckDirectory(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //xmlDocument.Save(); }
private void LoadRuntimeChangableAudioSettings() { XmlDocument xmlDocument; bool needSave = false; // Check if exists runtime/resources data file and load xmlDocument if (!File.Exists(AudioConstants.GetCachePath())) { if (!File.Exists(AudioConstants.GetResourcesPath())) { SaveRuntimeChangableAudioSettings(); xmlDocument = XmlParser.LoadFromFile(AudioConstants.GetCachePath()); Debug.LogError("Couldn't find configuration file in resources"); } else { xmlDocument = XmlParser.LoadFromResources(AudioConstants.GetReadableRuntimeResourcesPath()); needSave = true; } } else { xmlDocument = XmlParser.LoadFromFile(AudioConstants.GetCachePath()); } // Parsing audio data if (!XmlParser.IsExistRootTag(xmlDocument, AudioConstants.XML_ROOT)) { Debug.Log("Couldn't find root tag"); return; } XmlNode rootNode = XmlParser.GetRootTag(xmlDocument, AudioConstants.XML_ROOT); if (!XmlDataParser.IsAnyTagInChildExist(rootNode, AudioConstants.XML_RUNTIME_TAG)) { Debug.Log(string.Format("{0} tag not founded", AudioConstants.XML_RUNTIME_TAG)); return; } XmlNode audioNode = XmlDataParser.FindUniqueTagInChild(rootNode, AudioConstants.XML_RUNTIME_TAG); _runtimeAudioSettings.Load(audioNode); _runtimeAudioSettings.SoundVolume = _runtimeAudioSettings.SoundVolume; if (needSave) { SaveRuntimeChangableAudioSettings(); } }
private void SaveRuntimeChangableAudioSettings() { XmlDocument xmlDocument = new XmlDocument(); XmlNode rootNode = XmlParser.CreateRootTag(xmlDocument, AudioConstants.XML_ROOT); XmlNode audioNode = xmlDocument.CreateElement(AudioConstants.XML_RUNTIME_TAG); _runtimeAudioSettings.Save(xmlDocument, audioNode); rootNode.AppendChild(audioNode); if (!Directory.Exists(Path.GetDirectoryName(AudioConstants.GetCachePath()))) { Directory.CreateDirectory(Path.GetDirectoryName(AudioConstants.GetCachePath())); } xmlDocument.Save(AudioConstants.GetCachePath()); }
public static XmlDocument Load() { XmlDocument xmlDocument; string path = AudioConstants.GetResourcesPath(); CheckDirectory(Path.GetDirectoryName(path)); if (!File.Exists(path)) { xmlDocument = new XmlDocument(); XmlNode root = XmlParser.CreateRootTag(xmlDocument, "AudioData"); xmlDocument.Save(path); } xmlDocument = XmlParser.LoadFromFile(AudioConstants.GetResourcesPath()); return(xmlDocument); }
private void SaveConfiguration(bool saveAdditionalToResources = false) { XmlDocument xmlDocument = new XmlDocument(); XmlNode root = XmlParser.CreateRootTag(xmlDocument, AudioConstants.XML_ROOT); XmlNode defaultNode = xmlDocument.CreateElement(AudioConstants.XML_RUNTIME_TAG); _runtimeAudioSettings.Save(xmlDocument, defaultNode); root.AppendChild(defaultNode); defaultNode = xmlDocument.CreateElement("AudioConfiguration"); _generalAudioSettings.Save(xmlDocument, defaultNode); //XmlDataParser.AddAttributeToNode (xmlDocument, defaultNode, "SoundSourceCount", soundSourceCount.ToString()); XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "fade", fadeTime.ToString()); XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "fadeOn", useFadeOn.ToString()); root.AppendChild(defaultNode); if (audioData != null) { foreach (var item in audioData) { XmlNode blockNode = xmlDocument.CreateElement("AudioBlock"); item.Value.SaveToXml(xmlDocument, blockNode); root.AppendChild(blockNode); } } else { return; } xmlDocument.Save(AudioConstants.GetResourcesPath()); AssetDatabase.Refresh(); }