Example #1
0
    private static long LoadFilesThread(Data data, string currentPath, int indent = 0)
    {
        GUIContent content  = GetGUIContent(currentPath);
        long       dataSize = 0;

        if (content != null)
        {
            data.indent         = indent;
            data.content        = content;
            data.assetPath      = currentPath;
            data.isIllegalImage = ValidateImage(currentPath);
            data.fileMemorySize = MemorySize(currentPath);
        }

        foreach (var path in Directory.GetFiles(currentPath))
        {
            content = GetGUIContent(path);
            if (content != null)
            {
                Data child = new Data();
                child.indent         = indent + 1;
                child.content        = content;
                child.assetPath      = path;
                child.isIllegalImage = ValidateImage(path);
                child.fileMemorySize = MemorySize(path);
                //FileInfo fi = new FileInfo(path);
                //child.fileSize = fi.Length;
                //dataSize += fi.Length;
                child.fileSize = FileSize(path);
                dataSize      += child.fileSize;
                data.childs.Add(child);
            }
        }

        ThreadPars[] threadParses = new ThreadPars[ThreadCount];
        for (int index = 0; index < ThreadCount; index++)
        {
            threadParses[index] = new ThreadPars();
        }

        var i = 0;

        foreach (var path in Directory.GetDirectories(currentPath))
        {
            Data childDir = new Data();
            data.childs.Add(childDir);

            int index = i % ThreadCount;
            threadParses[index].ChildDataList.Add(childDir);
            threadParses[index].DataPathList.Add(path);
            i++;
            //dataSize += LoadFilesThread (childDir,path, indent + 1);
        }


        ThreadRun[] tRun          = new ThreadRun[ThreadCount];
        int         finishedState = ThreadCount;

        IAsyncResult[] results = new IAsyncResult[ThreadCount];



        _updateDelegate = delegate
        {
            var finishedCount = 0;
            for (int j = 0; j < ThreadCount; j++)
            {
                if (results[j].IsCompleted)
                {
                    ++finishedCount;
                }
            }

            EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount);

            if (finishedCount >= finishedState)
            {
                for (int j = 0; j < ThreadCount; j++)
                {
                    dataSize += tRun[j].EndInvoke(results[j]);
                }
                EditorUtility.ClearProgressBar();
                EditorApplication.update -= _updateDelegate;


                ArtToolsWindow window = (ArtToolsWindow)EditorWindow.GetWindow(typeof(ArtToolsWindow));
                window.Show();
                data.fileSize = dataSize;
                //LogData();
            }
        };

        for (int j = 0; j < ThreadCount; j++)
        {
            tRun[j]    = ThreadFind;
            results[j] = tRun[j].BeginInvoke(threadParses[j], null, null);
        }

        EditorApplication.update += _updateDelegate;


        data.fileSize = dataSize;
        return(dataSize);
    }
Example #2
0
 public static void OpenWindow()
 {
     ArtToolsWindow.OpenWindow();
 }