Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void Save(XmlDocument xmlDocument)
        {
            string path = Path.GetDirectoryName(AudioConstants.GetResourcesPath());

            CheckDirectory(path);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //xmlDocument.Save();
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
0
        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();
        }