예제 #1
0
        public void LoadAudioBlockData(string pathToAudioXmlFile, string shortXmlFileName, string blockName)
        {
            XmlDocument xmlDocument = XmlDataParser.LoadXmlDocumentFromResources(pathToAudioXmlFile, shortXmlFileName);
            XmlNode     rootNode    = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData");
            XmlNode     targetNode  = XmlDataParser.FindTagByUniqueAttributeValueInChild(rootNode, "AudioBlock", "Name", blockName);

            XmlNode audioNode;

            MusicList.Clear();
            if (XmlDataParser.IsAnyTagInChildExist(targetNode, "Music"))
            {
                audioNode = XmlDataParser.FindUniqueTagInChild(targetNode, "Music");
                Delay     = float.Parse(audioNode.Attributes["DelayBetweenTracks"].Value);
                if (XmlDataParser.IsAnyTagInChildExist(audioNode, "Track"))
                {
                    foreach (XmlNode item in XmlDataParser.FindAllTagsInChild(audioNode, "Track"))
                    {
                        MusicList.Add(item.Attributes["Name"].Value);
                    }
                }
            }

            SoundList.Clear();
            if (XmlDataParser.IsAnyTagInChildExist(targetNode, "Sound"))
            {
                audioNode = XmlDataParser.FindUniqueTagInChild(targetNode, "Sound");
                if (XmlDataParser.IsAnyTagInChildExist(audioNode, "Track"))
                {
                    foreach (XmlNode item in XmlDataParser.FindAllTagsInChild(audioNode, "Track"))
                    {
                        SoundList.Add(item.Attributes["Name"].Value);
                    }
                }
            }
        }
예제 #2
0
        public void SaveToXml(XmlDocument xmlDocument, XmlNode target)
        {
            XmlDataParser.AddAttributeToNode(xmlDocument, target, "Name", name);

            if (music.IsFilled)
            {
                XmlNode musicNode = xmlDocument.CreateElement("Music");

                if (music.delay > 0)
                {
                    XmlDataParser.AddAttributeToNode(xmlDocument, musicNode, "DelayBetweenTracks", music.delay.ToString());
                }

                XmlDataParser.AddAttributeToNode(xmlDocument, musicNode, "MusicNotReplyLength", music.musicNotReplyCount.ToString());

                foreach (var musicItem in music.tracks)
                {
                    SaveTrackToXml(xmlDocument, musicNode, musicItem.Value, music.IsBackgroundMusic(musicItem.Value) ? false : true);
                }

                target.AppendChild(musicNode);
            }

            if (sound.IsFilled)
            {
                XmlNode soundNode = xmlDocument.CreateElement("Sound");
                foreach (var soundItem in sound.tracks)
                {
                    SaveTrackToXml(xmlDocument, soundNode, soundItem.Value);
                }
                target.AppendChild(soundNode);
            }
        }
예제 #3
0
        private void LoadAudioConfiguration()
        {
            // Default settings
            maxSoundSourceCount = 3;
            fadeTime            = 0;
            fadeOn = false;

            if (!XmlDataParser.ExistsInResourcesXmlFile(BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName))
            {
                return;
            }

            XmlDocument xmlDocument = XmlDataParser.LoadXmlDocumentFromResources(BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);

            XmlNode rootNode = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData");

            if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioConfiguration"))
            {
                return;
            }

            XmlNode configNode = XmlDataParser.FindUniqueTagInChild(rootNode, "AudioConfiguration");

            maxSoundSourceCount = int.Parse(configNode.Attributes ["SoundSourceCount"].Value);
            fadeTime            = AEngineTool.ParseFloat(configNode.Attributes ["fade"].Value, 0f);
            fadeOn = bool.Parse(configNode.Attributes ["fadeOn"].Value);
        }
        private void CreateStandardXmlDocument()
        {
            XmlDocument document = new XmlDocument();

            XmlDataParser.SaveXmlDocumentToProject(document, BaseEngineConstants.AudioConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);
            AssetDatabase.Refresh();
        }
