Beispiel #1
0
        public void RefreshFiles()
        {
            _files = _fileManager.GetFiles();
            Array.Sort(_files, (a, b) => (_fileManager.CreationDateFromPath(a)
                                          .CompareTo(_fileManager.CreationDateFromPath(b))));
            while (_fileTexts.Count > _files.Length)
            {
                GameObject toDestroy = _fileTexts[_fileTexts.Count - 1].gameObject;
                _fileTexts.RemoveAt(_fileTexts.Count - 1);
                _listedFiles.RemoveAt(_listedFiles.Count - 1);
                Destroy(toDestroy);
            }

            if (_files.Length == 0)
            {
                if (_selector != null)
                {
                    Destroy(_selector.gameObject);
                }

                if (noFilesFoundText != null)
                {
                    noFilesFoundText.gameObject.SetActive(true);
                }
            }
            else
            {
                if (_selector == null)
                {
                    _selector = Instantiate(_selectorPrefab, _textParent.transform);
                    _selector.localRotation = Quaternion.identity;
                    _selector.localScale    = Vector3.one;
                    _selector.sizeDelta     = new Vector2(_textParent.rect.width,
                                                          _textPrefab.rectTransform.rect.height);
                }

                if (noFilesFoundText != null)
                {
                    noFilesFoundText.gameObject.SetActive(false);
                }
            }

            _textParent.sizeDelta = new Vector2(_textParent.rect.width,
                                                _textPrefab.rectTransform.rect.height * _files.Length);
            float heightFromTop = 0;

            for (int i = 0; i < _files.Length; i++)
            {
                if (_fileTexts.Count < _files.Length)
                {
                    Text newText = (Text)Instantiate(_textPrefab, _textParent.transform);
                    newText.rectTransform.localRotation = Quaternion.identity;
                    newText.rectTransform.localScale    = Vector3.one;
                    newText.rectTransform.sizeDelta     = new Vector2(_textParent.rect.width,
                                                                      newText.rectTransform.rect.height);
                    _fileTexts.Add(newText);

                    ListedFile listedFile = newText.gameObject.GetComponent <ListedFile>();
                    listedFile._displayer = this;
                    _listedFiles.Add(listedFile);
                }
                string filename = _fileManager.NameFromPath(_files[i]);
                _fileTexts[i].text = Path.GetFileNameWithoutExtension(filename);
                _fileTexts[i].rectTransform.localPosition = new Vector3(
                    -_textParent.rect.width / 2F,
                    _textParent.rect.height / 2F - heightFromTop, 0F);

                _listedFiles[i].FileName  = filename;
                _listedFiles[i].FilePath  = _files[i];
                _listedFiles[i].ListIndex = i;
                heightFromTop            += _fileTexts[i].rectTransform.rect.height;
            }

            refreshSelected();
        }
Beispiel #2
0
 public void NotifyPointerDown(ListedFile listedFile)
 {
     _selectedFileIdx = listedFile.ListIndex;
     refreshSelected();
 }