Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealityStop committed Nov 10, 2020
2 parents 8057fba + 397378d commit 846a9dc
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions Editor/BuildHelper.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions Editor/BuildHelper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Editor/Unity.CustomPackage.LinkMerge.asmdef
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
}
7 changes: 7 additions & 0 deletions Editor/Unity.CustomPackage.LinkMerge.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion README.md

This file was deleted.

17 changes: 17 additions & 0 deletions package.json
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()"
}
}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 846a9dc

Please sign in to comment.