예제 #5
0
        public bool LoadAudioBlock(string blockName)
        {
            if (audioBlock.name == blockName)
            {
                return(false);
            }

            XmlDocument xmlDocument = XmlDataParser.LoadXmlDocumentFromResources(BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);
            XmlNode     rootNode    = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData");

            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);
        }
        private void InitConfiguration()
        {
            if (audioData == null)
            {
                audioData = new Dictionary <string, AudioBlock> ();
            }
            else
            {
                audioData.Clear();
            }

            if (!XmlDataParser.ExistsInProjectXmlFile(BaseEngineConstants.AudioConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName))
            {
                CreateStandardXmlDocument();
            }


            XmlDocument xmlDocument = XmlDataParser.LoadXmlDocumentFromProject(BaseEngineConstants.AudioConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);
            XmlNode     rootNode    = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData");

            if (XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioSettings"))
            {
                XmlNode defaultNode = XmlDataParser.FindUniqueTagInChild(rootNode, "AudioSettings");

                defaultSetting.useMusic    = bool.Parse(defaultNode.Attributes ["useMusic"].Value);
                defaultSetting.musicVolume = AEngineTool.ParseFloat(defaultNode.Attributes["musicVolume"].Value, 1f);

                defaultSetting.useSound    = bool.Parse(defaultNode.Attributes ["useSound"].Value);
                defaultSetting.soundVolume = AEngineTool.ParseFloat(defaultNode.Attributes["soundVolume"].Value, 1f);
            }

            if (XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioConfiguration"))
            {
                XmlNode configNode = XmlDataParser.FindUniqueTagInChild(rootNode, "AudioConfiguration");

                soundSourceCount = int.Parse(configNode.Attributes ["SoundSourceCount"].Value);
                fadeTime         = AEngineTool.ParseFloat(configNode.Attributes["fade"].Value, 0f);
                useFadeOn        = bool.Parse(configNode.Attributes ["fadeOn"].Value);
            }

            if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioBlock"))
            {
                return;
            }

            foreach (XmlNode item in XmlDataParser.FindAllTagsInChild(rootNode, "AudioBlock"))
            {
                string key = item.Attributes ["Name"].Value;

                if (!audioData.ContainsKey(key))
                {
                    audioData.Add(key, new AudioBlock());
                    audioData [key].LoadFromXml(item);
                }
                else
                {
                    Debug.LogError("Some equals audio blocks name");
                }
            }
        }
예제 #7
0
        public void LoadFromXml(XmlNode target)
        {
            name = target.Attributes ["Name"].Value;

            if (music == null)
            {
                music = new MusicTrackList();
            }
            if (sound == null)
            {
                sound = new SoundTrackList();
            }
            music.Clear();
            sound.Clear();

            if (XmlDataParser.IsAnyTagInChildExist(target, "Music"))
            {
                XmlNode musicNode = XmlDataParser.FindUniqueTagInChild(target, "Music");
                if (XmlDataParser.IsAnyTagInChildExist(musicNode, "Track"))
                {
                    if (musicNode.Attributes ["DelayBetweenTracks"] != null)
                    {
                        music.delay = AEngineTool.ParseFloat(musicNode.Attributes ["DelayBetweenTracks"].Value, 0f);
                    }
                    if (musicNode.Attributes ["MusicNotReplyLength"] != null)
                    {
                        music.musicNotReplyCount = int.Parse(musicNode.Attributes ["MusicNotReplyLength"].Value);
                    }

                    foreach (XmlNode musicTrack in XmlDataParser.FindAllTagsInChild(musicNode, "Track"))
                    {
                        Track track = LoadTrackFromXml(musicTrack);
                        music.tracks.Add(track.name, track);
                        if (musicTrack.Attributes ["Special"] == null)
                        {
                            music.AddTrackToBackgroundMusic(track);
                        }
                    }
                }
            }

            if (XmlDataParser.IsAnyTagInChildExist(target, "Sound"))
            {
                XmlNode soundNode = XmlDataParser.FindUniqueTagInChild(target, "Sound");
                if (XmlDataParser.IsAnyTagInChildExist(soundNode, "Track"))
                {
                    foreach (XmlNode soundTrack in XmlDataParser.FindAllTagsInChild(soundNode, "Track"))
                    {
                        Track track = LoadTrackFromXml(soundTrack);
                        sound.tracks.Add(track.name, track);
                    }
                }
            }
        }
예제 #8
0
        private void LoadAudioSettings()
        {
            XmlDocument xmlDocument;
            bool        needSave = false;

            if (!XmlDataParser.ExistsXmlFile(BaseEngineConstants.BaseSettingsPath, BaseEngineConstants.AudioSettingsShortFileName))
            {
                if (!XmlDataParser.ExistsInResourcesXmlFile(BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName))
                {
                    SaveAudioSettings();
                    xmlDocument = XmlDataParser.LoadXmlDocumentFromFile(BaseEngineConstants.BaseSettingsPath, BaseEngineConstants.AudioSettingsShortFileName);
                }
                else
                {
                    xmlDocument = XmlDataParser.LoadXmlDocumentFromResources(BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);
                    needSave    = true;
                }
            }
            else
            {
                xmlDocument = XmlDataParser.LoadXmlDocumentFromFile(BaseEngineConstants.BaseSettingsPath, BaseEngineConstants.AudioSettingsShortFileName);
            }

            if (!XmlDataParser.IsAnyTagExist(xmlDocument, "AudioData"))
            {
                Debug.Log("AudioData not founded");
                return;
            }
            XmlNode rootNode = XmlDataParser.FindUniqueTag(xmlDocument, "AudioData");

            if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "AudioSettings"))
            {
                Debug.Log("AudioSettings  not founded");
                return;
            }

            XmlNode audioNode = XmlDataParser.FindUniqueTagInChild(rootNode, "AudioSettings");

            isMusic      = bool.Parse(audioNode.Attributes ["useMusic"].Value);
            musicVolumme = AEngineTool.ParseFloat(audioNode.Attributes ["musicVolume"].Value, 1f);

            isSound      = bool.Parse(audioNode.Attributes ["useSound"].Value);
            soundVolumme = AEngineTool.ParseFloat(audioNode.Attributes ["soundVolume"].Value, 1f);

            if (needSave)
            {
                SaveAudioSettings();
            }
        }
