void UpdateView() { // Clear all current buttons for (int i = 0; i < _tCurrentView.Count; i++) { Destroy(_tCurrentView[i].gameObject); } _tCurrentView.Clear(); // For each faborite, create a button with the right label and the right path to to folder to open for (int i = 0; i < _sFavorites.Count; i++) { GameObject tNewButtonGO = Instantiate(_tButtonTemplate.gameObject); tNewButtonGO.SetActive(true); tNewButtonGO.transform.SetParent(_tButtonTemplate.transform.parent); FileBrowser_Button tNewButton = tNewButtonGO.GetComponent <FileBrowser_Button>(); tNewButton.Init(FileBrowser_UI.ButtonType.Folder, _sFavorites[i], new DirectoryInfo(_sFavorites[i]).Name); _tCurrentView.Add(tNewButton); } }
public void SetHeight(float fValue) { FileBrowser_UI.Instance._tVirtualView._fHeight = fValue; FileBrowser_UI.Instance._tVirtualView.UpdateLook(); Transform tView = FileBrowser_UI.Instance._tVirtualView._tScrollRect.content.transform; for (int i = 0; i < tView.childCount; i++) { FileBrowser_Button tButton = tView.GetChild(i).GetComponent <FileBrowser_Button>(); if (tButton != null) { Vector2 tDelta = tButton._tSubImage.rectTransform.sizeDelta; tDelta.x = fValue - 10; tButton._tSubImage.rectTransform.sizeDelta = tDelta; Vector2 tPosition = tButton._sLabel.rectTransform.offsetMin; tPosition.x = fValue + 5; tButton._sLabel.rectTransform.offsetMin = tPosition; } } }
// Set currently selected button public void SetSelected(FileBrowser_Button tSelected) { _tLastSelected = tSelected; _tCurrentlySelected = tSelected; _fDoubleClickTime = Time.realtimeSinceStartup; }
IEnumerator Coroutine_GenerateThumbnails(FileBrowser_Button tButton) { FileInfo tInfo = new FileInfo(tButton._sPath); if (tInfo.Exists) { // Check if file has the correct extension bool bOK = false; for (int j = 0; j < _tThumbnailsFilter.Length; j++) { if (tInfo.Extension.ToLower().Contains(_tThumbnailsFilter[j].ToLower())) { bOK = true; } } if (bOK) { // Retrieve file asyncronously WWW tWWW = new WWW("file://" + tButton._sPath); while (!tWWW.isDone) { yield return(null); } if (string.IsNullOrEmpty(tWWW.error)) { _tTextureHigh = tWWW.texture; if (_tTextureHigh != null) { // Adapat thumbnail size to texture ratio int iW = _tThumbnailsSize; int iH = _tThumbnailsSize; if (_tTextureHigh.width < _tTextureHigh.height) { iW = (int)((float)_tTextureHigh.width / _tTextureHigh.height * _tThumbnailsSize); } else if (_tTextureHigh.height < _tTextureHigh.width) { iH = (int)((float)_tTextureHigh.height / _tTextureHigh.width * _tThumbnailsSize); } // Start thread to resize image to thumbnail size _tThread = new Thread_Thumbnails(_tTextureHigh, iW, iH); _tThread.Start(); yield return(StartCoroutine(_tThread.WaitFor())); // Set image as sprite for the UI _tTextureLow = _tThread._tResult; tButton._tSubImage.sprite = Sprite.Create(_tTextureLow, new Rect(0, 0, iW, iH), Vector2.one * 0.5f); tButton._tSubImage.color = Color.white; _tThread.Abort(); _tThread = null; _tTextureHigh = null; _tTextureLow = null; } } } yield return(null); } }
public void GenerateThumbnails(FileBrowser_Button tButton) { CancelGeneration(); StartCoroutine(Coroutine_GenerateThumbnails(tButton)); }