Exemplo n.º 1
0
    /// <summary>
    /// 标记文件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="packOption"></param>
    private void MarkDirectory(DirectoryInfo dirInfo, PackOption packOption)
    {
        FileInfo[]      files        = null;
        DirectoryInfo[] subDirectory = null;
        switch (packOption)
        {
        case PackOption.AllFiles:
            files = dirInfo.GetFiles("*", SearchOption.AllDirectories);            // 取出所有文件
            break;

        case PackOption.TopDirectiony:
            files        = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);   // 取出第一层文件
            subDirectory = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);
            foreach (var item in subDirectory)
            {
                MarkDirectory(item, PackOption.AllFiles);
            }
            break;

        case PackOption.AllDirectiony:
            files        = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);   // 取出第一层文件
            subDirectory = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);
            foreach (var item in subDirectory)
            {
                MarkDirectory(item, PackOption.AllDirectiony);
            }
            break;
        }



        // 标记
        int    total  = files.Length;
        string abName = dirInfo.FullName.Substring(dirInfo.FullName.IndexOf("Assets", StringComparison.Ordinal));

        for (int i = 0; i < total; i++)
        {
            var fileInfo = files[i];

            if (fileInfo.Name.EndsWith(".mata"))
            {
                continue;
            }

            EditorUtility.DisplayProgressBar(dirInfo.Name, $"正在标记资源{fileInfo.Name}...", (float)i / total);

            string filePath = fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets", StringComparison.Ordinal)); // 获取 "Assets"目录起的 文件名, 可不用转 "\\"

            AssetImporter importer = AssetImporter.GetAtPath(filePath);                                                   // 拿到该文件的 AssetImporter
            if (importer)
            {
                importer.assetBundleName    = abName;
                importer.assetBundleVariant = "ab";
                //importer.SaveAndReimport();
            }
        }
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 2
0
        private static int RunPackOption(PackOption packOption)
        {
            Console.WriteLine("开始打包");
            var packageFile = new FileInfo("Package.xml");

            if (!packageFile.Exists)
            {
                Console.WriteLine("打包文件" + packageFile.FullName + "不存在");
                return(-1);
            }

            Console.WriteLine("开始解析");

            try
            {
                var package = MedaltraFairjousuFowluNererisMoubeturce.ParseFile(packageFile.FullName);

                var regex = new Regex(@"^[a-zA-Z0-9]+$");

                if (string.IsNullOrEmpty(package.Name) || !regex.IsMatch(package.Name) ||
                    (package.Name[0] >= '0' && package.Name[0] <= '9'))
                {
                    throw new ArgumentException($"上传 package 的 Name 不符合规范");
                }

                if (!File.Exists("File\\" + package.File))
                {
                    Console.WriteLine("入口文件" + Path.GetFullPath("File\\" + package.File) + "不存在");
                    return(-1);
                }

                var file = Path.GetTempFileName();
                File.Delete(file);
                ZipFile.CreateFromDirectory(Environment.CurrentDirectory, file);
                var moveFile = Path.Combine(Environment.CurrentDirectory, package.Name + package.Version + ".zip");
                if (File.Exists(moveFile))
                {
                    File.Delete(moveFile);
                }

                File.Move(file, moveFile);

                Console.WriteLine("完成");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(-1);
            }

            return(0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 标记文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="packOption"></param>
        public static List <AssetBundleBuild> MarkDirectory(DirectoryInfo dirInfo, PackOption packOption, bool isRootNameEqualAsset = true)
        {
            List <AssetBundleBuild> builds = new List <AssetBundleBuild>();

            if (isRootNameEqualAsset)
            {
                MarkDirectory(dirInfo, packOption, "Assets", ref builds);
            }
            else
            {
                MarkDirectory(dirInfo, packOption, dirInfo.Name, ref builds);
            }

            return(builds);
        }
Exemplo n.º 4
0
 public DefaultPackageProviderService(PackOption packOption, ISerializeService serializeService, IHttpClientFactory httpClientFactory)
 {
     this.packOption        = packOption;
     this.serializeService  = serializeService;
     this.httpClientFactory = httpClientFactory;
 }
Exemplo n.º 5
0
 public static PersistencePack CreateData(PackOption option) => new PersistencePack(option);
Exemplo n.º 6
0
        /// <summary>
        /// 标记文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="packOption"></param>
        private static void MarkDirectory(DirectoryInfo dirInfo, PackOption packOption, string markRootName, ref List <AssetBundleBuild> builds)
        {
            FileInfo[]      files = null;
            DirectoryInfo[] subDirectory;
            switch (packOption)
            {
            case PackOption.AllFiles:
                files = dirInfo.GetFiles("*", SearchOption.AllDirectories);            // 取出所有文件
                break;

            case PackOption.TopDirectiony:
                files        = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);   // 取出第一层文件
                subDirectory = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);
                foreach (var item in subDirectory)
                {
                    MarkDirectory(item, PackOption.AllFiles, markRootName, ref builds);
                }
                break;

            case PackOption.AllDirectiony:
                files        = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);   // 取出第一层文件
                subDirectory = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly);
                foreach (var item in subDirectory)
                {
                    MarkDirectory(item, PackOption.AllDirectiony, markRootName, ref builds);
                }
                break;

            case PackOption.TopFileOnly:
                files = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);            // 取出所有文件
                break;
            }

            // 添加AssetBundleBuild
            List <string> assetNames = new List <string>();

            int    total  = files.Length;
            string abName = dirInfo.FullName.Substring(dirInfo.FullName.IndexOf(markRootName, StringComparison.Ordinal));

            for (int i = 0; i < total; i++)
            {
                var fileInfo = files[i];

                if (fileInfo.Name.EndsWith(".meta"))
                {
                    continue;
                }

                EditorUtility.DisplayProgressBar(dirInfo.Name, $"正在标记资源{fileInfo.Name}...", (float)i / total);

                string filePath = fileInfo.FullName.Substring(fileInfo.FullName.IndexOf("Assets", StringComparison.Ordinal));       // 获取 "Assets"目录起的 文件名, 可不用转 "\\"

                assetNames.Add(filePath);
            }

            if (assetNames.Count > 0)
            {
                builds.Add(new AssetBundleBuild()
                {
                    assetBundleName    = abName,
                    assetBundleVariant = "ab",
                    assetNames         = assetNames.ToArray()
                });
            }

            EditorUtility.ClearProgressBar();
        }
 public DefaultActionNameResolveService(PackOption packOption, IPackageProviderService packageProviderService)
 {
     this.packOption             = packOption;
     this.packageProviderService = packageProviderService;
 }
 public DefaultDownloadService(PackOption packOption, ILogger <DefaultDownloadService> logger, IHttpClientFactory httpClientFactory)
 {
     this.packOption        = packOption;
     this.logger            = logger;
     this.httpClientFactory = httpClientFactory;
 }