[unity] SpineEditorUtilities. Skip processing if null atlas.

This commit is contained in:
pharan 2018-12-07 03:17:48 +08:00 committed by GitHub
parent c0694bf14b
commit 2aa5685c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -860,26 +860,28 @@ namespace Spine.Unity.Editor {
// Iterate regions and bake marked. // Iterate regions and bake marked.
Atlas atlas = atlasAsset.GetAtlas(); Atlas atlas = atlasAsset.GetAtlas();
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); if (atlas != null) {
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas); FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); var regions = (List<AtlasRegion>)field.GetValue(atlas);
string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath); string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name); string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name);
bool hasBakedRegions = false; bool hasBakedRegions = false;
for (int i = 0; i < regions.Count; i++) { for (int i = 0; i < regions.Count; i++) {
AtlasRegion region = regions[i]; AtlasRegion region = regions[i];
string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.AssetUtility.GetPathSafeName(region.name) + ".prefab").Replace("\\", "/"); string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.AssetUtility.GetPathSafeName(region.name) + ".prefab").Replace("\\", "/");
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject)); GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
if (prefab != null) { if (prefab != null) {
SkeletonBaker.BakeRegion(atlasAsset, region, false); SkeletonBaker.BakeRegion(atlasAsset, region, false);
hasBakedRegions = true; hasBakedRegions = true;
}
} }
}
if (hasBakedRegions) { if (hasBakedRegions) {
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
AssetDatabase.Refresh(); AssetDatabase.Refresh();
}
} }
protectFromStackGarbageCollection.Remove(atlasAsset); protectFromStackGarbageCollection.Remove(atlasAsset);