Пример #1
0
        public void ThreadPoolCallback(System.Object threadContext)
        {
            try
            {
                stopWatch.Start();
                for (int i = m_StartIndex; i < m_EndIndex; ++i)
                {
                    ResourceDependencyInfo info = m_AllResInfos[i];
                    for (int j = 0; j < info.dependencyPaths.Length; ++j)
                    {
                        string dependencyPath = info.dependencyPaths[j];
                        if (dependencyPath == info.path)
                        {
                            continue;
                        }
                        foreach (var it in m_SearchInfos)
                        {
                            if (dependencyPath.Equals(it.path))
                            {
                                it.searched = true;
                            }
                        }
                    }
                }
                stopWatch.Stop();
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat(ex.Message);
            }

            doneEvent.Set();
        }
Пример #2
0
        public void ThreadPoolCallback(System.Object threadContext)
        {
            try
            {
                for (int i = m_StartIndex; i < m_EndIndex; ++i)
                {
                    ResourceDependencyInfo info = m_AllResInfos[i];
                    for (int j = 0; j < info.dependencyPaths.Length; ++j)
                    {
                        if (info.dependencyPaths[j].Equals(m_SearchPath))
                        {
                            info.beDependend = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat(ex.Message);
            }

            doneEvent.Set();
        }
Пример #3
0
    public Dictionary <string, List <string> > FindResourceRefrences()
    {
        Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >();

        string[] allGuids = AssetDatabase.FindAssets(ResourceRefrenceWindow.SEARCH_TYPE, new string[] { m_SearchDir });

        ShowProgress(0, allGuids.Length, 0);

        ResourceDependencyInfo[] allResourcesInfos = new ResourceDependencyInfo[allGuids.Length];
        UnityEngine.Object[]     roots             = new UnityEngine.Object[1];
        for (int i = 0; i < allGuids.Length; ++i)
        {
            ResourceDependencyInfo info = new ResourceDependencyInfo();
            string guid = allGuids[i];
            string path = AssetDatabase.GUIDToAssetPath(guid);
            roots[0] = AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object));
            UnityEngine.Object[] dependency      = EditorUtility.CollectDependencies(roots);
            string[]             dependencyPaths = new string[dependency.Length];
            for (int j = 0; j < dependency.Length; ++j)
            {
                dependencyPaths[j] = AssetDatabase.GetAssetPath(dependency[j]);
            }
            info.path            = path;
            info.dependencyPaths = dependencyPaths;
            info.beDependend     = false;
            allResourcesInfos[i] = info;
        }

        int threadCounts = Mathf.Min(Environment.ProcessorCount, allGuids.Length);

        FindRefrenceSearchJob[] searchJobsArray = new FindRefrenceSearchJob[threadCounts];
        ManualResetEvent[]      events          = new ManualResetEvent[threadCounts];
        for (int i = 0; i < threadCounts; ++i)
        {
            searchJobsArray[i] = new FindRefrenceSearchJob();
            events[i]          = searchJobsArray[i].doneEvent;
        }
        int timeout    = 600000; // 10 分钟超时
        int index      = 0;
        int step       = 10;
        int startIndex = 0;

        //Less then step * threadCounts
        for (; index < threadCounts; index++)
        {
            if (index * step >= allGuids.Length)
            {
                break;
            }

            FindRefrenceSearchJob job = searchJobsArray[index];
            job.SetData(startIndex, step, allResourcesInfos, m_Src);
            ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

            ShowProgress((float)index * step / (float)(allGuids.Length), allGuids.Length, index * step);

            startIndex += step;
        }

        for (; index < threadCounts; ++index)
        {
            searchJobsArray[index].doneEvent.Set();
        }

        for (int i = index * step; i < allGuids.Length; i += step)
        {
            index = WaitForDoFile(events, timeout);
            FindRefrenceSearchJob job = searchJobsArray[index];
            job.SetData(startIndex, step, allResourcesInfos, m_Src);
            ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

            ShowProgress((float)i / (float)(allGuids.Length), allGuids.Length, i);

            startIndex += step;
        }

        WaitHandle.WaitAll(events, timeout);

        List <string> prefabList = new List <string>();
        List <string> sceneList  = new List <string>();
        List <string> matList    = new List <string>();
        List <string> otherList  = new List <string>();

        for (int i = 0; i < allResourcesInfos.Length; ++i)
        {
            ResourceDependencyInfo info = allResourcesInfos[i];
            if (!info.beDependend || info.path.Equals(m_Src))
            {
                continue;
            }
            string path = info.path.ToLower();
            if (path.EndsWith(".prefab"))
            {
                prefabList.Add(path);
                continue;
            }
            else if (path.EndsWith(".unity"))
            {
                sceneList.Add(path);
                continue;
            }
            else if (path.EndsWith(".mat"))
            {
                matList.Add(path);
                continue;
            }
            else
            {
                otherList.Add(path);
            }
        }

        dic.Add("Prefab", prefabList);
        dic.Add("Material", matList);
        dic.Add("Scene", sceneList);
        dic.Add("Other", otherList);

        EditorUtility.ClearProgressBar();

        return(dic);
    }