class in UnityEditor.PackageManager.Requests
/
Inherits from:PackageManager.Requests.Request_1
Represents an asynchronous request to add a package to the project.
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
Property | Description |
---|---|
Error | The error returned by the request, if any. |
IsCompleted | Whether the request is complete. |
Status | The request status. |
Result | A property that provides access to the result of a completed Package Manager request operation. |