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();
        }
        void OnGUI()
        {
            GUILayout.Space(10);
            AssetBundleConfig.Init();

            GUILayout.Label("Build Platform", EditorStyles.boldLabel);
            platformIndex = EditorGUILayout.Popup("Platform", platformIndex, EditorPlatformPath.BuildPlatformNames);
            AssetBundlePath.PackingPlatformName = EditorPlatformPath.BuildPlatformNames[platformIndex];

            GUILayout.BeginHorizontal();
            isForceRebuild = GUILayout.Toggle(isForceRebuild, "  Force Rebuild");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            isOnlyBuildLua = GUILayout.Toggle(isOnlyBuildLua, "  Only Build LuaFile(只打lua文件,仅支持lua文件中内容更改,不支持添加或删除lua文件)");
            GUILayout.EndHorizontal();

            GUILayout.Label("Build AssetBundle Path", EditorStyles.boldLabel);
            GUILayout.Label(AssetBundlePath.GetAssetBundlePath());

            //GUILayout.BeginHorizontal();
            //if (GUILayout.Button("Included Shaders", GUILayout.Width(200), GUILayout.Height(30)))
            //{
            //    IncludeShaders();
            //}
            //GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Build AssetBundle", GUILayout.Width(200), GUILayout.Height(30)))
            {
                AssetBundleBuildUtil.StartBuildAssetBundle(EditorPlatformPath.BuildPlatforms[platformIndex], isForceRebuild, isOnlyBuildLua);
                //打出版本文件
                AssetVersionUtil.GenerateVersionInfoFile(AssetBundlePath.GetAssetBundlePath());
            }

            //分析器后面再加
            //if (GUILayout.Button("Asset Bundle Analyze", GUILayout.Width(150), GUILayout.Height(30)))
            //{
            //    AssetBundleBuildUtil.IsBuild = false;
            //    AssetBundleBuildUtil.StartBuildAssetBundle(EditorPlatformPath.BuildPlatforms[platformIndex]);//, groupNames[groupIndex]);
            //    AssetBundleAnalyzeUtil.StartAnalyze(AssetBundlePath.PackingPlatformName, AssetBundlePath.QualityName);
            //}
            //GUILayout.Space(20);
            //if (GUILayout.Button("Manifest Analyze", GUILayout.Width(150), GUILayout.Height(30)))
            //{
            //    AssetBundleBuildUtil.IsBuild = false;
            //    AssetBundleAnalyzeUtil.AnalizeBuildedAll(AssetBundlePath.GetAssetBundlePath());
            //    AssetBundleAnalyzeUtil.StartAnalyze(AssetBundlePath.PackingPlatformName, AssetBundlePath.QualityName);
            //}
            GUILayout.EndHorizontal();
        }
        public static bool StartBuildAssetBundle(BuildTarget platform, bool isForceRebuild = false, bool onlyBuildLua = false)
        {
            AssetBundleBuildLuaUtil.CheckAndCreateLuaTempDir();

            buildResultInfo = AssetBundleBuildParseUtil.GenarateAssetBundleBuildDatas(AssetBundleConfig.GetAllGroupInfos());

            //暂时移除所有的已有bundle(即每次重新打包)
            //EditorFileOperate.RemoveDir(AssetBundlePath.GetAssetBundlePath());
            //移除不存在的bundle资源文件与文件夹
            RemoveNonexistAssetBundleFiles();

            AssetBundleBuild[] needBuildFileList = buildResultInfo.ToBuildArray();
            HashSet <string>   onlyMoveFileList  = buildResultInfo.onlyMoveFileList;

            EditorPlatformPath.CheckDirExists(AssetBundlePath.GetAssetBundlePath());

            AssetBundleBuild[] realBuildFileList = needBuildFileList;
            if (onlyBuildLua)
            {
                List <AssetBundleBuild> tempList = new List <AssetBundleBuild>();
                for (int i = 0; i < needBuildFileList.Length; i++)
                {
                    if (needBuildFileList[i].assetBundleName.IndexOf(AssetBundlePath.LuaBundleNamePre) != -1)
                    {
                        tempList.Add(needBuildFileList[i]);
                    }
                }
                realBuildFileList = tempList.ToArray();
            }
            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(AssetBundlePath.GetAssetBundlePath(), realBuildFileList, isForceRebuild ? BuildAssetBundleOptions.ForceRebuildAssetBundle : BuildAssetBundleOptions.None, platform);

            AssetBundleBuildLuaUtil.ClearLuaTempDir();
            bool succ = true;

            if (manifest == null)
            {
                Debug.Log("BuildAssetBundle Fail!");
                return(false);
            }
            //如果只打lua文件,不需要移动这些
            if (!onlyBuildLua)
            {
                MoveFiles(onlyMoveFileList);
                MoveManifestAB();
            }
            else
            {
                DeleteManifestAB();
            }

            succ = succ && GenerateAssetBundleMappings(needBuildFileList);

            //MoveMainAssetBundle();
            //ChageAssetBundleManifetDependToRelativePath();

            AssetDatabase.Refresh();
            if (succ)
            {
                Debug.Log("BuildAssetBundle Success!");
            }
            else
            {
                Debug.Log("BuildAssetBundle Fail!");
            }
            return(true);
        }