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; }
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(); }