private void AddTrack(TrackList tracks, string path, bool isMusic) { string subPath = path.Substring(path.IndexOf("Resources/")); subPath = subPath.Remove(0, 10); string extansion = Path.GetExtension(subPath); if (extansion == ".meta") { return; } string shortPath = subPath.Replace(extansion, ""); string audioName = Path.GetFileNameWithoutExtension(subPath); if (!tracks.tracks.ContainsKey(audioName)) { Track track = new Track(); track.name = audioName; track.path = shortPath; tracks.tracks.Add(audioName, track); if (isMusic) { MusicTrackList _tracks = tracks as MusicTrackList; _tracks.AddTrackToBackgroundMusic(track); } } return; }
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); } } } }
public AudioBlock() { music = new MusicTrackList(); sound = new SoundTrackList(); }
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(); }