示例#1
0
    public void GetFileList(DirectoryInfo di)
    {
        // Clear directories
        for (int i = directoryInformations.Count - 1; i >= 0; i--)
        {
            Destroy(directoryInformations[i].gameObject);
        }

        directoryInformations.Clear();

        for (int i = fileInformations.Count - 1; i >= 0; i--)
        {
            Destroy(fileInformations[i].gameObject);
        }

        fileInformations.Clear();

        // Set directories
        currentDirectory = di;
        parentDirectory  = currentDirectory.Parent;

        if (parentDirectory == null)
        {
            backButton.SetDisable();
        }
        else
        {
            backButton.SetEnable();
        }

        // Create directories
        DirectoryInfo[] dia = di.GetDirectories();
        for (int i = 0; i < dia.Length; i++)
        {
            if ((dia[i].Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
            {
                continue;
            }

            GameObject directoryInformation = Instantiate(directoryInformationPrefab, scrollViewContent) as GameObject;
            directoryInformation.transform.localPosition = Vector3.zero;

            DirectoryInformation dirInfo = directoryInformation.GetComponent <DirectoryInformation>();
            dirInfo.InitItem(this);
            dirInfo.SetName(dia[i].Name);

            directoryInformations.Add(dirInfo);
        }

        // Create files
        FileInfo[] fia = di.GetFiles("*");
        for (int i = 0; i < fia.Length; i++)
        {
            if (CheckFileExtension(fia[i].Name))
            {
                GameObject fileInformation = Instantiate(fileInformationPrefab, scrollViewContent) as GameObject;
                fileInformation.transform.localPosition = Vector3.zero;

                FileInformation fileInfo = fileInformation.GetComponent <FileInformation>();
                fileInfo.InitItem(this);
                fileInfo.SetName(fia[i].Name);

                fileInformations.Add(fileInfo);
            }
        }
    }