[unity] Fixed new atlas format import after atlas format changes (see commit f8d6359). Replaced hardcoded first pass of dual-pass atlas loading with proper Atlas method calls.

This commit is contained in:
Harald Csaszar 2020-12-21 19:16:09 +01:00
parent 93695d5eed
commit 1a431045c6
4 changed files with 23 additions and 16 deletions

View File

@ -487,18 +487,14 @@ namespace Spine.Unity.Editor {
protectFromStackGarbageCollection.Add(atlasAsset);
atlasAsset.atlasFile = atlasText;
//strip CR
string atlasStr = atlasText.text;
atlasStr = atlasStr.Replace("\r", "");
string[] atlasLines = atlasStr.Split('\n');
List<string> pageFiles = new List<string>();
for (int i = 0; i < atlasLines.Length - 1; i++) {
if (atlasLines[i].Trim().Length == 0)
pageFiles.Add(atlasLines[i + 1].Trim());
Atlas atlas = atlasAsset.GetAtlas(onlyMetaData : true);
if (atlas != null) {
foreach (var page in atlas.Pages)
pageFiles.Add(page.name);
}
var populatingMaterials = new List<Material>(pageFiles.Count);//atlasAsset.materials = new Material[pageFiles.Count];
var populatingMaterials = new List<Material>(pageFiles.Count);
for (int i = 0; i < pageFiles.Count; i++) {
string texturePath = assetPath + "/" + pageFiles[i];
@ -555,7 +551,8 @@ namespace Spine.Unity.Editor {
Debug.Log(string.Format("{0} :: Imported with {1} material", atlasAsset.name, atlasAsset.materials.Length), atlasAsset);
// Iterate regions and bake marked.
Atlas atlas = atlasAsset.GetAtlas();
atlasAsset.Clear();
atlas = atlasAsset.GetAtlas(onlyMetaData: false);
if (atlas != null) {
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
var regions = (List<AtlasRegion>)field.GetValue(atlas);

View File

@ -39,6 +39,6 @@ namespace Spine.Unity {
public abstract bool IsLoaded { get; }
public abstract void Clear ();
public abstract Atlas GetAtlas ();
public abstract Atlas GetAtlas (bool onlyMetaData = false);
}
}

View File

@ -123,14 +123,14 @@ namespace Spine.Unity {
}
/// <returns>The atlas or null if it could not be loaded.</returns>
public override Atlas GetAtlas () {
public override Atlas GetAtlas (bool onlyMetaData = false) {
if (atlasFile == null) {
Debug.LogError("Atlas file not set for atlas asset: " + name, this);
Clear();
return null;
}
if (materials == null || materials.Length == 0) {
if (!onlyMetaData && (materials == null || materials.Length == 0)) {
Debug.LogError("Materials not set for atlas asset: " + name, this);
Clear();
return null;
@ -139,7 +139,12 @@ namespace Spine.Unity {
if (atlas != null) return atlas;
try {
atlas = new Atlas(new StringReader(atlasFile.text), "", new MaterialsTextureLoader(this));
TextureLoader loader;
if (!onlyMetaData)
loader = new MaterialsTextureLoader(this);
else
loader = new NoOpTextureLoader();
atlas = new Atlas(new StringReader(atlasFile.text), "", loader);
atlas.FlipV();
return atlas;
} catch (Exception ex) {
@ -207,6 +212,11 @@ namespace Spine.Unity {
}
}
public class NoOpTextureLoader : TextureLoader {
public void Load (AtlasPage page, string path) {}
public void Unload (object texture) {}
}
public class MaterialsTextureLoader : TextureLoader {
SpineAtlasAsset atlasAsset;

View File

@ -97,14 +97,14 @@ namespace Spine.Unity {
}
/// <returns>The atlas or null if it could not be loaded.</returns>
public override Atlas GetAtlas () {
public override Atlas GetAtlas (bool onlyMetaData = false) {
if (spriteAtlasFile == null) {
Debug.LogError("SpriteAtlas file not set for SpineSpriteAtlasAsset: " + name, this);
Clear();
return null;
}
if (materials == null || materials.Length == 0) {
if (!onlyMetaData && (materials == null || materials.Length == 0)) {
Debug.LogError("Materials not set for SpineSpriteAtlasAsset: " + name, this);
Clear();
return null;