static IEnumerator LoadResource() { for (int i = 0; i < entries.Count; i++) { Entry entry = entries[i]; if (entry.isDirectory) { yield return(null); continue; } if ((entry.songInfo.background || string.IsNullOrEmpty(entry.songInfo.backgroundPath)) && (entry.songInfo.banner || string.IsNullOrEmpty(entry.songInfo.bannerPath))) { yield return(null); continue; } FileInfo fileInfo = new FileInfo(GetAbsolutePath(entry.songInfo.filePath)); var resourceLoader = new ResourceLoader(fileInfo.Directory.FullName); if (!entry.songInfo.background && !string.IsNullOrEmpty(entry.songInfo.backgroundPath)) { var backgroundObj = new ResourceObject(-1, ResourceType.bmp, entry.songInfo.backgroundPath); yield return(SmartCoroutineLoadBalancer.StartCoroutine(bmsManager, resourceLoader.LoadResource(backgroundObj))); entry.songInfo.background = backgroundObj.texture; } if (!entry.songInfo.banner && !string.IsNullOrEmpty(entry.songInfo.bannerPath)) { var bannerObj = new ResourceObject(-2, ResourceType.bmp, entry.songInfo.bannerPath); yield return(SmartCoroutineLoadBalancer.StartCoroutine(bmsManager, resourceLoader.LoadResource(bannerObj))); entry.songInfo.banner = bannerObj.texture; } entries[i] = entry; cachedEntries[fileInfo.FullName] = entry; if (selectedEntry.HasValue && string.Equals(entry.songInfo.filePath, selectedEntry.Value.filePath, StringComparison.Ordinal)) { selectedEntry = entry.songInfo; if (OnSelectionChanged != null) { OnSelectionChanged.Invoke(selectedEntry); } } InvokeListUpdated(); yield return(null); } loadResourceCoroutine = null; yield break; }
void OnScroll(Vector2 position) { if (!SongInfoLoader.IsReady) { return; } Vector2 actualSize = scroller.content.rect.size; Vector2 contentPosition = scroller.content.anchoredPosition; Vector2 viewportPosition = scroller.viewport.anchoredPosition; int startIndex = Mathf.Max(0, Mathf.FloorToInt(contentPosition.y / sizePerEntry.y)); Rect viewportRect = scroller.viewport.rect; Vector2 offsetMin = viewportRect.min - contentPosition; Vector2 offsetMax = viewportRect.max - contentPosition; for (int i = 0, l = entryDisplay.Count, c = entries.Count; i < l; i++) { int actualIndex = startIndex + i - 1; SelectSongEntry entryDisp = entryDisplay[(actualIndex + l) % l]; if (actualIndex < c && actualIndex >= 0) { Vector2 pos = entryDisp.transform.anchoredPosition; pos.y = -actualIndex * sizePerEntry.y; float lerp = (pos.y - offsetMin.y) / (offsetMax.y - offsetMin.y); pos.x = Mathf.LerpUnclamped(slopeStart, slopeEnd, lerp); entryDisp.transform.anchoredPosition = pos; Entry entry = entries[actualIndex]; if (entry.isDirectory) { entryDisp.Load(entry.dirInfo, entry.isParentDirectory, this); } else { entryDisp.Load(entry.songInfo, this); } entryDisp.gameObject.SetActive(true); entryDisp.UpdateChildTransform(Mathf.LerpUnclamped(slopeAnchorStart, slopeAnchorEnd, lerp)); } else { entryDisp.gameObject.SetActive(false); } } SongInfoLoader.ScrollPosition = position; }
static int FinalCompare(ref Entry lhs, ref Entry rhs, int val) { if (val != 0) { return(val); } if (lhs.isParentDirectory || (lhs.isDirectory && !rhs.isDirectory)) { return(-1); } if (rhs.isParentDirectory || (!lhs.isDirectory && rhs.isDirectory)) { return(1); } string lhsDisplay = lhs.isDirectory ? lhs.dirInfo.Name : lhs.songInfo.name; string rhsDisplay = rhs.isDirectory ? rhs.dirInfo.Name : rhs.songInfo.name; return(string.Compare(lhsDisplay, rhsDisplay, StringComparison.InvariantCultureIgnoreCase)); }
public static int CompareByLevelInverse(Entry lhs, Entry rhs) { return(FinalCompare(ref lhs, ref rhs, rhs.songInfo.level.CompareTo(lhs.songInfo.level))); }
public static int CompareByBPMInverse(Entry lhs, Entry rhs) { return(FinalCompare(ref lhs, ref rhs, rhs.songInfo.bpm.CompareTo(lhs.songInfo.bpm))); }
public static int CompareByGenreInverse(Entry lhs, Entry rhs) { return(FinalCompare(ref lhs, ref rhs, string.Compare(rhs.songInfo.genre, lhs.songInfo.genre, StringComparison.InvariantCultureIgnoreCase))); }
public static int CompareByArtist(Entry lhs, Entry rhs) { return(FinalCompare(ref lhs, ref rhs, string.Compare(lhs.songInfo.artist, rhs.songInfo.artist, StringComparison.InvariantCultureIgnoreCase))); }
static bool Filter(Entry entry) { return(entry.isParentDirectory || entry.summary.IndexOf(filterText, StringComparison.InvariantCultureIgnoreCase) >= 0); }
static void ReadDirectoryThread() { try { entries.Clear(); var supportedFileTypes = SupportedFileTypes; if (!string.Equals(currentDirectory.FullName, rootDiectory.FullName, StringComparison.Ordinal)) { entries.Add(new Entry { isDirectory = true, isParentDirectory = true, dirInfo = currentDirectory, summary = "" }); } foreach (var dirInfo in currentDirectory.GetDirectories()) { try { if (supportedFileTypes.Any(filter => dirInfo.GetFiles(filter).Any()) || dirInfo.GetDirectories().Any()) { entries.Add(new Entry { isDirectory = true, dirInfo = dirInfo, summary = "" }); } } catch (Exception ex) { Debug.LogException(ex); } } foreach (var fileInfo in supportedFileTypes.SelectMany(filter => currentDirectory.GetFiles(filter))) { try { Entry current; if (!cachedEntries.TryGetValue(fileInfo.FullName, out current)) { current = new Entry { isDirectory = false, songInfo = LoadBMS(fileInfo) }; current.summary = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", current.songInfo.name, current.songInfo.artist, current.songInfo.subArtist, current.songInfo.genre, current.songInfo.comments ); if (string.IsNullOrEmpty(current.songInfo.name)) { current.songInfo.name = fileInfo.Name; } cachedEntries.Add(fileInfo.FullName, current); } entries.Add(current); } catch (Exception ex) { Debug.LogException(ex); } } SortInThread(); ready = true; ThreadHelper.RunInUnityThread(UpdateList); } catch (ThreadAbortException) { } catch (Exception ex) { Debug.LogException(ex); } }
static IEnumerable <Entry> ReadDirectoryThreadInner(DirectoryInfo currentDirectory) { var supportedFileTypes = SupportedFileTypes; if (!string.Equals(currentDirectory.FullName, rootDiectory.FullName, StringComparison.Ordinal)) { yield return new Entry { isDirectory = true, isParentDirectory = true, dirInfo = currentDirectory, summary = "" } } ; Entry current = new Entry(); bool hasEntry = false; foreach (var dirInfo in currentDirectory.GetDirectories()) { hasEntry = false; try { if (supportedFileTypes.Any(filter => dirInfo.GetFiles(filter).Any()) || dirInfo.GetDirectories().Any()) { current = new Entry { isDirectory = true, dirInfo = dirInfo, summary = "" }; hasEntry = true; } } catch (Exception ex) { Debug.LogException(ex); } if (hasEntry) { yield return(current); } } foreach (var fileInfo in supportedFileTypes.SelectMany(filter => currentDirectory.GetFiles(filter))) { hasEntry = false; try { if (!(hasEntry = cachedEntries.TryGetValue(fileInfo.FullName, out current))) { current = new Entry { isDirectory = false, songInfo = LoadBMS(fileInfo) }; current.summary = string.Format("{0}\n{1}\n{2}\n{3}\n{4}", current.songInfo.name, current.songInfo.artist, current.songInfo.subArtist, current.songInfo.genre, current.songInfo.comments ); if (string.IsNullOrEmpty(current.songInfo.name)) { current.songInfo.name = fileInfo.Name; } cachedEntries.Add(fileInfo.FullName, current); hasEntry = true; } } catch (Exception ex) { Debug.LogException(ex); } if (hasEntry) { yield return(current); } } }