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

fix: migration should check for read only package #136

Merged
merged 4 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Migration fails with scenes/prefabs in read-only packages `#136`
- Now, migration process doesn't see any scenes/prefabs in read-only packages.

### Security

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Migration fails with scenes/prefabs in read-only packages `#136`
- Now, migration process doesn't see any scenes/prefabs in read-only packages.

### Security

Expand Down
12 changes: 12 additions & 0 deletions Editor/Migration/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Anatawa12.AvatarOptimizer.PrefabSafeSet;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Assertions;
Expand Down Expand Up @@ -233,6 +234,9 @@ private static void MigrateAllScenes(List<string> scenePaths, Action<string, int
for (var i = 0; i < scenePaths.Count; i++)
{
var scenePath = scenePaths[i];
if (IsReadOnlyPath(scenePath))
continue;

var scene = EditorSceneManager.OpenScene(scenePath);

progressCallback(scene.name, i);
Expand Down Expand Up @@ -635,6 +639,13 @@ private static int NestCount(Object instance)
return nestCount;
}

private static bool IsReadOnlyPath(string path)
{
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(path);

return packageInfo != null && packageInfo.source != PackageSource.Embedded && packageInfo.source != PackageSource.Local;
}

private class PrefabInfo
{
public readonly GameObject Prefab;
Expand All @@ -656,6 +667,7 @@ bool CheckPrefabType(PrefabAssetType type) =>

var allPrefabRoots = AssetDatabase.FindAssets("t:prefab")
.Select(AssetDatabase.GUIDToAssetPath)
.Where(s => !IsReadOnlyPath(s))
.Select(AssetDatabase.LoadAssetAtPath<GameObject>)
.Where(x => x)
.Where(x => CheckPrefabType(PrefabUtility.GetPrefabAssetType(x)))
Expand Down