Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update export UnityPackage menu #441

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 77 additions & 57 deletions Assets/VRM/UniVRM/DevOnly/Editor/VRMExportUnityPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static string GetProjectRoot()
static string System(string workingDir, string fileName, string args)
{
// Start the child process.
using(var p = new System.Diagnostics.Process()) {
using (var p = new System.Diagnostics.Process())
{
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
Expand All @@ -58,7 +59,8 @@ static string System(string workingDir, string fileName, string args)
string err = p.StandardError.ReadToEnd();
p.WaitForExit();

if (p.ExitCode != 0 || string.IsNullOrEmpty(output)) {
if (p.ExitCode != 0 || string.IsNullOrEmpty(output))
{
throw new Exception(err);
}

Expand Down Expand Up @@ -98,7 +100,8 @@ static IEnumerable<string> GlobFiles(string path)
var fileName = Path.GetFileName(path);

// Domain specific filter logic
if (ignoredFilesForGlob.Any(f => fileName.EndsWithAndMeta(f))) {
if (ignoredFilesForGlob.Any(f => fileName.EndsWithAndMeta(f)))
{
yield break;
}

Expand Down Expand Up @@ -145,80 +148,97 @@ public static void CreateUnityPackage()
CreateUnityPackages(Path.GetFullPath(Path.Combine(Application.dataPath, "..")));
}

public static void CreateUnityPackages(string outputDir)
public class GlobList
{
// UniVRM and sub packages
{
var basePath = "Assets/VRM";
var packages = new Dictionary<string, string[]> () {
{"UniVRM", null}, // All
{"UniJSON-standalone", new string[] {"UniJSON"}},
{"UniHumanoid-standalone", new string[] {"UniHumanoid"}},
{"UniGLTF-standalone", new string[] {"UniGLTF", "UniHumanoid", "UniJSON", "UniUnlit", "DepthFirstScheduler"}},
};

var fileNames = GlobFiles(basePath).ToArray();
foreach(var packagePair in packages) {
CreateUnityPackage(outputDir, packagePair.Key, packagePair.Value, basePath, fileNames);
}
}
public readonly string[] Files;

// UniVRM Samples
public GlobList(string root, params string[] filters)
{
var fileNames = GlobFiles("Assets/VRM.Samples")
.Concat(GlobFiles("Assets/StreamingAssets/VRM.Samples"))
.ToArray();
CreateUnityPackage(outputDir, "UniVRM-samples", null /*All*/, "", fileNames);
var files = GlobFiles(root);
if (filters.Any())
{
var filtersWithRoot = filters.Select(x => $"{root}/{x}").ToArray();
Files = files.Where(x => filtersWithRoot.Any(y => x.StartsWith(y))).ToArray();
}
else
{
Files = files.ToArray();
}
}
}

public static void CreateUnityPackage(
string outputDir,
string name,
string[] containsPath,
string basePath,
string[] fileNames
)
{
CreateUnityPackageStandalone(outputDir, name, containsPath, basePath, fileNames, null, null);
}

public static void CreateUnityPackageStandalone(
string outputDir,
string name,
string[] containsPath,
string basePath,
IEnumerable<string> fileNames,
string[] includeSuffix,
string[] excludeSuffix
)
public class PackageInfo
{
public readonly string Name;
public GlobList[] List;

if (includeSuffix != null)
public PackageInfo(string name)
{
fileNames = fileNames
.Where(fileName => includeSuffix.Any(suffix => fileName.EndsWith(suffix)));
Name = name;
}
}

if (excludeSuffix != null)
public static void CreateUnityPackages(string outputDir)
{
// UniVRM and sub packages
{
fileNames = fileNames
.Where(fileName => !excludeSuffix.Any(suffix => fileName.EndsWith(suffix)));
var packages = new[]{
new PackageInfo("UniVRM")
{
List = new []{
new GlobList("Assets/VRM"),
new GlobList("Assets/VRMShaders"),
}
},
// new PackageInfo("UniJSON-standalone")
// {
// List = new [] {
// new GlobList("Assets/VRM", "UniJSON"),
// }
// },
// new PackageInfo("UniHumanoid-standalone")
// {
// List = new []{
// new GlobList("Assets/VRM", "UniHumanoid"),
// }
// },
// new PackageInfo("UniGLTF-standalone")
// {
// List = new []{
// new GlobList("Assets/VRM", "UniGLTF", "UniHumanoid", "UniJSON", "Assets/VRM/DepthFirstScheduler"),
// new GlobList("Assets/VRMShaders", "UniUnlit"),
// }
// }
};
foreach (var package in packages)
{
CreateUnityPackage(outputDir, package);
}
}

if (containsPath != null)
// UniVRM Samples
{
var containsPathWithBase = containsPath.Select(c => string.Format("{0}/{1}", basePath, c)).ToArray();
fileNames = fileNames
.Where(fileName => containsPathWithBase.Any(c => fileName.StartsWith(c)));
CreateUnityPackage(outputDir, new PackageInfo("UniVRM-samples")
{
List = new[]{
new GlobList("Assets/VRM.Samples"),
new GlobList("Assets/StreamingAssets/VRM.Samples"),
}
});
}
}

var targetFileNames = fileNames.ToArray();
public static void CreateUnityPackage(
string outputDir,
PackageInfo package
)
{
var targetFileNames = package.List.SelectMany(x => x.Files).ToArray();

Debug.LogFormat("Package '{0}' will include {1} files...", name, targetFileNames.Count());
Debug.LogFormat("Package '{0}' will include {1} files...", package.Name, targetFileNames.Count());
Debug.LogFormat("{0}", string.Join("", targetFileNames.Select((x, i) => string.Format("[{0:##0}] {1}\n", i, x)).ToArray()));

var path = MakePackagePathName(outputDir, name);
var path = MakePackagePathName(outputDir, package.Name);
AssetDatabase.ExportPackage(targetFileNames, path, ExportPackageOptions.Default);
}

Expand Down