Beispiel #1
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);
            }
        }
        private void DrawTrackList(TrackList trackList, bool withSpecial)
        {
            if (trackList.IsFilled)
            {
                string removeKey = "";
                foreach (var item in trackList.tracks)
                {
                    Track track = item.Value;

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("-", GUILayout.Width(20)))
                    {
                        removeKey = item.Key;
                    }
                    EditorGUILayout.LabelField(track.name, GUILayout.Width(120));
                    EditorGUILayout.LabelField("Volume:", GUILayout.Width(60));
                    track.Volume = EditorGUILayout.Slider(track.Volume, 0, 1, GUILayout.Width(200));

                    if (withSpecial)
                    {
                        MusicTrackList _trackList = trackList as MusicTrackList;
                        GUILayout.Space(30);
                        EditorGUILayout.LabelField("Not play in background", GUILayout.Width(150));
                        bool special = !_trackList.IsBackgroundMusic(track);
                        special = EditorGUILayout.Toggle(special, GUILayout.Width(20));
                        if (special != !_trackList.IsBackgroundMusic(track))
                        {
                            if (special)
                            {
                                _trackList.RemoveFromBackgroundMusic(track);
                            }
                            else
                            {
                                _trackList.AddTrackToBackgroundMusic(track);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (removeKey != "")
                {
                    if (withSpecial)
                    {
                        MusicTrackList _trackList = trackList as MusicTrackList;
                        _trackList.RemoveFromBackgroundMusic(_trackList.tracks[removeKey]);
                        _trackList.tracks.Remove(removeKey);
                    }
                    else
                    {
                        trackList.tracks.Remove(removeKey);
                    }

                    if (namesList.Contains(removeKey))
                    {
                        namesList.Remove(removeKey);
                    }
                }

                GUILayout.Space(8);
            }

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add selected tracks", GUILayout.Width(200)))
            {
                foreach (var obj in Selection.objects)
                {
                    string path = AssetDatabase.GetAssetPath(obj);
                    if (obj == null)
                    {
                        continue;
                    }

                    if (!Directory.Exists(path))
                    {
                        AddTrack(trackList, path, withSpecial);
                        continue;
                    }

                    string[] files = Directory.GetFiles(path);
                    if (files != null)
                    {
                        for (int i = 0; i < files.Length; i++)
                        {
                            AddTrack(trackList, files [i], withSpecial);
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }