private static void AdvisePackages(Lifetime lifetime, FrontendBackendModel frontendBackendModel, PackageManager packageManager) { // Called in the Guarded reentrancy context packageManager.Packages.AddRemove.Advise(lifetime, args => { switch (args.Action) { case AddRemove.Add: var packageData = args.Value.Value; var packageDetails = packageData.PackageDetails; var source = ToProtocolPackageSource(packageData.Source); var dependencies = (from d in packageDetails.Dependencies select new UnityPackageDependency(d.Key, d.Value)).ToArray(); var gitDetails = packageData.GitDetails != null ? new UnityGitDetails(packageData.GitDetails.Url, packageData.GitDetails.Hash, packageData.GitDetails.Revision) : null; var package = new UnityPackage(args.Value.Key, packageDetails.Version, packageData.PackageFolder?.FullPath, source, packageDetails.DisplayName, packageDetails.Description, dependencies, packageData.TarballLocation?.FullPath, gitDetails); frontendBackendModel.Packages.Add(args.Value.Key, package); break; case AddRemove.Remove: frontendBackendModel.Packages.Remove(args.Value.Key); break; } }); }
public override TemporaryDirectory DownloadPackage(Upset package) { TemporaryDirectory td = new TemporaryDirectory(); string sourcePath = System.IO.Path.Combine(Path, package.MetaInformation.dirName); if (Directory.Exists(sourcePath)) { Uplift.Common.FileSystemUtil.CopyDirectoryWithMeta(sourcePath, td.Path); } else if (IsUnityPackage(sourcePath)) { var unityPackage = new UnityPackage(); unityPackage.Extract(sourcePath, td.Path); } else { Debug.LogError(string.Format("Package {0} version {1} found at {2} has an unexpected format and cannot be downloaded ", package.PackageName, package.PackageVersion, sourcePath)); } return(td); }
public override TemporaryDirectory DownloadPackage(Upset package) { string sourceName = Regex.Replace(package.MetaInformation.dirName, ".Upset.xml$", ".unitypackage", RegexOptions.IgnoreCase); releases = GetPackagesReleases(); GitHubRelease release = releases.FirstOrDefault(rel => rel.assets.Any(asset => asset.name.Contains(sourceName))); if (release == null) { throw new ArgumentException(string.Format("Package {0} is not present in this repository", package.PackageName)); } GitHubAsset packageAsset = release.assets.First(asset => asset.name.Contains(sourceName)); TemporaryDirectory td = new TemporaryDirectory(); using (StreamReader sr = new StreamReader(GitHub.GetAssetStream(packageAsset, GetToken()))) { UnityPackage unityPackage = new UnityPackage(); unityPackage.Extract(sr.BaseStream, td.Path); } return(td); }
public override void Execute(Pipeline pipeline) { var unityPackageData = pipeline.Manifest.Data.OfType <UnityPackages>().ToArray(); var remappableAssets = unityPackageData .SelectMany(upd => upd.unityPackages) .SelectMany(up => up.AssetFiles) .Select(AssetDatabase.GetAssetPath) .SelectMany(path => { if (AssetDatabase.IsValidFolder(path)) { return(Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)); } else { return(Enumerable.Repeat(path, 1)); } }) .Select(path => (path, asset: AssetDatabase.LoadAssetAtPath <Object>(path))) .SelectMany(map => { var(path, asset) = map; if (asset is GameObject goAsset) { return(goAsset.GetComponentsInChildren <MonoBehaviour>() .Select(mb => (path: path, monoScript: MonoScript.FromMonoBehaviour(mb)))); } if (asset is ScriptableObject soAsset) { return(Enumerable.Repeat((path: path, monoScript: MonoScript.FromScriptableObject(soAsset)), 1)); } return(Enumerable.Empty <(string path, MonoScript monoScript)>()); }) .Select(map => { var type = map.monoScript.GetClass(); var fileId = FileIdUtil.Compute(type); var assemblyPath = type.Assembly.Location; var libraryGuid = PackageHelper.GetAssemblyHash(assemblyPath); AssetDatabase.TryGetGUIDAndLocalFileIdentifier(map.monoScript, out string scriptGuid, out long scriptId); return(Path: map.path, ScriptReference: $"{{fileID: {scriptId}, guid: {scriptGuid}, type: 3}}", AssemblyReference: $"{{fileID: {fileId}, guid: {libraryGuid}, type: 3}}"); }) .ToArray(); if (remapFileIds) { foreach (var map in remappableAssets) { var fileText = File.ReadAllText(map.Path); fileText = fileText.Replace(map.ScriptReference, map.AssemblyReference); File.WriteAllText(map.Path, fileText); } //AssetDatabase.Refresh(); } foreach (var unityPackageDatum in unityPackageData) { foreach (var outputPath in unityPackageDatum.StagingPaths.Select(path => path.Resolve(pipeline, this))) { if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } foreach (var unityPackage in unityPackageDatum.unityPackages) { UnityPackage.Export(unityPackage, outputPath); } } } if (remapFileIds) { foreach (var map in remappableAssets) { var fileText = File.ReadAllText(map.Path); fileText = fileText.Replace(map.AssemblyReference, map.ScriptReference); File.WriteAllText(map.Path, fileText); } //AssetDatabase.Refresh(); } }
public void EnsureUnpacked() { UnityPackage.EnsureUnpacked(); }