LanguageEnglish
  • C#

PackageCollection

class in UnityEditor.PackageManager

Switch to Manual

Description

A collection class that represents all packages in a Unity project, providing enumeration and error handling capabilities for package management operations.

Implements IEnumerable <PackageInfo> interface.

The PackageCollection class serves as a container for PackageInfo objects representing all packages in a Unity project. PackageCollection information is typically obtained as the result of a Client.List() operation. Use the PackageCollection to iterate through packages and check for collection-level errors that might occur during package resolution.

using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;

public class PackageExample { void ListAllPackages() { ListRequest request = Client.List(); while(!request.IsCompleted) {}

if (request.Status == StatusCode.Success) { PackageCollection packages = request.Result; // Check for collection-level errors if (packages.error != null) { Debug.LogError($"Collection error: {packages.error}"); return; }

// Enumerate through packages foreach (PackageInfo package in packages) { Debug.Log($"Found package: {package.name} @ {package.version}"); } } } }

Remarks

  • After the PackageCollection is created, it's immutable.
  • Package enumeration order isn't guaranteed.
  • Collection-level errors indicate issues with the overall package resolution, not with individual packages.
  • The collection can contain direct dependencies and transitive dependencies.
  • Use in conjunction with Client.List() to get an up-to-date view of project packages.

Related information

Properties

errorThe error associated with the package collection.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961