I wanted to import multiple asset packages at the same time.
Is this possible? If so then how?
I wanted to import multiple asset packages at the same time.
Is this possible? If so then how?
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*;*
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*;*
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.”);
}
}
}
}
No, there is currently no way to import multiple asset packages at once. You have to import them one by one.
Can we do it now?
Sorry for necroposting, I think IMD’s script is incredibly useful but got destroyed by the transition to Discussions and fixing it is quite a hassle, so here’s his complete solution in a single Cnt+C\Cnt+V
Same usage (put it into any Editor folder and “Tools\Unity Packages\Import Folder”)
using System.IO;
using UnityEditor;
using UnityEngine;
using Application = UnityEngine.Application;
/// <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
{
private static int successCount = 0;
[MenuItem("Tools/Unity Packages/Import Folder", false, 7)]
public static void ImportPackagesFromFolder()
{
var pPath = "";
successCount = 0;
pPath = EditorUtility.OpenFolderPanel("Select Package Path", Application.dataPath, "");
if (string.IsNullOrEmpty(pPath)) return;
var files = Directory.GetFiles(pPath, "*.unitypackage");
if (files.Length <= 0) return;
AssetDatabase.importPackageCompleted += PackageImportSuccess;
AssetDatabase.importPackageFailed += PackageImportFail;
foreach (var packagePath in files)
{
AssetDatabase.ImportPackage(packagePath, false);
}
AssetDatabase.importPackageCompleted -= PackageImportSuccess;
AssetDatabase.importPackageFailed -= PackageImportFail;
Debug.Log($"Import complete. {successCount} of {files.Length} packages successfully imported.");
}
private static void PackageImportSuccess(string packageName)
{
successCount++;
Debug.Log($"Completed import of package {packageName}");
}
private 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()
{
var pPath = "";
successCount = 0;
pPath = EditorUtility.OpenFolderPanel("Select Package Export Path", Application.dataPath, "");
if (string.IsNullOrEmpty(pPath)) return;
var selected = Selection.gameObjects;
if (selected != null && selected.Length > 0)
{
foreach (var transToPackage in selected)
{
var assetPath = AssetDatabase.GetAssetPath(transToPackage.GetInstanceID());
if (string.IsNullOrEmpty(assetPath)) continue;
var exportPath = pPath + "/" + transToPackage.name + ".unitypackage";
Debug.Log(string.Format($"Exporting {assetPath} to {exportPath}", assetPath, exportPath));
AssetDatabase.ExportPackage(assetPath, exportPath, ExportPackageOptions.IncludeDependencies);
successCount++;
}
Debug.Log(successCount == 0
? "No objects were selected in the project view."
: $"Export complete. {successCount} of {selected.Length} {selected} objects successfully exported.");
}
else
{
Debug.Log("Nothing selected to export.");
}
}
}
Thank you very much!
– Ruwaid4Thanks a bunch for your super script, buddy! Totally what i've been looking for.
– wmadwandThank you!
– Alex_FHi, I've got this when trying to import a folder: "Import complete. 0 of 18 packages successfully imported." Do you know what's wrong?
– protossguyIf you want the importer to recursively search folders for *.unitypackages, then change the call to
– TheUbMunsterDirectory.GetFiles(pPath, "*.unitypackage");on line 23 toDirectory.GetFiles(pPath, "*.unitypackage", SearchOption.AllDirectories);