LanguageEnglish
  • C#

Request

class in UnityEditor.PackageManager.Requests


Implements interfaces:ISerializationCallbackReceiver

Switch to Manual

Description

Base class for all Package Manager asynchronous operations. Use this class to track the status and results of package operations, such as adding, removing, or updating packages.

  • All Client (such as Client.Add, Client.Remove, and Client.List) return an object derived from the Request class.
  • Check the IsCompleted property to know when the operation is done.
  • Always check the Status property of the Request for a StatusCode of Success before accessing results to make sure the operation was successful.
using UnityEngine;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;

[ExecuteInEditMode] public class RequestExample : MonoBehaviour { ListRequest m_Request; void Start() { Debug.Log("Requesting packages list..."); m_Request = Client.List(); }

void Update() { if (m_Request != null && m_Request.IsCompleted) { if (m_Request.Status == StatusCode.Success) { foreach (var package in m_Request.Result) { Debug.Log($"Package: {package.name} ({package.version})"); } } else { Debug.Log($"Package list request failed: {m_Request.Error}"); } m_Request = null; } } }

Related information

Properties

ErrorThe error returned by the request, if any.
IsCompletedWhether the request is complete.
StatusThe request status.

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