Esempio n. 1
0
    public static Dictionary <string, string> GetFilesMD5(string path, string ext)
    {
        Dictionary <string, string> fileMd5Map = new Dictionary <string, string>();
        var files = EditorFileUtility.FilterDirectory(path, new string[] { ext });

        if (files != null)
        {
            foreach (var file in files)
            {
                var md5 = EditorFileUtility.GetMD5HashFromFile(file.FullName);
                fileMd5Map.Add(file.FullName, md5);
            }
        }

        return(fileMd5Map);
    }
Esempio n. 2
0
    public static void CheckResourceReference()
    {
        var filePaths = EditorFileUtility.FilterDirectoryIgnoreExt(Application.dataPath + "/Resources",
                                                                   IgnoreFileExtensionList);

        var rootPath = Path.GetDirectoryName(Application.dataPath);

        rootPath = rootPath.Replace("\\", "/") + "/";

        if (filePaths != null)
        {
            Queue <string> assetQueue = new Queue <string>();
            foreach (var filePath in filePaths)
            {
                var path = filePath.Replace("\\", "/");
                path = path.Replace(rootPath, "");
                assetQueue.Enqueue(path);
            }

            while (assetQueue.Count > 0)
            {
                var path = assetQueue.Dequeue();
                if (GameAssets.ContainsKey(path))
                {
                    continue;
                }

                GetAssetDependences(assetQueue, path);
            }

            Dictionary <string, List <string> > sameAssets = new Dictionary <string, List <string> >();
            foreach (var gameAsset in GameAssets)
            {
                var md5 =
                    EditorFileUtility.GetMD5HashFromFile(Path.GetDirectoryName(Application.dataPath) + "/" +
                                                         gameAsset.Value.Path);
                if (!sameAssets.ContainsKey(md5))
                {
                    sameAssets.Add(md5, new List <string>());
                    sameAssets[md5].Add(gameAsset.Value.Path);
                }
                else
                {
                    sameAssets[md5].Add(gameAsset.Value.Path);
                }
            }

            StringBuilder sb = new StringBuilder();
            foreach (var asset in sameAssets)
            {
                if (asset.Value.Count > 1)
                {
                    sb.AppendLine("MD5: " + asset.Key);
                    foreach (var p in asset.Value)
                    {
                        sb.AppendLine("\t资源路径:" + p);
                        foreach (var gameAsset in GameAssets)
                        {
                            foreach (var cd in gameAsset.Value.ChildDependences)
                            {
                                if (cd == p)
                                {
                                    sb.AppendLine("\t\t引用到它的资源:" + gameAsset.Key);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            sb.AppendLine();

            sb.AppendLine("Resources目录下未被直接引用的资源(可能是代码中引用)");
            foreach (var gameAsset in GameAssets)
            {
                var hasRefer = false;
                foreach (var gameAsset1 in GameAssets)
                {
                    var isRefer = false;
                    foreach (var cd in gameAsset1.Value.ChildDependences)
                    {
                        if (cd == gameAsset.Value.Path)
                        {
                            isRefer = true;
                            break;
                        }
                    }
                    if (isRefer)
                    {
                        hasRefer = true;
                        break;
                    }
                }

                if (!hasRefer)
                {
                    sb.AppendLine("\t资源路径:" + gameAsset.Value.Path);
                }
            }

            File.WriteAllText(Path.GetDirectoryName(Application.dataPath) + "/CheckResourceReference.txt", sb.ToString());
            WindowsOSUtility.ExploreFile(Path.GetDirectoryName(Application.dataPath));
        }
    }