//将lua文件拷贝到resource下,并改后缀名
        public static void CopyLuaFileToResourceDirAndRenameExt()
        {
            string[]      paths      = PackagePath.LuaSouceCodePaths;
            string        toDir      = PackagePath.ResourceLuaCodePath;
            List <string> movedFiles = new List <string>();

            for (int i = 0; i < paths.Length; i++)
            {
                string path = paths[i];
                if (Directory.Exists(path))
                {
                    EditorFileOperate.CopyToRenameExtension(path, toDir, "*.lua", ".bytes", movedFiles);
                }
            }
            //将移动的文件保存起来
            if (File.Exists(PackagePath.ResourceLuaCodeFileCfgPath))
            {
                File.Delete(PackagePath.ResourceLuaCodeFileCfgPath);
            }
            string fileNames = "";

            for (int i = 0; i < movedFiles.Count; i++)
            {
                string file         = movedFiles[i];
                string realFileName = file.Replace(PackagePath.GameAssetsDirectory, "");
                fileNames += realFileName + ",";
            }
            if (fileNames.EndsWith(","))
            {
                fileNames = fileNames.Substring(0, fileNames.Length - 1);
            }
            File.WriteAllText(PackagePath.ResourceLuaCodeFileCfgPath, fileNames);
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
        private static void RemoveNonexistAssetBundleFiles()
        {
            string assetBundleDir = AssetBundlePath.GetAssetBundlePath();

            if (!Directory.Exists(assetBundleDir))
            {
                return;
            }
            //把所有会的bundle文件统计出来,再去检索已存在的bundle,把不存在的移除掉
            List <AssetBundleBuildSearchInfo> allAssetBundleInfos = new List <AssetBundleBuildSearchInfo>();

            foreach (AssetbundleBuildSearchGroupInfo group in AssetBundleConfig.GetAllGroupInfos())
            {
                allAssetBundleInfos.AddRange(group.buildAssets);
            }

            HashSet <string> onlyMoveFileList = new HashSet <string>();

            //以下不移除
            onlyMoveFileList.Add(AssetBundlePath.GetAssetBundleEntryPath().Replace(assetBundleDir, ""));
            onlyMoveFileList.Add(AssetBundlePath.GetManifestAssetBundlePath());
            onlyMoveFileList.Add(AssetBundlePath.GetManifestAssetBundlePath() + ".manifest");

            HashSet <string> hasFilePaths = new HashSet <string>();

            foreach (string s in buildResultInfo.onlyMoveFileList)
            {
                onlyMoveFileList.Add(s);
            }
            foreach (var build in buildResultInfo.needBuildList)
            {
                hasFilePaths.Add(assetBundleDir + build.assetBundleName);
                hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".manifest");
                hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".meta");
                hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".manifest.meta");
            }
            foreach (string path in onlyMoveFileList)
            {
                string p = path.Replace("\\", "/").Replace(AssetBundlePath.ProjectGameAssetsDirectory, "").ToLower();
                hasFilePaths.Add(assetBundleDir + p);
                hasFilePaths.Add(assetBundleDir + p + ".meta");
            }

            string[] files = Directory.GetFiles(assetBundleDir, "*.*", SearchOption.AllDirectories);
            foreach (string f in files)
            {
                string filePath = f.Replace("\\", "/");
                if (!hasFilePaths.Contains(filePath))
                {
                    Debug.Log("移除不存在的历史Bundle>>" + filePath);
                    File.Delete(filePath);
                }
            }

            EditorFileOperate.RemoveEmptyDir(assetBundleDir);
            AssetDatabase.Refresh();
        }
        public static void CheckAndCreateLuaTempDir()
        {
            string path = AssetBundlePath.LuaTempDir;

            if (Directory.Exists(path))
            {
                EditorFileOperate.RemoveDir(path);
            }
            Directory.CreateDirectory(path);
        }
        public static void CheckAndCreateLuaTempDir()
        {
            string path = PackagePath.ResourceLuaCodePath;

            if (Directory.Exists(path))
            {
                EditorFileOperate.RemoveDir(path);
            }
            Directory.CreateDirectory(path);
        }
        public static void CheckAndCreateAssetBundleDir()
        {
            string path = PackagePath.StreamingAssetABDir;

            if (Directory.Exists(path))
            {
                EditorFileOperate.RemoveDir(path);
            }
            Directory.CreateDirectory(path);
        }
 //将lua文件拷贝到临时文件,并改后缀名
 public static string CopyLuaFileToTempDirAndRenameExt(string path)
 {
     if (Directory.Exists(path))
     {
         string        tempDir = AssetBundlePath.LuaTempDir;
         DirectoryInfo dir     = Directory.CreateDirectory(path);
         //string toDir = tempDir + dir.FullName.Replace("\\","/").Replace(AssetBundlePath.ProjectDirWithAsset, "");
         string toDir = tempDir;
         EditorFileOperate.CopyToRenameExtension(path, toDir, "*.lua", ".bytes");
         AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
         return(toDir);
     }
     return(null);
 }
        //将打包的版本文件拷贝到Resource目录下(用来与包外版本号对比用,发生未知错误时的判定)
        public static bool CopyVersionTxtToResourceDir()
        {
            string from = PackagePath.GetOutVersionFile();
            string to   = PackagePath.ResourceVersionFile;

            if (!File.Exists(from))
            {
                Debug.LogError("can not find version file:path=" + from);
                return(false);
            }
            EditorFileOperate.CopyTo(from, to, null);
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            return(true);
        }
        public static bool CopyABToStreamingAssetDir()
        {
            string from = PackagePath.GetOutAssetBundleDir();

            if (!Directory.Exists(from))
            {
                Debug.LogError("can not find ab dir:path =" + from);
                return(false);
            }
            string to = PackagePath.GetStreamingAssetABDir();

            EditorFileOperate.CopyTo(from, to, ".manifest");
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            return(true);
        }
 public static void ClearLuaTempDir()
 {
     EditorFileOperate.RemoveDir(AssetBundlePath.LuaTempDir);
 }
 public static void ClearLuaTempDir()
 {
     EditorFileOperate.RemoveDir(PackagePath.ResourceLuaCodePath);
 }
 public static void ClearResourceVersionFileDir()
 {
     EditorFileOperate.RemoveFile(PackagePath.ResourceVersionFile);
 }
 public static void ClearAssetBundleDir()
 {
     Debug.Log("移除streamingAssets目录");
     EditorFileOperate.RemoveDir(PackagePath.StreamingAssetABDir);
 }