Skip to content

Commit

Permalink
Unity 2022 update, dependency update
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackebein committed Mar 4, 2024
1 parent f3aa779 commit 6f104c2
Show file tree
Hide file tree
Showing 18 changed files with 606 additions and 331 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ public static List<string> GetAffectedPackageList(IVRCPackage package)

public static void ForceRefresh ()
{
MethodInfo method = typeof( UnityEditor.PackageManager.Client ).GetMethod( "Resolve", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.DeclaredOnly );
if( method != null )
method.Invoke( null, null );

UnityEditor.PackageManager.Client.Resolve();
AssetDatabase.Refresh();
}

Expand Down
167 changes: 117 additions & 50 deletions Packages/com.vrchat.core.vpm-resolver/Editor/Resolver/ResolverWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
Expand All @@ -21,9 +23,25 @@ public class ResolverWindow : EditorWindow
private static Button _resolveButton;
private static Box _manifestInfo;
private static Label _manifestLabel;
private static Label _manifestInfoText;
private static VisualElement _manifestPackageList;
private static bool _isUpdating;
private static Color _colorPositive = Color.green;
private static Color _colorNegative = new Color(1, 0.3f, 0.3f);

const string HAS_REFRESHED_KEY = "VRC.PackageManagement.Resolver.Refreshed";

private static bool IsUpdating
{
get => _isUpdating;
set
{
_isUpdating = value;
_refreshButton.SetEnabled(!value);
_refreshButton.text = value ? "Refreshing..." : "Refresh";
_manifestLabel.text = value ? "Refreshing packages ..." : "Required Packages";
}
}


[MenuItem("VRChat SDK/Utilities/Package Resolver")]
Expand All @@ -33,48 +51,66 @@ public static void ShowWindow()
wnd.titleContent = new GUIContent("Package Resolver");
}

public static void Refresh()
public static async Task Refresh()
{
if (_rootView == null || string.IsNullOrWhiteSpace(Resolver.ProjectDir)) return;

_manifestInfo.SetEnabled(!_isUpdating);
_refreshButton.SetEnabled(!_isUpdating);
_manifestLabel.text = (_isUpdating ? "Working ..." : "Required Packages");
_manifestInfo.Clear();
_manifestInfo.Add(_manifestLabel);

bool needsResolve = VPMProjectManifest.ResolveIsNeeded(Resolver.ProjectDir);
string resolveStatus = needsResolve ? "Please press \"Resolve\" to Download them." : "All of them are in the project.";
IsUpdating = true;
_manifestPackageList.Clear();

// check for vpm dependencies
if (!Resolver.VPMManifestExists())
{
TextElement noManifestText = new TextElement();
noManifestText.text = "No VPM Manifest";
noManifestText.style.color = _colorNegative;
_manifestInfo.Add(noManifestText);
_manifestInfoText.style.display = DisplayStyle.Flex;
_manifestInfoText.text = "No VPM Manifest";
_manifestInfoText.style.color = _colorNegative;
}
else
{
var manifest = VPMProjectManifest.Load(Resolver.ProjectDir);
var project = new UnityProject(Resolver.ProjectDir);

// Here is where we detect if all dependencies are installed
var allDependencies = (manifest.locked != null && manifest.locked.Count > 0)
? manifest.locked
: manifest.dependencies;
_manifestInfoText.style.display = DisplayStyle.None;
}

var manifest = VPMProjectManifest.Load(Resolver.ProjectDir);
var project = await Task.Run(() => new UnityProject(Resolver.ProjectDir));

// Here is where we detect if all dependencies are installed
var allDependencies = manifest.locked != null && manifest.locked.Count > 0
? manifest.locked
: manifest.dependencies;

var depList = await Task.Run(() =>
{
var results = new Dictionary<(string id, string version), (IVRCPackage package, List<string> allVersions)>();
foreach (var pair in allDependencies)
{
var id = pair.Key;
var version = pair.Value.version;
IVRCPackage package = project.VPMProvider.GetPackage(id, version);
_manifestInfo.Add(CreateDependencyRow(id, version, project, (package != null)));
var package = project.VPMProvider.GetPackage(id, version);
results.Add((id, version), (package, Resolver.GetAllVersionsOf(id)));
}

var legacyPackages = project.VPMProvider.GetLegacyPackages();

results = results.Where(i => !legacyPackages.Contains(i.Key.id)).ToDictionary(i => i.Key, i => i.Value);

return results;
});

foreach (var dep in depList)
{

_manifestPackageList.Add(
CreateDependencyRow(
dep.Key.id,
dep.Key.version,
project,
dep.Value.package,
dep.Value.allVersions
)
);
}
_resolveButton.SetEnabled(needsResolve);
Resolver.ForceRefresh();

IsUpdating = false;
}

/// <summary>
Expand Down Expand Up @@ -119,44 +155,81 @@ private void CreateGUI()
name = "manifest-info",
};
_manifestLabel = (new Label("Required Packages") { name = "manifest-header" });
_manifestInfo.Add(_manifestLabel);
_manifestInfoText = new Label();
_manifestInfo.Add(_manifestInfoText);
_manifestPackageList = new VisualElement();
_manifestPackageList.style.flexDirection = FlexDirection.Column;
_manifestPackageList.style.alignItems = Align.Stretch;
_manifestInfo.Add(_manifestPackageList);

_rootView.Add(_manifestInfo);

// Refresh Button
var refreshBox = new Box();
_refreshButton = new Button(Refresh)
_refreshButton = new Button(() =>
{
// When manually refreshing - ensure package manager is also up to date
Resolver.ForceRefresh();
Refresh();
})
{
text = "Refresh",
name = "refresh-button-base"
};
refreshBox.Add(_refreshButton);
_rootView.Add(refreshBox);

