Version: Unity 6.2 Alpha (6000.2)
LanguageEnglish
  • C#

Events

class in UnityEditor.PackageManager

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

An interface for accessing the package manager events. Use these events to monitor package changes in your Unity project.

The registeringPackages event fires before any package changes occur. The registeredPackages event fires after all changes are complete. Both events provide a PackageRegistrationEventArgs parameter which contains details about the changes. Events are usually reset during domain reloads, so register your handlers using [InitializeOnLoad].

using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine;

[InitializeOnLoad] public class PackageChangeMonitor { static PackageChangeMonitor() { // Register for package change events Events.registeringPackages += OnPackagesRegistering; Events.registeredPackages += OnPackagesRegistered; }

private static void OnPackagesRegistering(PackageRegistrationEventArgs args) { // Called before packages are changed if (args.added.Count > 0) Debug.Log($"About to add {args.added.Count} packages"); if (args.removed.Count > 0) Debug.Log($"About to remove {args.removed.Count} packages"); }

private static void OnPackagesRegistered(PackageRegistrationEventArgs args) { // Called after packages have changed foreach (var package in args.added) Debug.Log($"Added package: {package.name} ({package.version})"); foreach (var package in args.removed) Debug.Log($"Removed package: {package.name}"); } }

Events

registeredPackagesEvent raised after applying changes to the registered packages list.
registeringPackagesEvent raised before applying changes to the registered packages list.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961