mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] SpineAtlasAsset.CreateRuntimeInstance methods now provide an optional newCustomTextureLoader parameter.
This commit is contained in:
parent
af4a511722
commit
5a1a19b4e5
@ -49,6 +49,8 @@
|
|||||||
* **Breaking changes**
|
* **Breaking changes**
|
||||||
|
|
||||||
* **Additions**
|
* **Additions**
|
||||||
|
* `BoneFollower` and `BoneFollowerGraphic` now provide an additional `Follow Parent World Scale` parameter to allow following simple scale of parent bones (rotated/skewed scale can't be supported).
|
||||||
|
* `SpineAtlasAsset.CreateRuntimeInstance` methods now provide an optional `newCustomTextureLoader` parameter (defaults to `null`) which can be set to e.g. `(a) => new YourCustomTextureLoader(a)` to use your own `TextureLoader` subclass instead of `MaterialsTextureLoader`.
|
||||||
|
|
||||||
* **Changes of default values**
|
* **Changes of default values**
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
using Spine;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -39,6 +38,7 @@ namespace Spine.Unity {
|
|||||||
public class SpineAtlasAsset : AtlasAssetBase {
|
public class SpineAtlasAsset : AtlasAssetBase {
|
||||||
public TextAsset atlasFile;
|
public TextAsset atlasFile;
|
||||||
public Material[] materials;
|
public Material[] materials;
|
||||||
|
public TextureLoader customTextureLoader;
|
||||||
protected Atlas atlas;
|
protected Atlas atlas;
|
||||||
|
|
||||||
public override bool IsLoaded { get { return this.atlas != null; } }
|
public override bool IsLoaded { get { return this.atlas != null; } }
|
||||||
@ -50,11 +50,19 @@ namespace Spine.Unity {
|
|||||||
#region Runtime Instantiation
|
#region Runtime Instantiation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a runtime AtlasAsset</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>();
|
SpineAtlasAsset atlasAsset = ScriptableObject.CreateInstance<SpineAtlasAsset>();
|
||||||
atlasAsset.Reset();
|
atlasAsset.Reset();
|
||||||
atlasAsset.atlasFile = atlasText;
|
atlasAsset.atlasFile = atlasText;
|
||||||
atlasAsset.materials = materials;
|
atlasAsset.materials = materials;
|
||||||
|
if (newCustomTextureLoader != null)
|
||||||
|
atlasAsset.customTextureLoader = newCustomTextureLoader(atlasAsset);
|
||||||
|
|
||||||
if (initialize)
|
if (initialize)
|
||||||
atlasAsset.GetAtlas();
|
atlasAsset.GetAtlas();
|
||||||
@ -70,8 +78,11 @@ namespace Spine.Unity {
|
|||||||
/// atlas asset JSON file. When procedurally creating textures, each <c>Texture.name</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,
|
/// 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>
|
/// 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)"/>
|
/// <seealso cref="SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool, Func{SpineAtlasAsset, TextureLoader})"/>
|
||||||
public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Material materialPropertySource, bool initialize) {
|
public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures,
|
||||||
|
Material materialPropertySource, bool initialize,
|
||||||
|
Func<SpineAtlasAsset, TextureLoader> newCustomTextureLoader = null) {
|
||||||
|
|
||||||
// Get atlas page names.
|
// Get atlas page names.
|
||||||
string atlasString = atlasText.text;
|
string atlasString = atlasText.text;
|
||||||
atlasString = atlasString.Replace("\r", "");
|
atlasString = atlasString.Replace("\r", "");
|
||||||
@ -106,24 +117,26 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create AtlasAsset normally
|
// Create AtlasAsset normally
|
||||||
return CreateRuntimeInstance(atlasText, materials, initialize);
|
return CreateRuntimeInstance(atlasText, materials, initialize, newCustomTextureLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// <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>
|
/// 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,
|
/// 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>
|
/// 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>
|
/// <seealso cref="SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool, Func{SpineAtlasAsset, TextureLoader})"/>
|
||||||
public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Shader shader, bool initialize) {
|
public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText,
|
||||||
|
Texture2D[] textures, Shader shader, bool initialize,
|
||||||
|
Func<SpineAtlasAsset, TextureLoader> newCustomTextureLoader = null) {
|
||||||
|
|
||||||
if (shader == null)
|
if (shader == null)
|
||||||
shader = Shader.Find("Spine/Skeleton");
|
shader = Shader.Find("Spine/Skeleton");
|
||||||
|
|
||||||
Material materialProperySource = new Material(shader);
|
Material materialProperySource = new Material(shader);
|
||||||
var oa = CreateRuntimeInstance(atlasText, textures, materialProperySource, initialize);
|
return CreateRuntimeInstance(atlasText, textures, materialProperySource, initialize, newCustomTextureLoader);
|
||||||
|
|
||||||
return oa;
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -154,7 +167,7 @@ namespace Spine.Unity {
|
|||||||
try {
|
try {
|
||||||
TextureLoader loader;
|
TextureLoader loader;
|
||||||
if (!onlyMetaData)
|
if (!onlyMetaData)
|
||||||
loader = new MaterialsTextureLoader(this);
|
loader = customTextureLoader == null ? new MaterialsTextureLoader(this) : customTextureLoader;
|
||||||
else
|
else
|
||||||
loader = new NoOpTextureLoader();
|
loader = new NoOpTextureLoader();
|
||||||
atlas = new Atlas(new StringReader(atlasFile.text), "", loader);
|
atlas = new Atlas(new StringReader(atlasFile.text), "", loader);
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
using Spine;
|
using Spine;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.U2D;
|
using UnityEngine.U2D;
|
||||||
|
|
||||||
@ -185,7 +184,7 @@ namespace Spine.Unity {
|
|||||||
texture = AccessPackedTextureEditor(spriteAtlas);
|
texture = AccessPackedTextureEditor(spriteAtlas);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
texture = AccessPackedTexture(sprites);
|
texture = AccessPackedTexture(sprites);
|
||||||
|
|
||||||
Material material = materials[0];
|
Material material = materials[0];
|
||||||
#if !UNITY_EDITOR
|
#if !UNITY_EDITOR
|
||||||
@ -300,8 +299,7 @@ namespace Spine.Unity {
|
|||||||
if (sprites.Length == 0) {
|
if (sprites.Length == 0) {
|
||||||
Debug.LogWarning(string.Format("SpriteAtlas '{0}' contains no sprites. Please make sure all assigned images are set to import type 'Sprite'.", spriteAtlasFile.name), spriteAtlasFile);
|
Debug.LogWarning(string.Format("SpriteAtlas '{0}' contains no sprites. Please make sure all assigned images are set to import type 'Sprite'.", spriteAtlasFile.name), spriteAtlasFile);
|
||||||
return;
|
return;
|
||||||
}
|
} else if (sprites[0].packingMode == SpritePackingMode.Tight) {
|
||||||
else if (sprites[0].packingMode == SpritePackingMode.Tight) {
|
|
||||||
Debug.LogError(string.Format("SpriteAtlas '{0}': Tight packing is not supported. Please disable 'Tight Packing' in the SpriteAtlas Inspector.", spriteAtlasFile.name), spriteAtlasFile);
|
Debug.LogError(string.Format("SpriteAtlas '{0}': Tight packing is not supported. Please disable 'Tight Packing' in the SpriteAtlas Inspector.", spriteAtlasFile.name), spriteAtlasFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user