public override IPlugin ExecutePlugin()
        {
            ConfigItem.PluginRunContext = this;
            if (Plugins.ContainsKey(ConfigItem.Url))
            {
                _init[ConfigItem.Url] = false;
                IPlugin thePlugin = Plugins[ConfigItem.Url];
                ProcessParametricPlugin(thePlugin);
                thePlugin.InitPlugin(ConfigItem, Context);
                thePlugin.ShowPlugin(ConfigItem, Context);
                return(Plugins[ConfigItem.Url]);
            }
            else
            {
                AutoResetEvent theSignal = new AutoResetEvent(false);
                ThreadRun      runThread = new ThreadRun(ConfigItem, Context, theSignal, Plugins, this);
                ThreadStart    ts        = new ThreadStart(runThread.Run);
                Thread         td        = new Thread(ts);
                td.SetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Name         = ConfigItem.Url;
                td.Start();
                _init[ConfigItem.Url] = true;
                theSignal.WaitOne();

                theSignal.Close();
                return(Plugins[ConfigItem.Url]);
            }
        }
        public override IPlugin ExecutePlugin()
        {
            ConfigItem.PluginRunContext = this;
            if (Plugins.ContainsKey(ConfigItem.Url))
            {
                _init[ConfigItem.Url] = false;
                IPlugin thePlugin = Plugins[ConfigItem.Url];
                ProcessParametricPlugin(thePlugin);
                thePlugin.InitPlugin(ConfigItem, Context);
                thePlugin.ShowPlugin(ConfigItem, Context);
                return Plugins[ConfigItem.Url];
            }
            else
            {
                AutoResetEvent theSignal = new AutoResetEvent(false);
                ThreadRun runThread = new ThreadRun(ConfigItem, Context, theSignal, Plugins, this);
                ThreadStart ts = new ThreadStart(runThread.Run);
                Thread td = new Thread(ts);
                td.SetApartmentState(ApartmentState.STA);
                td.IsBackground = true;
                td.Name = ConfigItem.Url;
                td.Start();
                _init[ConfigItem.Url] = true;
                theSignal.WaitOne();

                theSignal.Close();
                return Plugins[ConfigItem.Url];
            }
        }
Example #3
0
    private void StartCheck()
    {
        EditorSettings.serializationMode = SerializationMode.ForceText;
        AssetDatabase.Refresh();

        List <string> imagePaths = UIAssetUtils.GetAllImages(false);

        imagePaths = imagePaths.Where(s => !Regex.IsMatch(s, "ColorPokerCard")).Where(s => !Regex.IsMatch(s, "PokerCard")).ToList();


        List <string> withoutExtensions = new List <string>()
        {
            ".prefab", ".unity", ".mat", ".cs"
        };

        string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories)
                         .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();

        //预先load内容
        List <string> assetContents = new List <string>();

        foreach (var file in files)
        {
            assetContents.Add(File.ReadAllText(file));
        }
        files = Directory.GetFiles("Codes", "*.*", SearchOption.AllDirectories)
                .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
        List <string> codeContents = new List <string>();

        foreach (var file in files)
        {
            codeContents.Add(File.ReadAllText(file));
        }

        ThreadPars[] threadParses = new ThreadPars[ThreadCount];
        for (int i = 0; i < ThreadCount; i++)//添加查找的范围内容
        {
            threadParses[i] = new ThreadPars();
            threadParses[i].assetContents = assetContents;
            threadParses[i].codeContents  = codeContents;
        }

        for (int i = 0; i < imagePaths.Count; i++)
        {
            int index = i % ThreadCount;
            threadParses[index].imagePaths.Add(imagePaths[i]);
            threadParses[index].imageGUIDPaths.Add(AssetDatabase.AssetPathToGUID(imagePaths[i]));
        }

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

        IAsyncResult[] results = new IAsyncResult[ThreadCount];

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

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

            if (finishedCount >= finishedState)
            {
                for (int i = 0; i < ThreadCount; i++)
                {
                    List <string> temRunThreadData = tRun[i].EndInvoke(results[i]);
                    foreach (var path in temRunThreadData)
                    {
                        Results.Add(path);
                    }
                }

                EditorUtility.ClearProgressBar();
                EditorApplication.update -= _updateDelegate;
                this.ShowNotification(new GUIContent("查找完成!"));
                isDone = true;
                watch.Stop();
                UnityEngine.Debug.Log("累计用时:" + watch.ElapsedMilliseconds);
            }
        };

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

        EditorApplication.update += _updateDelegate;
    }
