Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages install path can again be edited from preferences window #619

Merged
merged 9 commits into from
Apr 1, 2024
17 changes: 2 additions & 15 deletions src/NuGetForUnity/Editor/Ui/NugetPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public class NugetPreferences : SettingsProvider
/// </summary>
public const string NuGetForUnityVersion = "4.0.2";

private const string RefreshOnStartKey = "NugetForUnityPrefsShouldRefreshOnNextStart";

private const float LabelPading = 5;

private readonly GUIContent deleteX = new GUIContent("\u2716");
Expand Down Expand Up @@ -78,12 +76,6 @@ public class NugetPreferences : SettingsProvider
private NugetPreferences()
: base("Preferences/NuGet For Unity", SettingsScope.User)
{
if (SessionState.GetBool(RefreshOnStartKey, false))
{
SessionState.EraseBool(RefreshOnStartKey);
AssetDatabase.Refresh();
}

shouldShowPackagesConfigPathWarning = ConfigurationManager.NugetConfigFile.Placement == NugetPlacement.CustomWithinAssets &&
!UnityPathHelper.IsPathInAssets(ConfigurationManager.NugetConfigFile.PackagesConfigDirectoryPath);
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
Expand Down Expand Up @@ -163,12 +155,6 @@ public override void OnGUI([CanBeNull] string searchContext)
var newPlacement = (NugetPlacement)EditorGUILayout.EnumPopup("Placement:", ConfigurationManager.NugetConfigFile.Placement);
if (newPlacement != ConfigurationManager.NugetConfigFile.Placement)
{
// For some reason Unity needs to do one additional refresh after the first one when we move files to Packages folder.
if (newPlacement == NugetPlacement.InPackagesFolder)
{
SessionState.SetBool(RefreshOnStartKey, true);
}

var oldRepoPath = ConfigurationManager.NugetConfigFile.RepositoryPath;
InstalledPackagesManager.UpdateInstalledPackages(); // Make sure it is initialized before we move files around
ConfigurationManager.MoveConfig(newPlacement);
Expand Down Expand Up @@ -567,7 +553,8 @@ public override void OnGUI([CanBeNull] string searchContext)

if (needsAssetRefresh)
{
AssetDatabase.Refresh();
// AssetDatabase.Refresh(); doesn't work when we move the files from Assets to Packages so we use this instead:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing both works well!
Erasing AssetDatabase.Refresh(); causes error.

EditorApplication.ExecuteMenuItem("Assets/Refresh");
}
}

Expand Down
Loading