- Home /
Answer by ericksson · Sep 15, 2011 at 12:53 PM
No, there is currently no way to import multiple asset packages at once. You have to import them one by one.
Answer by IMD · Sep 17, 2018 at 07:53 PM
Hello, here's a nice class I've written today to both import and export multiple Unity packages via Menu > Tools from and to a chosen folder. Enjoy :)
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
/// <summary>
/// Unity package helper. Provides Menu options for automatically importing and
/// exporting multiple Unity packages.
/// Auth: Isaac Dart; 2018-09-17
/// </summary>
public class UnityPackageHelper
{
static int successCount = 0;
[MenuItem("Tools/Unity Packages/Import Folder", false, 7)]
public static void ImportPackagesFromFolder()
{
string pPath = "";
successCount = 0;
pPath = EditorUtility.OpenFolderPanel("Select Package Path", Application.dataPath, "");
if (!String.IsNullOrEmpty(pPath)) {
string[] files = Directory.GetFiles(pPath, "*.unitypackage");
if (files != null && files.Length > 0) {
AssetDatabase.importPackageCompleted += PackageImportSuccess;
AssetDatabase.importPackageFailed += PackageImportFail;
for (int i = 0; i < files.Length; i++) {
string packagePath = files[i];
AssetDatabase.ImportPackage(packagePath, false);
}
AssetDatabase.importPackageCompleted -= PackageImportSuccess;
AssetDatabase.importPackageFailed -= PackageImportFail;
Debug.Log("Import complete. " + successCount + " of " + files.Length + " packages successfully imported.");
}
}
}
static void PackageImportSuccess(string packageName)
{
successCount ++;
Debug.Log("Completed import of package '" + packageName + "'");
}
static void PackageImportFail(string packageName, string errorMessage)
{
Debug.Log("Failed to import package '" + packageName + "' with error message '"+ errorMessage + "'.");
}
[MenuItem("Tools/Unity Packages/Export To Folder", false, 7)]
public static void ExportSelectionAsPackages()
{
string pPath = "";
successCount = 0;
pPath = EditorUtility.OpenFolderPanel("Select Package Export Path", Application.dataPath, "");
if (!String.IsNullOrEmpty(pPath))
{
GameObject[] selected = Selection.gameObjects;
if (selected != null && selected.Length > 0)
{
for (int i = 0; i < selected.Length; i++)
{
GameObject transToPackage = selected[i];
string assetPath = AssetDatabase.GetAssetPath(transToPackage.GetInstanceID());
if (String.IsNullOrEmpty(assetPath)) continue;
string exportPath = pPath + "/" + transToPackage.name + ".unitypackage";
Debug.Log(String.Format("Exporting '{0}' to '{1}' ...", assetPath, exportPath));
AssetDatabase.ExportPackage(assetPath, exportPath,ExportPackageOptions.IncludeDependencies);
successCount++;
}
if (successCount == 0) {
Debug.Log("No objects were selected in the project view.");
} else {
Debug.Log("Export complete. " + successCount + " of " + selected.Length + " selected objects successfully exported.");
}
} else {
Debug.Log("Nothing selected to export.");
}
}
}
}
Thanks a bunch for your super script, buddy! Totally what i've been looking for.
Hi, I've got this when trying to import a folder: "Import complete. 0 of 18 packages successfully imported." Do you know what's wrong?
Oh my bad. It has been imported, but it in another folder. Thanks so much for the script!
If you want the importer to recursively search folders for *.unitypackages, then change the call to Directory.GetFiles(pPath, "*.unitypackage");
on line 23 to Directory.GetFiles(pPath, "*.unitypackage", SearchOption.AllDirectories);
Answer by $$anonymous$$ · Feb 19, 2018 at 09:07 AM
Can we do it now?
Still no. Why do you want to import multiple assets at the same time anyway?
Hi @$$anonymous$$; yes my above script still works. Just drop it into a new class under an Editor folder and use the new menu which appears under Tools > Unity Packages > Import Folder. Cheers.