Game/Library/PackageCache/com.unity.package-manager-ui@2.0.13/Editor/Sources/Services/Upm/UpmAddOperation.cs
2021-01-16 18:29:12 +01:00

35 lines
1.0 KiB
C#

using System;
using UnityEditor.PackageManager.Requests;
using System.Linq;
namespace UnityEditor.PackageManager.UI
{
internal class UpmAddOperation : UpmBaseOperation, IAddOperation
{
public PackageInfo PackageInfo { get; protected set; }
public event Action<PackageInfo> OnOperationSuccess = delegate { };
public void AddPackageAsync(PackageInfo packageInfo, Action<PackageInfo> doneCallbackAction = null, Action<Error> errorCallbackAction = null)
{
PackageInfo = packageInfo;
OnOperationError += errorCallbackAction;
OnOperationSuccess += doneCallbackAction;
Start();
}
protected override Request CreateRequest()
{
return Client.Add(PackageInfo.PackageId);
}
protected override void ProcessData()
{
var request = CurrentRequest as AddRequest;
var package = FromUpmPackageInfo(request.Result).First();
OnOperationSuccess(package);
}
}
}