public static bool CompressABToStreamingAssetDir()
        {
            Debug.Log("正在压缩bundle到StreamingAssets目录中...");
            string from = PackagePath.GetOutAssetBundleDir();

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

            string toDir = PackagePath.GetStreamingAssetABDir();

            if (!Directory.Exists(toDir))
            {
                Directory.CreateDirectory(toDir);
            }
            string to = PackagePath.GetStreamingAssetABZipFilePath();

            try
            {
                //压缩时,会将/../这些东西打到压缩文件,导致解压时会有问题(拿文件相对目录时)
                from = new DirectoryInfo(from).FullName;
                //LaunchCompress.CompressDirExcept(from, to, ".manifest");
            }
            catch (Exception e)
            {
                Debug.LogError("compress bundle fail!msg:" + e.Message + ",StackTrace:" + e.StackTrace);
                return(false);
            }
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            return(true);
        }
        void OnGUI()
        {
            GUILayout.Space(10);
            GUILayout.Label("Package type", EditorStyles.boldLabel);
            packageType = (PackageType)EditorGUILayout.EnumPopup("type", packageType);

            GUILayout.Space(10);
            androidProjectIndex = EditorGUILayout.Popup("android project", androidProjectIndex, androidProject);
            GUILayout.Label("Build Platform", EditorStyles.boldLabel);
            platformIndex                = EditorGUILayout.Popup("Platform", platformIndex, EditorPlatformPath.BuildPlatformNames);
            PackagePath.PlatformName     = EditorPlatformPath.BuildPlatformNames[platformIndex];
            PackagePath.PackageExtension = EditorPlatformPath.BuildPlatFormExtensions[platformIndex];

            optionGroupState = EditorGUILayout.BeginToggleGroup("Build Options", optionGroupState);
            optionState[0]   = EditorGUILayout.Toggle("Development", optionState[0]);
            optionState[1]   = EditorGUILayout.Toggle("AllowDebugging", optionState[1]);
            optionState[2]   = EditorGUILayout.Toggle("ConnectWithProfiler", optionState[2]);
            EditorGUILayout.EndToggleGroup();

            GUILayout.Label("Build Package Path", EditorStyles.boldLabel);
            GUILayout.Label(PackagePath.GetPackageDir());

            if (GUILayout.Button("Build Package", GUILayout.Width(200), GUILayout.Height(30)))
            {
                PackageSettingUtil.ChangeSetting();
                PackageAndroidUtil.CopyAndroidToPublish(androidProject[androidProjectIndex]);
                PackageUtil.Package(packageType, EditorPlatformPath.BuildPlatforms[platformIndex], GetBuildOpetions());
            }
        }
        //将打包的版本文件拷贝到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);
        }
        private static void BuildResource(BuildTarget buildTarget, BuildOptions buildOptions)
        {
            //新建resource文件下的Lua代码目录
            PackageResourceLuaUtil.CheckAndCreateLuaTempDir();
            //将lua文件拷贝到Resource下
            PackageResourceLuaUtil.CopyLuaFileToResourceDirAndRenameExt();
            //打包
            string packageName = PackagePath.GetPackagePath(PackageType.Resource);

            Directory.CreateDirectory(packageName);
            BuildPipeline.BuildPlayer(GetAllBuildScenes(), packageName, buildTarget, buildOptions);
            //最后删除临时目录
            PackageResourceLuaUtil.ClearLuaTempDir();
            AssetDatabase.Refresh();

            //打开包所在的文件夹
            System.Diagnostics.Process.Start(PackagePath.GetPackagePathDir(PackageType.Resource));
        }
        private static void BuildAssetBundle(BuildTarget buildTarget, BuildOptions buildOptions)
        {
            //将所有的bundle文件拷贝到streamingasset文件
            PackageAssetBundleUtil.CheckAndCreateAssetBundleDir();
            //将assetbundle压缩到streamingAsset
            //if(!PackageAssetBundleUtil.CopyABToStreamingAssetDir())
            if (!PackageAssetBundleUtil.CompressABToStreamingAssetDir())
            {
                PackageAssetBundleUtil.ClearAssetBundleDir();
                AssetDatabase.Refresh();
                return;
            }
            //将版本文件拷贝到Resource目录
            if (!PackageAssetBundleUtil.CopyVersionTxtToResourceDir())
            {
                PackageAssetBundleUtil.ClearAssetBundleDir();
                AssetDatabase.Refresh();
                return;
            }
            //打包
            string packageName = PackagePath.GetPackagePath(PackageType.AssetBundle);

            Directory.CreateDirectory(packageName);
            Debug.Log("packageName:" + packageName);

            BuildPipeline.BuildPlayer(PackagePath.sceneNames, packageName, buildTarget, buildOptions);

            //删除streamingAsset中的bundle目录
            PackageAssetBundleUtil.ClearAssetBundleDir();
            //删除拷贝到Resources目录的版本文件
            PackageAssetBundleUtil.ClearResourceVersionFileDir();
            AssetDatabase.Refresh();

            //打开包所在的文件夹
            System.Diagnostics.Process.Start(PackagePath.GetPackagePathDir(PackageType.AssetBundle));
        }