public void CheckFileStatus() { if (this.showFileStatus) { if (this.selectedFile != null && this.selectedFile.IsSelected == false) { this.needAnimationForShowFile = true; } } else { foreach (FileThumbnail thumbnail in this.fileThumbnails) { if (thumbnail.IsSelected) { if (this.selectedFile == null || this.selectedFile != thumbnail) { this.RenderFile(thumbnail.FileFolder); this.selectedFile = thumbnail; } this.needAnimationForShowFile = true; } } } if (this.needAnimationForShowFile && this.showFileStatus == false) { foreach (FileThumbnail thumbnail in this.fileThumbnails) { thumbnail.SetTextVisiable(false); } } }
/// <summary> /// 以IO方式进行加载 /// </summary> private void RenderUI() { double startTime = (double)Time.time; string[] folders = Directory.GetDirectories(this.FileFolder); int availableFolderIndex = 0; float thumbnailWidth = 1f / 5f; for (int folderIndex = 0; folderIndex < folders.Length; folderIndex++) { string folder = folders [folderIndex]; FileAttributes attr = File.GetAttributes(folder); //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { int yIndex = availableFolderIndex / 5; int xIndex = availableFolderIndex % 5; Vector3 pos = new Vector3(0.4f - xIndex * thumbnailWidth, 0.3f - yIndex * (thumbnailWidth + 0.05f), 0.38f); print(pos); GameObject thumbnail = (GameObject)Instantiate(this.ThumbnailPrefab, Vector3.zero, Quaternion.identity); FileThumbnail fileThumbnail = thumbnail.GetComponent <FileThumbnail> (); fileThumbnail.FileFolder = folder; string[] files = Directory.GetFiles(folder); for (int index = 0; index < files.Length; index++) { string filePath = files [index]; int lastIndex = filePath.LastIndexOf('/'); if (lastIndex < 0) { lastIndex = this.FileFolder.LastIndexOf('\\'); } string fileName = filePath.Substring(lastIndex + 1); if (fileName.StartsWith(".")) { continue; } if (filePath.ToLower().EndsWith(".jpg") || filePath.ToLower().EndsWith(".png")) { fileThumbnail.Thumbnail = filePath; break; } } thumbnail.transform.parent = this.FilesCatalog.transform; thumbnail.transform.localPosition = pos; this.fileThumbnails.Add(fileThumbnail); availableFolderIndex++; } } double costTime = (double)Time.time - startTime; Debug.Log("IO加载用时:" + costTime); }