diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..ac325e8 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9f4e1c2642830f34d8b704386ba6e3af +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/BuildHelper.cs b/Editor/BuildHelper.cs new file mode 100644 index 0000000..82af466 --- /dev/null +++ b/Editor/BuildHelper.cs @@ -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 xmlPathList = new List(); + 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); + } + } +} \ No newline at end of file diff --git a/Editor/BuildHelper.cs.meta b/Editor/BuildHelper.cs.meta new file mode 100644 index 0000000..63c95d3 --- /dev/null +++ b/Editor/BuildHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c12770bea2254cc41b88f94667a1ae57 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Unity.CustomPackage.LinkMerge.asmdef b/Editor/Unity.CustomPackage.LinkMerge.asmdef new file mode 100644 index 0000000..a0ee6c2 --- /dev/null +++ b/Editor/Unity.CustomPackage.LinkMerge.asmdef @@ -0,0 +1,15 @@ +{ + "name": "Unity.CustomPackage.LinkMerge", + "references": [], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/Unity.CustomPackage.LinkMerge.asmdef.meta b/Editor/Unity.CustomPackage.LinkMerge.asmdef.meta new file mode 100644 index 0000000..dd237d6 --- /dev/null +++ b/Editor/Unity.CustomPackage.LinkMerge.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1e7f100b027e4184dae29d96f09e1440 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md deleted file mode 100644 index b86a0aa..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -Unity.CustomPackage.LinkMerge diff --git a/package.json b/package.json new file mode 100644 index 0000000..4df3595 --- /dev/null +++ b/package.json @@ -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()" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..eba0a6c --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 411775e880ef3704d833ee1d2fc9d4d5 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: