-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev'
- Loading branch information
Showing
8 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using UnityEditor.Build; | ||
using UnityEditor.Build.Reporting; | ||
using UnityEditor.PackageManager; | ||
using UnityEngine; | ||
|
||
public class PackagesLinkXmlExtractor : IPreprocessBuildWithReport, IPostprocessBuildWithReport | ||
{ | ||
public string TemporaryFolder | ||
{ | ||
get { return $"{Application.dataPath}/Temporary-Build/";} | ||
} | ||
|
||
public string TemporaryFolderMeta | ||
{ | ||
get { return $"{Application.dataPath}/Temporary-Build.meta";} | ||
} | ||
|
||
public string LinkFilePath | ||
{ | ||
get { return $"{TemporaryFolder}link.xml"; } | ||
} | ||
|
||
public int callbackOrder { get { return 0; } } | ||
|
||
public void OnPreprocessBuild(BuildReport report) | ||
{ | ||
if (!File.Exists(LinkFilePath)) | ||
CreateMergedLinkFromPackages(); | ||
} | ||
|
||
public void OnPostprocessBuild(BuildReport report) | ||
{ | ||
if(File.Exists(LinkFilePath)) | ||
File.Delete(LinkFilePath); | ||
if (Directory.Exists(TemporaryFolder)) | ||
{ | ||
if (!Directory.EnumerateFiles(TemporaryFolder, "*").Any()) | ||
Directory.Delete(TemporaryFolder); | ||
Directory.Delete(TemporaryFolder, true); | ||
} | ||
if (File.Exists(TemporaryFolderMeta)) | ||
File.Delete(TemporaryFolderMeta); | ||
} | ||
|
||
private void CreateMergedLinkFromPackages() | ||
{ | ||
var request = Client.List(); | ||
do { } while (!request.IsCompleted); | ||
if (request.Status == StatusCode.Success) | ||
{ | ||
List<string> xmlPathList = new List<string>(); | ||
foreach (var package in request.Result) | ||
{ | ||
var path = package.resolvedPath; | ||
xmlPathList.AddRange(Directory.EnumerateFiles(path, "linkmerge.xml", SearchOption.AllDirectories).ToList()); | ||
} | ||
|
||
if (xmlPathList.Count <= 0) | ||
return; | ||
|
||
var xmlList = xmlPathList.Select(XDocument.Load).ToArray(); | ||
|
||
var combinedXml = xmlList.First(); | ||
foreach (var xDocument in xmlList.Where(xml => xml != combinedXml)) | ||
{ | ||
combinedXml.Root.Add(xDocument.Root.Elements()); | ||
} | ||
|
||
if (!Directory.Exists(TemporaryFolder)) | ||
Directory.CreateDirectory(TemporaryFolder); | ||
combinedXml.Save(LinkFilePath); | ||
} | ||
else if (request.Status >= StatusCode.Failure) | ||
{ | ||
Debug.LogError(request.Error.message); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "Unity.CustomPackage.LinkMerge", | ||
"references": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Unity.CustomPackage.LinkMerge", | ||
"version": "1.0.0", | ||
"displayName": "Custom Package Link Merger", | ||
"description": "A Utility to pull in flagged link.xml files from custom packages.", | ||
"unity": "2018.4", | ||
"dependencies": {}, | ||
"keywords": [ | ||
"Packages", | ||
"Link" | ||
"Merge" | ||
"LinkMerge" | ||
], | ||
"author": { | ||
"name": "Reality.Stop()" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.