// Refresh on open
// Sometimes unity can get into a bad state where calling package manager refresh will endlessly reload assemblies
// That in turn means that a Full refresh will be called every single time assemblies are loaded
// Which locks up the editor in an endless loop
// This condition ensures that the UPM resolve only happens on first launch
// We also call it after installing packages or hitting Refresh manually
if (!SessionState.GetBool(HAS_REFRESHED_KEY, false))
{
SessionState.SetBool(HAS_REFRESHED_KEY, true);
Resolver.ForceRefresh();
}

Refresh();
rootVisualElement.schedule.Execute(() => Refresh()).ExecuteLater(100);
}

private static VisualElement CreateDependencyRow(string id, string version, UnityProject project, bool havePackage)
private static VisualElement CreateDependencyRow(string id, string version, UnityProject project, IVRCPackage package, List <string> allVersions)
{
// Table

VisualElement row = new Box() { name = "package-box" };
VisualElement column1 = new Box() { name = "package-box" };
VisualElement column2 = new Box() { name = "package-box" };
VisualElement column3 = new Box() { name = "package-box" };
VisualElement column4 = new Box() { name = "package-box" };
bool havePackage = package != null;

// Table Row
VisualElement row = new Box { name = "package-row" };
VisualElement column1 = new Box { name = "package-box" };
VisualElement column2 = new Box { name = "package-box" };
VisualElement column3 = new Box { name = "package-box" };
VisualElement column4 = new Box { name = "package-box" };

column1.style.minWidth = 200;
column1.style.width = new StyleLength(new Length(40, LengthUnit.Percent));
column2.style.minWidth = 100;
column2.style.width = new StyleLength(new Length(20, LengthUnit.Percent));
column3.style.minWidth = 100;
column3.style.width = new StyleLength(new Length(20, LengthUnit.Percent));
column4.style.minWidth = 100;
column4.style.width = new StyleLength(new Length(20, LengthUnit.Percent));

row.Add(column1);
row.Add(column2);
row.Add(column3);
row.Add(column4);

// Package Name + Status

column1.style.alignItems = Align.FlexStart;
if (havePackage)
{
column1.style.flexDirection = FlexDirection.Column;
var titleRow = new VisualElement();
titleRow.style.unityFontStyleAndWeight = FontStyle.Bold;
titleRow.Add(new Label(package.Title));
column1.Add(titleRow);
}
TextElement text = new TextElement { text = $"{id} {version} " };

column1.Add(text);
Expand All @@ -165,29 +238,23 @@ private static VisualElement CreateDependencyRow(string id, string version, Unit
{
TextElement missingText = new TextElement { text = "MISSING" };
missingText.style.color = _colorNegative;
missingText.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
column2.Add(missingText);
}

// Version Popup

var choices = new List<string>();
foreach (string n in Resolver.GetAllVersionsOf(id))
var currVersion = Mathf.Max(0, havePackage ? allVersions.IndexOf(package.Version) : 0);
var popupField = new PopupField<string>(allVersions, 0)
{
choices.Add(n);
}

var popupField = new PopupField<string>(choices, 0);
popupField.value = choices[0];
popupField.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
value = allVersions[currVersion]
};

column3.Add(popupField);

// Button

Button updateButton = new Button() { text = "Update" };
if (havePackage)
RefreshUpdateButton(updateButton, version, choices[0]);
RefreshUpdateButton(updateButton, version, allVersions[0]);
else
RefreshMissingButton(updateButton);

Expand Down Expand Up @@ -264,7 +331,6 @@ private static void RefreshMissingButton(Button button)
{
button.text = "Resolve";
SetButtonColor(button, Color.white);
button.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
}

private static void SetButtonColor(Button button, Color color)
Expand All @@ -281,11 +347,12 @@ private static void SetButtonColor(Button button, Color color)
private static async void OnUpdatePackageClicked(UnityProject project, IVRCPackage package)
{
_isUpdating = true;
Refresh();
await Refresh();
await Task.Delay(500);
await Task.Run(() => project.UpdateVPMPackage(package));
project.UpdateVPMPackage(package);
_isUpdating = false;
Refresh();
Resolver.ForceRefresh();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@

#package-box {
margin:2px;
padding:10px;
border-width:0px;
border-width: 0;
flex-direction:row;
max-height:20px;
min-height:20px;
height:20px;
padding-top:0px;
padding-bottom:0px;
margin-top:0px;
margin-bottom:0px;
padding: 6px;
justify-content: center;
align-items:center;
}

#package-row {
padding: 0;
margin: 0;
flex-direction: row;
background-color: rgba(0,0,0,0);
}

#manifest-header {
font-size: 20px;
margin-bottom: 10px;
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.vrchat.core.vpm-resolver/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name" : "com.vrchat.core.vpm-resolver",
"displayName" : "VRChat Package Resolver Tool",
"version" : "0.1.26",
"unity" : "2019.4",
"version" : "0.1.28",
"unity" : "2022.3",
"description" : "Tool to Download VPM Packages",
"vrchatVersion" : "2022.3.3",
"author" : {
Expand Down
10 changes: 4 additions & 6 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"dependencies": {
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.rider": "3.0.26",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.ide.vscode": "1.2.5",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "2.1.6",
"com.unity.timeline": "1.2.18",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.6",
"com.unity.ugui": "1.0.0",
"com.unity.xr.oculus.standalone": "2.38.4",
"com.unity.xr.openvr.standalone": "2.0.5",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down Expand Up @@ -41,4 +39,4 @@
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}
}
Loading

0 comments on commit 6f104c2

Please sign in to comment.