소스 검색

Fixed slot colors.

NathanSweet 12 년 전
부모
커밋
e0fffa79b3
3개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 13 0
      spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs
  2. 2 1
      spine-unity/Assets/Shaders/Skeleton.shader
  3. 4 0
      spine-unity/Assets/examples/Unity 4.meta

+ 13 - 0
spine-unity/Assets/Plugins/Spine/SkeletonComponent.cs

@@ -39,6 +39,7 @@ public class SkeletonComponent : MonoBehaviour {
 	public Spine.AnimationState state;
 	private Mesh mesh;
 	private Vector3[] vertices;
+	private Color[] colors;
 	private Vector2[] uvs;
 	private int[] triangles;
 	private int quadCount;
@@ -117,6 +118,7 @@ public class SkeletonComponent : MonoBehaviour {
 		if (quadCount != this.quadCount) {
 			this.quadCount = quadCount;
 			vertices = new Vector3[quadCount * 4];
+			colors = new Color[quadCount * 4];
 			uvs = new Vector2[quadCount * 4];
 			triangles = new int[quadCount * 6];
 			mesh.Clear();
@@ -124,6 +126,7 @@ public class SkeletonComponent : MonoBehaviour {
 
 		// Setup mesh.
 		int quadIndex = 0;
+		Color color = new Color();
 		for (int i = 0, n = drawOrder.Count; i < n; i++) {
 			Slot slot = drawOrder[i];
 			Attachment attachment = slot.Attachment;
@@ -138,6 +141,15 @@ public class SkeletonComponent : MonoBehaviour {
 				vertices[vertexIndex + 2] = new Vector3(regionVertices[RegionAttachment.X2], regionVertices[RegionAttachment.Y2], 0);
 				vertices[vertexIndex + 3] = new Vector3(regionVertices[RegionAttachment.X3], regionVertices[RegionAttachment.Y3], 0);
 				
+				color.r = skeleton.R * slot.R;
+				color.g = skeleton.G * slot.G;
+				color.b = skeleton.B * slot.B;
+				color.a = skeleton.A * slot.A;
+				colors[vertexIndex] = color;
+				colors[vertexIndex + 1] = color;
+				colors[vertexIndex + 2] = color;
+				colors[vertexIndex + 3] = color;
+
 				float[] regionUVs = regionAttachment.UVs;
 				uvs[vertexIndex] = new Vector2(regionUVs[RegionAttachment.X1], 1 - regionUVs[RegionAttachment.Y1]);
 				uvs[vertexIndex + 1] = new Vector2(regionUVs[RegionAttachment.X4], 1 - regionUVs[RegionAttachment.Y4]);
@@ -156,6 +168,7 @@ public class SkeletonComponent : MonoBehaviour {
 			}
 		}
 		mesh.vertices = vertices;
+		mesh.colors = colors;
 		mesh.uv = uvs;
 		mesh.triangles = triangles;
 

+ 2 - 1
spine-unity/Assets/Shaders/Skeleton.shader

@@ -9,8 +9,9 @@ Shader "Skeleton" {
 		ZWrite Off
 		Blend One OneMinusSrcAlpha
         Pass {
+        	ColorMaterial AmbientAndDiffuse
             SetTexture [_MainTex] {
-            	combine texture
+            	combine texture * primary
             }
         }
     }

+ 4 - 0
spine-unity/Assets/examples/Unity 4.meta

@@ -0,0 +1,4 @@
+fileFormatVersion: 2
+guid: c42e48410176c3b43ac8ba8fbb1256d2
+DefaultImporter:
+  userData: