Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Sample.OnBeforeImportFinish

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

Raised after files are imported into the project, but before the Asset Database refreshes.

Subscribe to this event to react to imported samples — for example, by importing dependent samples or packages — before the Asset Database refresh picks up the new files. The event is invoked with a list of SampleImportEventData describing each imported sample. The event fires once per call to Sample.Import, regardless of how many samples were imported in that call.

Subscribers are responsible for unsubscribing when they are no longer needed.

using System.Collections.Generic;
using UnityEditor;
using UnityEditor.PackageManager.UI;
using UnityEngine;

public static class SampleImportLogger { [InitializeOnLoadMethod] static void Subscribe() { Sample.OnBeforeImportFinish += OnSamplesImported; }

static void OnSamplesImported(IReadOnlyList<SampleImportEventData> events) { foreach (var data in events) Debug.Log($"Imported {data.sampleDisplayName} from {data.packageTechnicalName} to {data.newImportPath}"); } }

Additional resources: SampleImportEventData, Sample.Import