mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Changed to Color32. Reduced zeroing mesh verts.
This commit is contained in:
parent
00803c42a5
commit
692f24c6b9
@ -36,8 +36,9 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
public String initialSkinName;
|
public String initialSkinName;
|
||||||
public float timeScale = 1;
|
public float timeScale = 1;
|
||||||
private Mesh mesh;
|
private Mesh mesh;
|
||||||
|
private int lastVertexCount;
|
||||||
private Vector3[] vertices;
|
private Vector3[] vertices;
|
||||||
private Color[] colors;
|
private Color32[] colors;
|
||||||
private Vector2[] uvs;
|
private Vector2[] uvs;
|
||||||
private int[] triangles;
|
private int[] triangles;
|
||||||
private float[] vertexPositions = new float[8];
|
private float[] vertexPositions = new float[8];
|
||||||
@ -99,11 +100,13 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
|
|
||||||
// Ensure mesh data is the right size.
|
// Ensure mesh data is the right size.
|
||||||
Vector3[] vertices = this.vertices;
|
Vector3[] vertices = this.vertices;
|
||||||
bool newTriangles = quadCount > vertices.Length / 4;
|
int vertexCount = quadCount * 4;
|
||||||
|
bool newTriangles = vertexCount > vertices.Length;
|
||||||
if (newTriangles) {
|
if (newTriangles) {
|
||||||
this.vertices = vertices = new Vector3[quadCount * 4];
|
// Not enough vertices, increase size.
|
||||||
colors = new Color[quadCount * 4];
|
this.vertices = vertices = new Vector3[vertexCount];
|
||||||
uvs = new Vector2[quadCount * 4];
|
colors = new Color32[vertexCount];
|
||||||
|
uvs = new Vector2[vertexCount];
|
||||||
triangles = new int[quadCount * 6];
|
triangles = new int[quadCount * 6];
|
||||||
mesh.Clear();
|
mesh.Clear();
|
||||||
|
|
||||||
@ -118,15 +121,17 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
triangles[index + 5] = vertex + 1;
|
triangles[index + 5] = vertex + 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Too many vertices, zero the extra.
|
||||||
Vector3 zero = new Vector3(0, 0, 0);
|
Vector3 zero = new Vector3(0, 0, 0);
|
||||||
for (int i = quadCount * 4, n = vertices.Length; i < n; i++)
|
for (int i = vertexCount, n = lastVertexCount; i < n; i++)
|
||||||
vertices[i] = zero;
|
vertices[i] = zero;
|
||||||
}
|
}
|
||||||
|
lastVertexCount = vertexCount;
|
||||||
|
|
||||||
// Setup mesh.
|
// Setup mesh.
|
||||||
float[] vertexPositions = this.vertexPositions;
|
float[] vertexPositions = this.vertexPositions;
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
Color color = new Color();
|
Color32 color = new Color32();
|
||||||
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
||||||
@ -139,10 +144,10 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
|
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
|
||||||
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);
|
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);
|
||||||
|
|
||||||
color.a = skeleton.A * slot.A;
|
color.a = (byte)(skeleton.A * slot.A * 255);
|
||||||
color.r = skeleton.R * slot.R * color.a;
|
color.r = (byte)(skeleton.R * slot.R * color.a);
|
||||||
color.g = skeleton.G * slot.G * color.a;
|
color.g = (byte)(skeleton.G * slot.G * color.a);
|
||||||
color.b = skeleton.B * slot.B * color.a;
|
color.b = (byte)(skeleton.B * slot.B * color.a);
|
||||||
colors[vertexIndex] = color;
|
colors[vertexIndex] = color;
|
||||||
colors[vertexIndex + 1] = color;
|
colors[vertexIndex + 1] = color;
|
||||||
colors[vertexIndex + 2] = color;
|
colors[vertexIndex + 2] = color;
|
||||||
@ -157,7 +162,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
vertexIndex += 4;
|
vertexIndex += 4;
|
||||||
}
|
}
|
||||||
mesh.vertices = vertices;
|
mesh.vertices = vertices;
|
||||||
mesh.colors = colors;
|
mesh.colors32 = colors;
|
||||||
mesh.uv = uvs;
|
mesh.uv = uvs;
|
||||||
if (newTriangles) mesh.triangles = triangles;
|
if (newTriangles) mesh.triangles = triangles;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user