Пример #1
0
        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();
            }
        }
Пример #2
0
        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());
        }