Skip to content

Commit

Permalink
fix: support 2021.3.26 or later
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Nov 20, 2023
1 parent 9bf490f commit 563142f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
19 changes: 19 additions & 0 deletions Assets/Tests/ReflectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#else
using UnityEditor.PackageManager.UI;
#endif
#if UNITY_2023_1_OR_NEWER
using UpmPackage = UnityEditor.PackageManager.UI.Internal.Package;
#endif

namespace Coffee.UpmGitExtension
{
Expand All @@ -34,6 +37,22 @@ public void UpmPackageVersion_Tag()
);
}

[Test]
public void UpmPackage_UpdateVersions()
{
if (Application.isBatchMode) return; // Skip in batch mode.
#if UNITY_2020_1
var upmClient = UpmClient.instance;
var database = PackageDatabase.instance;
#else
var upmClient = UnityEditor.ScriptableSingleton<ServicesContainer>.instance.Resolve<UpmClient>();
var database = UnityEditor.ScriptableSingleton<ServicesContainer>.instance.Resolve<PackageDatabase>();
#endif

var package = database.GetPackage("com.coffee.softmask-for-ugui") as UpmPackage;
package.UpdateVersionsSafety(new[] { package.GetInstalledVersion() });
}

#if UNITY_2023_1_OR_NEWER
#elif UNITY_2021_2_OR_NEWER
[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
// UpmPackage.UpdateVersions is removed from Unity 2021.3.26

#if UNITY_2021_3_0 || UNITY_2021_3_1 || UNITY_2021_3_2 || UNITY_2021_3_3 || UNITY_2021_3_4 || UNITY_2021_3_5 || UNITY_2021_3_6 || UNITY_2021_3_7 || UNITY_2021_3_8 || UNITY_2021_3_9
#elif UNITY_2021_3_10 || UNITY_2021_3_11 || UNITY_2021_3_12 || UNITY_2021_3_13 || UNITY_2021_3_14 || UNITY_2021_3_15 || UNITY_2021_3_16 || UNITY_2021_3_17 || UNITY_2021_3_18 || UNITY_2021_3_19
#elif UNITY_2021_3_20 || UNITY_2021_3_21 || UNITY_2021_3_22 || UNITY_2021_3_23 || UNITY_2021_3_24 || UNITY_2021_3_25
#elif UNITY_2021_3
#define UNITY_2021_3_26_OR_NEWER
#endif

using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor.PackageManager;
#if UNITY_2021_1_OR_NEWER
Expand All @@ -24,16 +34,30 @@ public static PackageInfo GetPackageInfo(this IPackageVersion self)

internal static class UpmPackageExtensions
{
public static void UpdateVersionsSafety(this UpmPackage self, IEnumerable<UpmPackageVersion> updatedVersions)
public static UpmPackage UpdateVersionsSafety(this UpmPackage self, IEnumerable<UpmPackageVersion> versions)
{
if (self.Has("UpdateVersions", updatedVersions, 0))
#if UNITY_2023_1_OR_NEWER
var factory = UnityEditor.ScriptableSingleton<ServicesContainer>.instance.Resolve<UpmPackageFactory>();
self = factory.CreatePackage(self.name, new UpmVersionList(versions.OrderBy(v => v.version)));
#elif UNITY_2022_2_OR_NEWER || UNITY_2021_3_26_OR_NEWER
self = new UpmPackage(self.uniqueId, true, new UpmVersionList(versions.OrderBy(v => v.version)));
#else
if (self.Has("UpdateVersions", versions, 0))
{
self.Call("UpdateVersions", updatedVersions, 0);
self.Call("UpdateVersions", versions, 0);
}
else if (self.Has("UpdateVersions", versions))
{
self.Call("UpdateVersions", versions);
}
else
{
self.Call("UpdateVersions", updatedVersions);
throw new System.NotImplementedException(
"void UpmPackage.UpdateVersions(IEnumerable<UpmPackageVersion>, int) or void UpmPackage.UpdateVersions(IEnumerable<UpmPackageVersion>) is not found");
}
#endif

return self;
}
}

Expand Down
12 changes: 1 addition & 11 deletions Packages/src/Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,7 @@ private static void UpdateGitPackageVersions()
.OrderBy(v => v.semVersion)
.ThenBy(v => v.isInstalled)
.ToArray();

#if UNITY_2023_1_OR_NEWER
var factory = ScriptableSingleton<ServicesContainer>.instance.Resolve<UpmPackageFactory>();
var versionList = new UpmVersionList(newVersions.OrderBy(v => v.version));
upmPackage = factory.CreatePackage(upmPackage.name, versionList);
#elif UNITY_2022_2_OR_NEWER
var versionList = new UpmVersionList(newVersions.OrderBy(v => v.version));
upmPackage = new UpmPackage(upmPackage.uniqueId, true, versionList);
#else
upmPackage.UpdateVersionsSafety(newVersions);
#endif
upmPackage = upmPackage.UpdateVersionsSafety(newVersions);

return upmPackage;
}
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This project addresses these issues by extending the UI of the Unity Package Man

## ⚙ Installation

_This package requires as following:
This package requires as following:

- **v1.x**: Unity 2018.3 to 2019.4
- **v2.x**: Unity 2020.1 or later
Expand Down

0 comments on commit 563142f

Please sign in to comment.