diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index d0a973e72..eff0aa759 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -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 pageFiles = new List(); - 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(pageFiles.Count);//atlasAsset.materials = new Material[pageFiles.Count]; + var populatingMaterials = new List(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)field.GetValue(atlas); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs index a987b54fc..2746182c0 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs @@ -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); } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs index f419a9fec..9d7cecf26 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs @@ -123,14 +123,14 @@ namespace Spine.Unity { } /// The atlas or null if it could not be loaded. - 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; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineSpriteAtlasAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineSpriteAtlasAsset.cs index 6dec03a1c..f84e19693 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineSpriteAtlasAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineSpriteAtlasAsset.cs @@ -97,14 +97,14 @@ namespace Spine.Unity { } /// The atlas or null if it could not be loaded. - 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;