Skip to content

Commit 05cf6bd

Browse files
committed
Fixed UnityAsset importing in installer
1 parent 4579af3 commit 05cf6bd

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

MLAPI-Editor/MLAPIEditor.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ public void OnGUI()
2525
float extraPaddingBottom = 30f;
2626
GUILayout.BeginArea(new Rect(padding, padding, position.width - (padding * 2f), (position.height - (padding * 2f)) - extraPaddingBottom));
2727
scrollPos = GUILayout.BeginScrollView(scrollPos);
28-
GUIStyle style = new GUIStyle(EditorStyles.wordWrappedLabel);
29-
style.normal.textColor = Color.yellow;
30-
style.alignment = TextAnchor.MiddleCenter;
31-
style.fontStyle = FontStyle.Bold;
28+
GUIStyle warningStyle = new GUIStyle(EditorStyles.wordWrappedLabel);
29+
warningStyle.normal.textColor = Color.yellow;
30+
warningStyle.alignment = TextAnchor.MiddleCenter;
31+
warningStyle.fontStyle = FontStyle.Bold;
32+
33+
GUIStyle errorStyle = new GUIStyle(EditorStyles.wordWrappedLabel);
34+
errorStyle.normal.textColor = Color.red;
35+
errorStyle.alignment = TextAnchor.MiddleCenter;
36+
errorStyle.fontStyle = FontStyle.Bold;
37+
38+
3239
EditorGUILayout.LabelField("The version you are upgrading to has a greater major version. This means that there are non backwards compatibile changes. \n" +
33-
"For more information about the MLAPI versioning, please visit SemVer.org \n" +
34-
"Here are the versions with breaking changes you are skipping.", style);
40+
"For more information about the MLAPI versioning, please visit SemVer.org", warningStyle);
41+
EditorGUILayout.LabelField("It's ALWAYS recommended to do a backup when upgrading major versions. If your project doesn't compile " +
42+
"There is good chance serialized data will be PERMANENTLY LOST. Don't be stupid.", errorStyle);
43+
EditorGUILayout.LabelField("Here are the versions with breaking changes you are skipping.", EditorStyles.wordWrappedLabel);
3544
GUILayout.Space(5);
3645
for (int i = 0; i < releases.Length; i++)
3746
{
@@ -240,8 +249,10 @@ private long lastUpdated
240249
private float progressTarget = 0f;
241250
private float progress = 0f;
242251

252+
[SerializeField]
243253
private bool PendingPackageLock = false;
244-
private readonly Queue<string> PendingPackages = new Queue<string>();
254+
[SerializeField]
255+
private List<string> PendingPackages = new List<string>();
245256

246257

247258
[MenuItem("Window/MLAPI")]
@@ -264,7 +275,14 @@ private void OnGUI()
264275

265276
if (PendingPackages.Count > 0 && !EditorApplication.isCompiling && !EditorApplication.isUpdating && !PendingPackageLock)
266277
{
267-
string packageName = PendingPackages.Dequeue();
278+
PendingPackageLock = true;
279+
280+
string packageName = PendingPackages[PendingPackages.Count - 1];
281+
PendingPackages.RemoveAt(PendingPackages.Count - 1);
282+
283+
AssetDatabase.importPackageCompleted += OnPackageImported;
284+
AssetDatabase.importPackageFailed += OnPackageImportFailed;
285+
268286
AssetDatabase.ImportPackage(Application.dataPath + "/MLAPI/Lib/" + packageName, false);
269287
}
270288

@@ -348,6 +366,18 @@ private void OnGUI()
348366
Repaint();
349367
}
350368

369+
private void OnPackageImported(string packageName)
370+
{
371+
AssetDatabase.importPackageCompleted -= OnPackageImported;
372+
PendingPackageLock = false;
373+
}
374+
375+
private void OnPackageImportFailed(string packageName, string errorMessage)
376+
{
377+
AssetDatabase.importPackageFailed -= OnPackageImportFailed;
378+
PendingPackageLock = false;
379+
}
380+
351381
private List<MLAPIVersion> GetMajorVersionsBetween(MLAPIVersion currentVersion, MLAPIVersion targetVersion)
352382
{
353383
List<MLAPIVersion> versionsBetween = new List<MLAPIVersion>();
@@ -461,7 +491,7 @@ private IEnumerator InstallRelease(int index)
461491

462492
if (releases[index].assets[i].name.EndsWith(".unitypackage"))
463493
{
464-
PendingPackages.Enqueue(releases[index].assets[i].name);
494+
PendingPackages.Add(releases[index].assets[i].name);
465495
}
466496
yield return null;
467497
}

0 commit comments

Comments
 (0)