예제 #9
0
        private void SaveAudioSettings()
        {
            XmlDocument xmlDocument = new XmlDocument();
            XmlNode     rootNode    = XmlDataParser.CreateRootNode(xmlDocument, "AudioData");

            XmlNode audioNode = xmlDocument.CreateElement("AudioSettings");

            XmlDataParser.AddAttributeToNode(xmlDocument, audioNode, "useMusic", isMusic.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, audioNode, "musicVolume", musicVolumme.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, audioNode, "useSound", isSound.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, audioNode, "soundVolume", soundVolumme.ToString());
            rootNode.AppendChild(audioNode);

            XmlDataParser.SaveXmlDocument(xmlDocument, BaseEngineConstants.BaseSettingsPath, BaseEngineConstants.AudioSettingsShortFileName);
        }
예제 #10
0
        private static void Load()
        {
            XmlDocument xmlDocument = XmlDataParser.LoadXmlDocumentFromFile("", "GameSettings");
            XmlNode     rootNode    = XmlDataParser.FindUniqueTag(xmlDocument, "GameSettings");

            if (!XmlDataParser.IsAnyTagInChildExist(rootNode, "Item"))
            {
                return;
            }

            data.Clear();
            foreach (XmlNode item in XmlDataParser.FindAllTagsInChild(rootNode, "Item"))
            {
                data.Add(item.Attributes ["Key"].Value, item.Attributes ["Value"].Value);
            }
        }
        private void SaveConfiguration(bool saveAdditionalToResources = false)
        {
            XmlDocument xmlDocument = new XmlDocument();
            XmlNode     root        = XmlDataParser.CreateRootNode(xmlDocument, "AudioData");

            XmlNode defaultNode = xmlDocument.CreateElement("AudioSettings");

            XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "useMusic", defaultSetting.useMusic.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "musicVolume", defaultSetting.musicVolume.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "useSound", defaultSetting.useSound.ToString());
            XmlDataParser.AddAttributeToNode(xmlDocument, defaultNode, "soundVolume", defaultSetting.soundVolume.ToString());
            root.AppendChild(defaultNode);

            defaultNode = xmlDocument.CreateElement("AudioConfiguration");
            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;
            }

            if (saveAdditionalToResources)
            {
                if (!Directory.Exists("Assets/Resources/" + BaseEngineConstants.AudioResConfigurationPath))
                {
                    Directory.CreateDirectory("Assets/Resources/" + BaseEngineConstants.AudioResConfigurationPath);
                }

                XmlDataParser.SaveXmlDocumentToResources(xmlDocument, BaseEngineConstants.AudioResConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);
            }

            XmlDataParser.SaveXmlDocumentToProject(xmlDocument, BaseEngineConstants.AudioConfigurationPath, BaseEngineConstants.AudioConfigurationShortFileName);

            AssetDatabase.Refresh();
        }
예제 #12
0
        private void SaveTrackToXml(XmlDocument xmlDocument, XmlNode target, Track track, bool special = false)
        {
            XmlNode trackNode = xmlDocument.CreateElement("Track");

            XmlDataParser.AddAttributeToNode(xmlDocument, trackNode, "Name", track.name);
            if (track.path != null && track.path != "")
            {
                XmlDataParser.AddAttributeToNode(xmlDocument, trackNode, "Path", track.path);
            }
            XmlDataParser.AddAttributeToNode(xmlDocument, trackNode, "Volume", track.Volume.ToString());
            if (special)
            {
                XmlDataParser.AddAttributeToNode(xmlDocument, trackNode, "Special", "");
            }

            target.AppendChild(trackNode);
        }
예제 #13
0
        private static void Init()
        {
            if (isInited)
            {
                return;
            }

            isInited = true;
            data     = new Dictionary <string, string> ();

            if (!XmlDataParser.ExistsXmlFile("", "GameSettings"))
            {
                XmlDocument xmlDocument = new XmlDocument();

                XmlDataParser.CreateRootNode(xmlDocument, "GameSettings");
                XmlDataParser.SaveXmlDocument(xmlDocument, "", "GameSettings");
            }

            Load();
        }
예제 #14
0
        public static void Save()
        {
            if (!isInited)
            {
                Init();
            }

            XmlDocument xmlDocument = new XmlDocument();
            XmlNode     rootNode    = XmlDataParser.CreateRootNode(xmlDocument, "GameSettings");

            foreach (KeyValuePair <string, string> item in data)
            {
                XmlNode itemNode = xmlDocument.CreateElement("Item");

                XmlDataParser.AddAttributeToNode(xmlDocument, itemNode, "Key", item.Key);
                XmlDataParser.AddAttributeToNode(xmlDocument, itemNode, "Value", item.Value);

                rootNode.AppendChild(itemNode);
            }

            XmlDataParser.SaveXmlDocument(xmlDocument, "", "GameSettings");
        }