RequestExtensions.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEditor.PackageManager.Requests; //ListRequest
  2. using UnityEditor.PackageManager; //PackageCollection
  3. using System.Collections.Generic; //IEnumerable
  4. namespace Unity.RenderStreaming.Editor {
  5. /// <summary>
  6. /// An extension class to extend the functionalities of UnityEditor.PackageManager.Requests classes
  7. /// </summary>
  8. internal static class RequestExtensions
  9. {
  10. /// <summary>
  11. /// Find a PackageInfo which has the passed parameter
  12. /// </summary>
  13. /// <param name="listRequest">list of <see cref="Request">Request</see> object</param>
  14. /// <param name="packageName">the package name</param>
  15. /// <returns>The PackageInfo if found, otherwise null</returns>
  16. public static PackageInfo FindPackage(this Request<PackageCollection> listRequest, string packageName) {
  17. IEnumerable<PackageInfo> packageInfoCollection = listRequest.Result as IEnumerable<PackageInfo>;
  18. if (null == packageInfoCollection) {
  19. return null;
  20. }
  21. var enumerator = packageInfoCollection.GetEnumerator();
  22. while (enumerator.MoveNext()) {
  23. PackageInfo curInfo = enumerator.Current;
  24. if (curInfo.name == packageName) {
  25. return curInfo;
  26. }
  27. }
  28. return null;
  29. }
  30. }
  31. } //namespace Unity.RenderStreaming.Editor