public static void Export() { try { EditorUtility.DisplayProgressBar("Export " + Helpers.currentPackageName, "Exporting...", 0f); var referencedPackages = PackageManager.GetInstalledPackages(m_excludedPackages); var codePackage = new CodePackage { name = Helpers.currentPackageName, guid = System.Guid.NewGuid().ToString(), references = System.Array.ConvertAll(referencedPackages, o => o.name), }; var manifestPath = Helpers.CombinePath(Helpers.currentPackageDirectoryInProject, Helpers.currentPackageName + ".json"); File.WriteAllText(manifestPath, JsonUtility.ToJson(codePackage, prettyPrint: true)); AssetDatabase.ImportAsset(manifestPath); var packagePath = Helpers.CombinePath(Helpers.currentPackageDirectoryInProject, Helpers.currentPackageName + ".unitypackage"); AssetDatabase.DeleteAsset(packagePath); AssetDatabase.ExportPackage(Helpers.currentPackageDirectoryInProject, packagePath, ExportPackageOptions.Recurse); AssetDatabase.ImportAsset(packagePath); } finally { EditorUtility.ClearProgressBar(); } }
private void CollectPackageDeps(List <string> list, CodePackage package) { if (PackageManager.actualInstalledPackages.Any(p => p.name == package.name)) { return; } foreach (var reference in package.references) { var refPackage = PackageManager.allPackages.SingleOrDefault(p => p.name == reference); if (refPackage == null) { Debug.LogErrorFormat("Failed to resolve {0}", reference); } else { CollectPackageDeps(list, refPackage); } } if (!list.Contains(package.name)) { list.Add(package.name); } }
private void PrepareImportPackage(CodePackage package) { var list = new List <string>(); CollectPackageDeps(list, package); if (list.Count == 1) { EditorApplication.delayCall += () => PackageManager.ImportPackage(list[0]); } else { m_packageNamesToImport = list.ToArray(); } }