コード例 #1
0
    public static void CheckTwoFolderTexName()
    {
        Object[] objects = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
        if (objects.Length != 2)
        {
            Debug.LogError(string.Format("{0}", "文件夹个数不为2"));
            return;
        }

        List <string>[]   lists     = new List <string> [objects.Length];
        List <FileInfo>[] fileLists = new List <FileInfo> [objects.Length];

        for (int i = 0; i < objects.Length; i++)
        {
            lists[i]     = new List <string>();
            fileLists[i] = new List <FileInfo>();

            DirectoryInfo directInfo = new DirectoryInfo(AssetDatabase.GetAssetPath(objects[i]));

            string   imgtype   = "*.BMP|*.JPG|*.GIF|*.PNG";
            string[] ImageType = imgtype.Split('|');
            for (int j = 0; j < ImageType.Length; j++)
            {
                FileInfo[] files = directInfo.GetFiles(ImageType[j], SearchOption.AllDirectories);
                for (int k = 0; k < files.Length; k++)
                {
                    lists[i].Add(files[k].Name);
                    fileLists[i].Add(files[k]);
                    //Debug.Log(string.Format("{0}\n,{1}\n,{2}\n", files[k].DirectoryName, files[k].FullName, files[k].Name));
                }
            }
        }

        List <string> sameList       = LinqUtil.CustomIntersect(lists[0], lists[1]);
        List <string> differenceList = LinqUtil.CustomExcept(lists[0], lists[1]);

        for (int i = 0; i < sameList.Count; i++)
        {
            Debug.Log("sameList = " + sameList[i]);
        }

        for (int i = 0; i < differenceList.Count; i++)
        {
            Debug.Log("differenceList = " + differenceList[i]);
        }

        /*如果加了这句,就可以将两个不同的名字改为相同的名字
         * for (int i = 0; i < differenceList.Count; i++)
         * {
         *  for (int j = 0; j < fileLists[0].Count; j++)
         *  {
         *      if (fileLists[0][j].Name == differenceList[i])
         *      {
         *          string oldName = GetPathByFullName(fileLists[0][j].FullName);
         *          AssetDatabase.RenameAsset(oldName, fileLists[1][j].Name);
         *          AssetDatabase.SaveAssets();
         *          AssetDatabase.Refresh();
         *      }
         *  }
         * }*/
    }