// ReSharper disable once UnusedMember.Local
            // ReSharper disable once RedundantAssignment
            private static bool Prefix(ref IEnumerable <ExportPackageItem> __result, ICollection <string> guids, bool includeDependencies)
            {
                // check if this is an attempt to export from Packages, otherwise use original method
                var someGuidsAreInsidePackages = guids
                                                 .Select(AssetDatabase.GUIDToAssetPath)
                                                 .Any(x => !string.IsNullOrEmpty(x) && x.StartsWith("Packages/", StringComparison.OrdinalIgnoreCase));

                if (!someGuidsAreInsidePackages)
                {
                    return(true);
                }

                string[] resultingGuids = new string[0];
                foreach (var guid in guids)
                {
                    resultingGuids = AssetDatabase.CollectAllChildren(guid, resultingGuids);
                }

                // if (includeDependencies)
                //     Helpers.Log("You're exporting a package. If your package has dependencies and you want to export them, they need to be manually selected.");

                var rootsAndChildGuids = resultingGuids.Union(guids).Distinct().ToList();

                if (includeDependencies)
                {
                    rootsAndChildGuids = rootsAndChildGuids.Union(AssetDatabase
                                                                  .GetDependencies(rootsAndChildGuids.Select(AssetDatabase.GUIDToAssetPath).ToArray(), true)
                                                                  .Select(AssetDatabase.AssetPathToGUID))
                                         .Distinct().ToList();
                }

                __result = rootsAndChildGuids
                           .Select(x => new ExportPackageItem()
                {
                    assetPath     = AssetDatabase.GUIDToAssetPath(x),
                    enabledStatus = (int)PackageExportTreeView.EnabledState.All,
                    guid          = x,
                    isFolder      = AssetDatabase.IsValidFolder(AssetDatabase.GUIDToAssetPath(x))
                })
                           .Where(x => !x.isFolder); // ignore folders, otherwise these seem to end up being separate assets and ignored on import

                // this just doesn't warn, but still does not include the right items
                // __result = PackageUtility.BuildExportPackageItemsList(resultingGuids, false);
                return(false);
            }
            internal static void AddChildrenToResults(List <string> results, string assetPath)
            {
                if (File.Exists(assetPath))
                {
                    results.Add(AssetDatabase.AssetPathToGUID(assetPath));
                    return;
                }

                string[] collection = new string[0];
                var      children   = AssetDatabase.CollectAllChildren(AssetDatabase.AssetPathToGUID(assetPath), collection);

                if (!children.Any())
                {
                    throw new NullReferenceException(Helpers.LogPrefix + "Seems you're trying to export something that's not in your AssetDatabase: " + assetPath + " - this can't be exported as .unitypackage.");
                }

                results.AddRange(children);
            }
Exemple #3
0
        public static string ExportUnitypackage(IEnumerable <string> rootGuids, string fileName)
        {
            if (!fileName.EndsWith(".unitypackage", StringComparison.OrdinalIgnoreCase))
            {
                Debug.LogError("File name must end with .unitypackage");
                return(null);
            }

            var collection = new string[0];

            foreach (var guid in rootGuids)
            {
                collection = AssetDatabase.CollectAllChildren(guid, collection);
            }

            PackageUtility.ExportPackage(collection, fileName);
            // TODO return absolute export path
            return(Application.dataPath + "/" + fileName);
        }