Skip to content

Call from other packages

Last updated

You can open the BLM CatalogWindow from your own editor extension, let the user pick product files, and import them. The API lives in the com.amari_noa.blm_integration_core.editor namespace. Reference com.amari-noa.blm-integration-core.editor from your assembly definition to use it. If you also use the UnityPackage Pipeline Core and Unity Editor Localization Core APIs, as the sample below does, add com.amari-noa.unitypackage-pipeline-core.editor and com.amari-noa.unity-editor-localization-core.editor to the references as well.

  1. Create a BlmPickerContext and open the window with BlmCatalogWindowGateway.Shared.Open.
  2. When the user picks files and clicks Import, the window closes and the import request (BlmImportBatchRequest) is passed to the BatchRequestConfirmed event.
  3. Pass the request to BlmImportProcessor.Shared.Execute to run the import.
  4. When the import finishes, the result (BlmImportBatchResultContext) is passed to the ImportBatchCompleted event.

A window opened from another package does not import anything by itself when Import is clicked. The caller decides whether and when to run the import.

using System.Collections.Generic;
using com.amari_noa.blm_integration_core.editor;
using com.amari_noa.unity_editor_localization_core.editor;
using com.amari_noa.unitypackage_pipeline_core.editor;
internal static class MyBlmPicker
{
private static BlmPickerContext _context;
public static void Open()
{
_context = new BlmPickerContext
{
PreferredDisplayExtensions = new List<string> { ".unitypackage" },
UnityPackageImportPipelineService = AmariUnityPackageImportPipeline.Service,
DestinationAssetPathUpdater = BlmImportProcessor.Shared,
EditorLocalizationService = EditorLocalization.Service,
HostDisplayName = "My Tool"
};
var gateway = BlmCatalogWindowGateway.Shared;
gateway.BatchRequestConfirmed += OnConfirmed;
gateway.WindowClosed += OnClosed;
gateway.Open(_context);
}
private static void OnConfirmed(BlmImportBatchRequest request)
{
BlmImportProcessor.Shared.ImportBatchCompleted += OnCompleted;
BlmImportProcessor.Shared.Execute(request, _context);
}
private static void OnCompleted(BlmImportBatchResultContext result)
{
BlmImportProcessor.Shared.ImportBatchCompleted -= OnCompleted;
// Check the outcome with result.SucceededItems / result.FailedItems
}
private static void OnClosed()
{
BlmCatalogWindowGateway.Shared.BatchRequestConfirmed -= OnConfirmed;
BlmCatalogWindowGateway.Shared.WindowClosed -= OnClosed;
}
}

The entry point for opening the window. Use BlmCatalogWindowGateway.Shared (IBlmCatalogWindowGateway).

Member Description
Open(BlmPickerContext context) Opens the window. If a required setting is missing, it logs an error to the Console and does not open the window
BatchRequestConfirmed Event that passes the import request (BlmImportBatchRequest) when Import is clicked
WindowClosed Event raised when the window closes
HasLostContext Whether the open window lost the caller’s settings in a domain reload. If true, the caller should open the window again

The settings used to open the window.

Member Description
UnityPackageImportPipelineService Required. The service used to import UnityPackages, usually AmariUnityPackageImportPipeline.Service
DestinationAssetPathUpdater Required. The target that receives imported asset paths, usually BlmImportProcessor.Shared
EditorLocalizationService Required. The service used for the display language, usually EditorLocalization.Service
PreferredDisplayExtensions Extensions grouped at the top of the file list (for example, .unitypackage)
HostDisplayName The caller’s name. When set, Opened by {name} appears at the top of the window
HostContext Any object the caller wants to keep with the call
InvocationContext The kind of call. Defaults to BlmInvocationContext.Integration; leave it as is
LocalizationSourceId The localization source ID used for window text. Keep the default

Runs imports. Use BlmImportProcessor.Shared.

Member Description
Execute(BlmImportBatchRequest request, BlmPickerContext context) Runs an import request. UnityPackages go through Unity’s standard package import dialog, and other files are copied under Assets/BLM/<shop name>/<product name>/
ImportBatchCompleted Event that passes the result (BlmImportBatchResultContext) when the import finishes
ImportQueueProgressed Event that passes the progress (BlmImportQueueProgressContext) when the import starts and each time a file is processed

An import request. Each element of Items (BlmImportRequestItem) is one file.

Member Description
BatchId The ID of the import request
Items The files to import (List<BlmImportRequestItem>)
BlmImportRequestItem.ProductId The item’s ID
BlmImportRequestItem.ProductName / ShopName The product name and shop name
BlmImportRequestItem.SourcePath The full path of the source file
BlmImportRequestItem.DestinationAssetPaths Filled with the paths of the imported assets after the import

The result of an import.

Member Description
BatchId The ID of the matching import request
SucceededItems / FailedItems The files that succeeded and the files that failed. Files skipped because a file with the same name exists count as succeeded. Processing stops at the first failure or cancellation, so the remaining files are in neither list
ImportStatus The overall result (AmariUnityPackagePipelineOperationStatus from UnityPackage Pipeline Core)
CancellationReason / FailureReason The reason for cancellation or failure
ErrorMessage The message when the import fails

For related APIs, see UnityPackage Pipeline Core and Unity Editor Localization Core.