Skip to content

Commit

Permalink
When in batchmode, call OnEditorUpdate from the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
VMaldecoasago committed Jul 8, 2024
1 parent 6b9c8f3 commit 06244e1
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using System.Threading;

namespace Apple.Core
{
Expand Down Expand Up @@ -180,6 +181,18 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del

EditorApplication.update += OnEditorUpdate;
Events.registeringPackages += OnPackageManagerRegistrationUpdate;

if (Application.isBatchMode) {
// when in -batchmode -quit, EditorUpdate is not called, so we have to
// lock the main thread until the packages are downloaded
static long nowMilis() => DateTimeOffset.Now.ToUnixTimeMilliseconds();
long start = nowMilis();
const long timeout = 10000;
while (_updateState != UpdateState.Updating && nowMilis() - start < timeout) {
Thread.Sleep(100);
OnEditorUpdate();
}
}
}

/// <summary>
Expand Down

0 comments on commit 06244e1

Please sign in to comment.