Example #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     threadX = new ThreadRun(textBox1.Text, textBox2.Text, this);
     ThreadRun.Begin();
 }
Example #5
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 #6
0
    //[MenuItem("Assets/Find References Thread",false,10)]
    public static void FindThread(string path, bool outExcel = false)
    {
        refDic.Clear();
        EditorSettings.serializationMode = SerializationMode.ForceText;
        AssetDatabase.Refresh();
        //string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        if (!string.IsNullOrEmpty(path))
        {
            List <string> _AssetGuidList = new List <string>();
            List <string> _AssetNameList = new List <string>();
            if (Directory.Exists(path))
            {
                string[] assetPathsFromFolder = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

                foreach (var tempPath in assetPathsFromFolder)
                {
                    if (!tempPath.EndsWith(".meta"))
                    {
                        var assetFindPath = GetRelativeAssetsPath(tempPath);
                        _AssetNameList.Add(assetFindPath);
                        _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(assetFindPath));
                    }
                }
            }
            else
            {
                _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(path));
                _AssetNameList.Add(path);
            }

            ThreadPars[] threadParses = new ThreadPars[ThreadCount];
            for (int i = 0; i < ThreadCount; i++)//添加查找的udid
            {
                threadParses[i] = new ThreadPars();
                threadParses[i].AssetGuidList = _AssetGuidList;
                threadParses[i].AssetNameList = _AssetNameList;
            }


            List <string> withoutExtensions = new List <string>()
            {
                ".prefab", ".unity", ".mat", ".asset"
            };
            string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories)
                             .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();
            for (int i = 0; i < files.Length; i++)//添加要查找的资源文件
            {
                int index = i % ThreadCount;
                threadParses[index].CheckAssetList.Add(files[i]);
            }


            string[] csFiles = Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories)
                               .Where(s => s.IndexOf("/editor/", System.StringComparison.OrdinalIgnoreCase) < 0).ToArray();
            for (int i = 0; i < csFiles.Length; i++)//添加要查找的CS文件
            {
                int index = i % ThreadCount;
                threadParses[index].CheckCSList.Add(csFiles[i]);
            }

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

            IAsyncResult[] results = new IAsyncResult[ThreadCount];

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

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

                if (finishedCount >= finishedState)
                {
                    for (int i = 0; i < ThreadCount; i++)
                    {
                        Dictionary <string, List <string> > temRunThreadData = tRun[i].EndInvoke(results[i]);
                        foreach (var keyValue in temRunThreadData)
                        {
                            var key = keyValue.Key;
                            if (key.Contains("/") || key.Contains("\\"))
                            {
                                key = AssetDatabase.AssetPathToGUID(key);
                            }

                            if (refDic.ContainsKey(key))
                            {
                                refDic[key].AddRange(keyValue.Value);
                            }
                            else
                            {
                                refDic.Add(key, keyValue.Value);
                            }
                        }
                    }

                    EditorUtility.ClearProgressBar();
                    EditorApplication.update -= _updateDelegate;

                    if (outExcel)
                    {
                        OutputToExcel();
                    }
                    else
                    {
                        FindReferences01 window = (FindReferences01)EditorWindow.GetWindow(typeof(FindReferences01));
                        window.Show();
                    }
                }
            };

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

            EditorApplication.update += _updateDelegate;
        }
    }