AddRequest
Represents an asynchronous request to add a package to the project.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Class
- Namespace: UnityEditor.PackageManager.Requests
- Assembly: UnityEditor.CoreModule
- Inherits from: Request<PackageInfo>
- Implements: ISerializationCallbackReceiver
public sealed class AddRequest : Request<PackageInfo>, ISerializationCallbackReceiver
Remarks
The PackageManager Client class returns an AddRequest instance when you call the Client.Add method to add a package to your project. Use this object to determine when the request is complete and to access the result.
Once the request comsplete, you can retrieve the PackageInfo instance from the Result property.
using UnityEngine;using UnityEditor.PackageManager;using UnityEditor.PackageManager.Requests;[ExecuteInEditMode]public class PackageManagerAddExample : MonoBehaviour{ AddRequest m_AddRequest; void Start() { Debug.Log("Client.Add example..."); m_AddRequest = Client.Add("com.unity.textmeshpro"); } void Update() { if (m_AddRequest != null && m_AddRequest.IsCompleted) { if (m_AddRequest.Status == StatusCode.Success) { var package = m_AddRequest.Result; Debug.Log($"Added package: {package.name}" + $"\nVersion: {package.version}" + $"\nDisplay name: {package.displayName}"); } else { Debug.LogError($"Add failed: {m_AddRequest.Error.message}"); } m_AddRequest = null; } }}
Related information