|
@@ -27,7 +27,6 @@
|
|
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
*****************************************************************************/
|
|
|
|
|
|
-using Spine;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
@@ -39,6 +38,7 @@ namespace Spine.Unity {
|
|
|
public class SpineAtlasAsset : AtlasAssetBase {
|
|
|
public TextAsset atlasFile;
|
|
|
public Material[] materials;
|
|
|
+ public TextureLoader customTextureLoader;
|
|
|
protected Atlas atlas;
|
|
|
|
|
|
public override bool IsLoaded { get { return this.atlas != null; } }
|
|
@@ -50,11 +50,19 @@ namespace Spine.Unity {
|
|
|
#region Runtime Instantiation
|
|
|
/// <summary>
|
|
|
/// Creates a runtime AtlasAsset</summary>
|
|
|
- public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize) {
|
|
|
+ /// <param name="newCustomTextureLoader">When not null, a function instantiating
|
|
|
+ /// a custom <c>TextureLoader</c> with the newly created <c>SpineAtlasAsset</c> as argument
|
|
|
+ /// is used instead of instantiating the default <c>MaterialsTextureLoader</c>.
|
|
|
+ /// A valid parameter is e.g. <c>(a) => new CustomTextureLoader(a)</c></param>
|
|
|
+ public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize,
|
|
|
+ Func<SpineAtlasAsset, TextureLoader> newCustomTextureLoader = null) {
|
|
|
+
|
|
|
SpineAtlasAsset atlasAsset = ScriptableObject.CreateInstance<SpineAtlasAsset>();
|
|
|
atlasAsset.Reset();
|
|
|
atlasAsset.atlasFile = atlasText;
|
|
|
atlasAsset.materials = materials;
|
|
|
+ if (newCustomTextureLoader != null)
|
|
|
+ atlasAsset.customTextureLoader = newCustomTextureLoader(atlasAsset);
|
|
|
|
|
|
if (initialize)
|
|
|
atlasAsset.GetAtlas();
|
|
@@ -70,8 +78,11 @@ namespace Spine.Unity {
|
|
|
/// atlas asset JSON file. When procedurally creating textures, each <c>Texture.name</c>
|
|
|
/// needs to be set to the atlas page texture filename without the .png extension,
|
|
|
/// e.g. 'my_skeleton' if the png filename listed in the atlas asset file is 'my_skeleton.png'.</param>
|
|
|
- /// <seealso cref="Spine.Unity.SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool)"/>
|
|
|
- public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Material materialPropertySource, bool initialize) {
|
|
|
+ /// <seealso cref="SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool, Func{SpineAtlasAsset, TextureLoader})"/>
|
|
|
+ public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures,
|
|
|
+ Material materialPropertySource, bool initialize,
|
|
|
+ Func<SpineAtlasAsset, TextureLoader> newCustomTextureLoader = null) {
|
|
|
+
|
|
|
// Get atlas page names.
|
|
|
string atlasString = atlasText.text;
|
|
|
atlasString = atlasString.Replace("\r", "");
|
|
@@ -106,24 +117,26 @@ namespace Spine.Unity {
|
|
|
}
|
|
|
|
|
|
// Create AtlasAsset normally
|
|
|
- return CreateRuntimeInstance(atlasText, materials, initialize);
|
|
|
+ return CreateRuntimeInstance(atlasText, materials, initialize, newCustomTextureLoader);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches.
|
|
|
+ /// Creates a runtime AtlasAsset. Only providing the textures is slower because
|
|
|
+ /// it has to search for atlas page matches.
|
|
|
/// <param name="textures">An array of all textures referenced in the provided <c>atlasText</c>
|
|
|
/// atlas asset JSON file. When procedurally creating textures, each <c>Texture.name</c>
|
|
|
/// needs to be set to the atlas page texture filename without the .png extension,
|
|
|
/// e.g. 'my_skeleton' if the png filename listed in the atlas asset file is 'my_skeleton.png'.</param>
|
|
|
- /// <seealso cref="Spine.Unity.AtlasAssetBase.CreateRuntimeInstance(TextAsset, Material[], bool)"/></summary>
|
|
|
- public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Shader shader, bool initialize) {
|
|
|
+ /// <seealso cref="SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool, Func{SpineAtlasAsset, TextureLoader})"/>
|
|
|
+ public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText,
|
|
|
+ Texture2D[] textures, Shader shader, bool initialize,
|
|
|
+ Func<SpineAtlasAsset, TextureLoader> newCustomTextureLoader = null) {
|
|
|
+
|
|
|
if (shader == null)
|
|
|
shader = Shader.Find("Spine/Skeleton");
|
|
|
|
|
|
Material materialProperySource = new Material(shader);
|
|
|
- var oa = CreateRuntimeInstance(atlasText, textures, materialProperySource, initialize);
|
|
|
-
|
|
|
- return oa;
|
|
|
+ return CreateRuntimeInstance(atlasText, textures, materialProperySource, initialize, newCustomTextureLoader);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -154,7 +167,7 @@ namespace Spine.Unity {
|
|
|
try {
|
|
|
TextureLoader loader;
|
|
|
if (!onlyMetaData)
|
|
|
- loader = new MaterialsTextureLoader(this);
|
|
|
+ loader = customTextureLoader == null ? new MaterialsTextureLoader(this) : customTextureLoader;
|
|
|
else
|
|
|
loader = new NoOpTextureLoader();
|
|
|
atlas = new Atlas(new StringReader(atlasFile.text), "", loader);
|