コード例 #1
0
ファイル: CLI.cs プロジェクト: mika-f/Unity-VariationPackager
        private static string CreateUnityPackage(IPackage meta, IPackageVariation variation)
        {
            var matcher = new Matcher();

            matcher.AddIncludePatterns(variation.UnityPackage.Includes);
            matcher.AddExclude("**/*.meta");
            if (variation.UnityPackage.Excludes != null)
            {
                matcher.AddExcludePatterns(variation.UnityPackage.Excludes);
            }

            var rootDirectory = new DirectoryInfoWrapper(new DirectoryInfo(Application.dataPath));
            var assets        = matcher.Execute(rootDirectory).Files.Select(w => $"Assets/{w.Path}");

            var destDirectory = Path.Combine(Application.dataPath, meta.Describe.Output);

            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            var destName  = string.IsNullOrWhiteSpace(variation.UnityPackage.Name) ? $"{meta.Name}.unitypackage" : $"{variation.UnityPackage.Name}.unitypackage";
            var publishTo = Path.Combine(destDirectory, destName);

            if (File.Exists(publishTo))
            {
                File.Delete(publishTo);
            }

            AssetDatabase.ExportPackage(assets.ToArray(), publishTo, ExportPackageOptions.Default);

            return(publishTo);
        }
コード例 #2
0
ファイル: CLI.cs プロジェクト: mika-f/Unity-VariationPackager
        private static void CreateZipPackage(IPackage meta, IPackageVariation variation, string publishedTo)
        {
            var matcher = new Matcher();

            if (variation.Archive?.Includes != null)
            {
                matcher.AddIncludePatterns(variation.Archive.Includes);
            }
            if (variation.Archive?.Excludes != null)
            {
                matcher.AddExcludePatterns(variation.Archive.Excludes);
            }

            var rootDirectory = new DirectoryInfoWrapper(new DirectoryInfo(Application.dataPath));
            var assets        = matcher.Execute(rootDirectory).Files.Select(w => $"Assets/{w.Path}");

            var sb = new List <string>();

            sb.Add(string.IsNullOrWhiteSpace(variation.Archive?.Name) ? meta.Name : variation.Archive.Name);
            if (!string.IsNullOrWhiteSpace(variation.Name))
            {
                sb.Add(variation.Name);
            }
            sb.Add(meta.Version);
            var archiveName   = string.Join("-", sb);
            var destDirectory = Path.Combine(Application.dataPath, meta.Describe.Output, archiveName);

            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            foreach (var asset in assets)
            {
                var baseDir = string.IsNullOrWhiteSpace(variation.Archive?.BaseDir) ? "" : $"Assets/{variation.Archive.BaseDir}";
                var destTo  = $"{destDirectory}/{(string.IsNullOrWhiteSpace(baseDir) ? asset : asset.Replace(baseDir, ""))}";
                if (!Directory.Exists(Path.GetDirectoryName(destTo)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destTo) ?? string.Empty);
                }
                File.Copy(asset, destTo, true);
            }

            File.Copy(publishedTo, $"{destDirectory}/{Path.GetFileName(publishedTo)}", true);

            ZipFile.CreateFromDirectory(destDirectory, $"{destDirectory}.zip", CompressionLevel.Optimal, true);

            Directory.Delete(destDirectory, true);
        }
コード例 #3
0
ファイル: CLI.cs プロジェクト: mika-f/Unity-VariationPackager
        private static void CreatePackage(IPackage meta, IPackageVariation variation, bool isKeepUnityPackage)
        {
            var dest = CreateUnityPackage(meta, variation);

            if (variation.Archive == null)
            {
                return;
            }

            CreateZipPackage(meta, variation, dest);

            if (isKeepUnityPackage)
            {
                var basename  = Path.GetDirectoryName(dest);
                var filename  = Path.GetFileNameWithoutExtension(dest);
                var extension = Path.GetExtension(dest);
                File.Move(dest, $"{basename}/{filename}-{meta.Version}{extension}");
            }
            else
            {
                File.Delete(dest);
            }
        }