mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Fixed SkeletonGraphic not updating the canvas renderer texture after skin changes (e.g. when calling GetRepackedSkin). Closes #1459.
This commit is contained in:
parent
0207da7493
commit
687b53d15d
@ -59,6 +59,8 @@ namespace Spine.Unity {
|
|||||||
public bool freeze;
|
public bool freeze;
|
||||||
public bool unscaledTime;
|
public bool unscaledTime;
|
||||||
|
|
||||||
|
private Texture baseTexture = null;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void OnValidate () {
|
protected override void OnValidate () {
|
||||||
// This handles Scene View preview.
|
// This handles Scene View preview.
|
||||||
@ -152,9 +154,8 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
public override Texture mainTexture {
|
public override Texture mainTexture {
|
||||||
get {
|
get {
|
||||||
// Fail loudly when incorrectly set up.
|
|
||||||
if (overrideTexture != null) return overrideTexture;
|
if (overrideTexture != null) return overrideTexture;
|
||||||
return skeletonDataAsset == null ? null : skeletonDataAsset.atlasAssets[0].PrimaryMaterial.mainTexture;
|
return baseTexture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +273,7 @@ namespace Spine.Unity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
meshBuffers = new DoubleBuffered<MeshRendererBuffers.SmartMesh>();
|
meshBuffers = new DoubleBuffered<MeshRendererBuffers.SmartMesh>();
|
||||||
|
baseTexture = skeletonDataAsset.atlasAssets[0].PrimaryMaterial.mainTexture;
|
||||||
canvasRenderer.SetTexture(this.mainTexture); // Needed for overwriting initializations.
|
canvasRenderer.SetTexture(this.mainTexture); // Needed for overwriting initializations.
|
||||||
|
|
||||||
// Set the initial Skin and Animation
|
// Set the initial Skin and Animation
|
||||||
@ -296,8 +298,7 @@ namespace Spine.Unity {
|
|||||||
skeleton.SetColor(this.color);
|
skeleton.SetColor(this.color);
|
||||||
var smartMesh = meshBuffers.GetNext();
|
var smartMesh = meshBuffers.GetNext();
|
||||||
var currentInstructions = this.currentInstructions;
|
var currentInstructions = this.currentInstructions;
|
||||||
|
MeshGenerator.GenerateSingleSubmeshInstruction(currentInstructions, skeleton, null);
|
||||||
MeshGenerator.GenerateSingleSubmeshInstruction(currentInstructions, skeleton, this.material);
|
|
||||||
bool updateTriangles = SkeletonRendererInstruction.GeometryNotEqual(currentInstructions, smartMesh.instructionUsed);
|
bool updateTriangles = SkeletonRendererInstruction.GeometryNotEqual(currentInstructions, smartMesh.instructionUsed);
|
||||||
|
|
||||||
meshGenerator.Begin();
|
meshGenerator.Begin();
|
||||||
@ -318,6 +319,15 @@ namespace Spine.Unity {
|
|||||||
canvasRenderer.SetMesh(mesh);
|
canvasRenderer.SetMesh(mesh);
|
||||||
smartMesh.instructionUsed.Set(currentInstructions);
|
smartMesh.instructionUsed.Set(currentInstructions);
|
||||||
|
|
||||||
|
if (currentInstructions.submeshInstructions.Count > 0) {
|
||||||
|
var material = currentInstructions.submeshInstructions.Items[0].material;
|
||||||
|
if (material != null && baseTexture != material.mainTexture) {
|
||||||
|
baseTexture = material.mainTexture;
|
||||||
|
if (overrideTexture == null)
|
||||||
|
canvasRenderer.SetTexture(this.mainTexture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//this.UpdateMaterial(); // TODO: This allocates memory.
|
//this.UpdateMaterial(); // TODO: This allocates memory.
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -133,6 +133,14 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Step 1 : Generate Instructions
|
#region Step 1 : Generate Instructions
|
||||||
|
/// <summary>
|
||||||
|
/// A specialized variant of <see cref="GenerateSkeletonRendererInstruction"/>.
|
||||||
|
/// Generates renderer instructions using a single submesh, using only a single material and texture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="instructionOutput">The resulting instructions.</param>
|
||||||
|
/// <param name="skeleton">The skeleton to generate renderer instructions for.</param>
|
||||||
|
/// <param name="material">Material to be set at the renderer instruction. When null, the last attachment
|
||||||
|
/// in the draw order list is assigned as the instruction's material.</param>
|
||||||
public static void GenerateSingleSubmeshInstruction (SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Material material) {
|
public static void GenerateSingleSubmeshInstruction (SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Material material) {
|
||||||
ExposedList<Slot> drawOrder = skeleton.drawOrder;
|
ExposedList<Slot> drawOrder = skeleton.drawOrder;
|
||||||
int drawOrderCount = drawOrder.Count;
|
int drawOrderCount = drawOrder.Count;
|
||||||
@ -161,6 +169,7 @@ namespace Spine.Unity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if SPINE_TRIANGLECHECK
|
#if SPINE_TRIANGLECHECK
|
||||||
|
object rendererObject = null;
|
||||||
bool skeletonHasClipping = false;
|
bool skeletonHasClipping = false;
|
||||||
var drawOrderItems = drawOrder.Items;
|
var drawOrderItems = drawOrder.Items;
|
||||||
for (int i = 0; i < drawOrderCount; i++) {
|
for (int i = 0; i < drawOrderCount; i++) {
|
||||||
@ -174,11 +183,13 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
var regionAttachment = attachment as RegionAttachment;
|
var regionAttachment = attachment as RegionAttachment;
|
||||||
if (regionAttachment != null) {
|
if (regionAttachment != null) {
|
||||||
|
rendererObject = regionAttachment.RendererObject;
|
||||||
attachmentVertexCount = 4;
|
attachmentVertexCount = 4;
|
||||||
attachmentTriangleCount = 6;
|
attachmentTriangleCount = 6;
|
||||||
} else {
|
} else {
|
||||||
var meshAttachment = attachment as MeshAttachment;
|
var meshAttachment = attachment as MeshAttachment;
|
||||||
if (meshAttachment != null) {
|
if (meshAttachment != null) {
|
||||||
|
rendererObject = meshAttachment.RendererObject;
|
||||||
attachmentVertexCount = meshAttachment.worldVerticesLength >> 1;
|
attachmentVertexCount = meshAttachment.worldVerticesLength >> 1;
|
||||||
attachmentTriangleCount = meshAttachment.triangles.Length;
|
attachmentTriangleCount = meshAttachment.triangles.Length;
|
||||||
} else {
|
} else {
|
||||||
@ -194,8 +205,14 @@ namespace Spine.Unity {
|
|||||||
current.rawTriangleCount += attachmentTriangleCount;
|
current.rawTriangleCount += attachmentTriangleCount;
|
||||||
current.rawVertexCount += attachmentVertexCount;
|
current.rawVertexCount += attachmentVertexCount;
|
||||||
totalRawVertexCount += attachmentVertexCount;
|
totalRawVertexCount += attachmentVertexCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#if !SPINE_TK2D
|
||||||
|
if (material == null)
|
||||||
|
current.material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
|
#else
|
||||||
|
if (material == null)
|
||||||
|
current.material = (rendererObject is Material) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
|
#endif
|
||||||
|
|
||||||
instructionOutput.hasActiveClipping = skeletonHasClipping;
|
instructionOutput.hasActiveClipping = skeletonHasClipping;
|
||||||
instructionOutput.rawVertexCount = totalRawVertexCount;
|
instructionOutput.rawVertexCount = totalRawVertexCount;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user