Merge branch '3.6' into 3.7-beta

This commit is contained in:
badlogic 2017-07-04 10:33:27 +02:00
commit 6137da3eb2
18 changed files with 550 additions and 484 deletions

View File

@ -851,22 +851,35 @@ void _spDeformTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton,
slot->attachmentVerticesCapacity = vertexCount; slot->attachmentVerticesCapacity = vertexCount;
} }
} }
if (slot->attachmentVerticesCount != vertexCount && pose != SP_MIX_POSE_SETUP) alpha = 1; /* Don't mix from uninitialized slot vertices. */
slot->attachmentVerticesCount = vertexCount; slot->attachmentVerticesCount = vertexCount;
frameVertices = self->frameVertices; frameVertices = self->frameVertices;
vertices = slot->attachmentVertices; vertices = slot->attachmentVertices;
if (time < frames[0]) { /* Time is before first frame. */ if (time < frames[0]) { /* Time is before first frame. */
spVertexAttachment* vertexAttachment = SUB_CAST(spVertexAttachment, slot->attachment);
switch (pose) { switch (pose) {
case SP_MIX_POSE_SETUP: case SP_MIX_POSE_SETUP:
slot->attachmentVerticesCount = 0; if (!vertexAttachment->bones) {
memcpy(vertices, vertexAttachment->vertices, vertexCount * sizeof(float));
} else {
for (i = 0; i < vertexCount; i++) vertices[i] = 0;
}
return; return;
case SP_MIX_POSE_CURRENT: case SP_MIX_POSE_CURRENT:
case SP_MIX_POSE_CURRENT_LAYERED: /* to appease compiler */ case SP_MIX_POSE_CURRENT_LAYERED: /* to appease compiler */
alpha = 1 - alpha; if (alpha == 1) break;
for (i = 0; i < vertexCount; i++) if (!vertexAttachment->bones) {
vertices[i] *= alpha; float* setupVertices = vertexAttachment->vertices;
for (i = 0; i < vertexCount; i++) {
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
}
} else {
alpha = 1 - alpha;
for (i = 0; i < vertexCount; i++) {
vertices[i] *= alpha;
}
}
} }
return; return;
} }

View File

@ -101,6 +101,7 @@ namespace Spine.Unity.Editor {
} }
position = EditorGUI.PrefixLabel(position, label); position = EditorGUI.PrefixLabel(position, label);
var image = Icon; var image = Icon;
var propertyStringValue = (property.hasMultipleDifferentValues) ? SpineInspectorUtility.EmDash : property.stringValue; var propertyStringValue = (property.hasMultipleDifferentValues) ? SpineInspectorUtility.EmDash : property.stringValue;
if (GUI.Button(position, string.IsNullOrEmpty(propertyStringValue) ? NoneLabel(image) : SpineInspectorUtility.TempContent(propertyStringValue, image), EditorStyles.popup)) if (GUI.Button(position, string.IsNullOrEmpty(propertyStringValue) ? NoneLabel(image) : SpineInspectorUtility.TempContent(propertyStringValue, image), EditorStyles.popup))

View File

@ -79,7 +79,7 @@ namespace Spine.Unity {
/// <summary> /// <summary>
/// Initialize and instantiate the BoundingBoxFollower colliders. This is method checks if the BoundingBoxFollower has already been initialized for the skeleton instance and slotName and prevents overwriting unless it detects a new setup.</summary> /// Initialize and instantiate the BoundingBoxFollower colliders. This is method checks if the BoundingBoxFollower has already been initialized for the skeleton instance and slotName and prevents overwriting unless it detects a new setup.</summary>
public void Initialize () { public void Initialize (bool overwrite = false) {
if (skeletonRenderer == null) if (skeletonRenderer == null)
return; return;
@ -89,7 +89,9 @@ namespace Spine.Unity {
return; return;
// Don't reinitialize if the setup did not change. // Don't reinitialize if the setup did not change.
if (colliderTable.Count > 0 && slot != null // Slot is set and colliders already populated. if (!overwrite
&&
colliderTable.Count > 0 && slot != null // Slot is set and colliders already populated.
&& &&
skeletonRenderer.skeleton == slot.Skeleton // Skeleton object did not change. skeletonRenderer.skeleton == slot.Skeleton // Skeleton object did not change.
&& &&
@ -110,27 +112,10 @@ namespace Spine.Unity {
} }
if (this.gameObject.activeInHierarchy) { if (this.gameObject.activeInHierarchy) {
foreach (var skin in skeleton.Data.Skins) { foreach (var skin in skeleton.Data.Skins)
var attachmentNames = new List<string>(); AddSkin(skin, skeleton, slotIndex);
skin.FindNamesForSlot(slotIndex, attachmentNames);
foreach (var skinKey in attachmentNames) { AddSkin(skeleton.skin, skeleton, slotIndex);
var attachment = skin.GetAttachment(slotIndex, skinKey);
var boundingBoxAttachment = attachment as BoundingBoxAttachment;
if (BoundingBoxFollower.DebugMessages && attachment != null && boundingBoxAttachment == null)
Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments: " + slotName);
if (boundingBoxAttachment != null) {
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, gameObject, isTrigger);
bbCollider.enabled = false;
bbCollider.hideFlags = HideFlags.NotEditable;
bbCollider.isTrigger = IsTrigger;
colliderTable.Add(boundingBoxAttachment, bbCollider);
nameTable.Add(boundingBoxAttachment, skinKey);
}
}
}
} }
if (BoundingBoxFollower.DebugMessages) { if (BoundingBoxFollower.DebugMessages) {
@ -144,6 +129,28 @@ namespace Spine.Unity {
} }
} }
void AddSkin (Skin skin, Skeleton skeleton, int slotIndex) {
var attachmentNames = new List<string>();
skin.FindNamesForSlot(slotIndex, attachmentNames);
foreach (var skinKey in attachmentNames) {
var attachment = skin.GetAttachment(slotIndex, skinKey);
var boundingBoxAttachment = attachment as BoundingBoxAttachment;
if (BoundingBoxFollower.DebugMessages && attachment != null && boundingBoxAttachment == null)
Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments: " + slotName);
if (boundingBoxAttachment != null) {
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, gameObject, isTrigger);
bbCollider.enabled = false;
bbCollider.hideFlags = HideFlags.NotEditable;
bbCollider.isTrigger = IsTrigger;
colliderTable.Add(boundingBoxAttachment, bbCollider);
nameTable.Add(boundingBoxAttachment, skinKey);
}
}
}
void OnDisable () { void OnDisable () {
if (clearStateOnDisable) if (clearStateOnDisable)
ClearState(); ClearState();
@ -206,13 +213,23 @@ namespace Spine.Unity {
if (bbAttachment == null) { if (bbAttachment == null) {
currentCollider = null; currentCollider = null;
currentAttachment = null;
currentAttachmentName = null;
} else { } else {
currentCollider = colliderTable[bbAttachment]; PolygonCollider2D foundCollider;
currentCollider.enabled = true; colliderTable.TryGetValue(bbAttachment, out foundCollider);
if (foundCollider != null) {
currentCollider = foundCollider;
currentCollider.enabled = true;
currentAttachment = bbAttachment;
currentAttachmentName = nameTable[bbAttachment];
} else {
currentCollider = null;
currentAttachment = bbAttachment;
currentAttachmentName = null;
if (BoundingBoxFollower.DebugMessages) Debug.LogFormat("Collider for BoundingBoxAttachment named '{0}' was not initialized. It is possibly from a new skin. currentAttachmentName will be null. You may need to call BoundingBoxFollower.Initialize(overwrite: true);", bbAttachment.Name);
}
} }
currentAttachment = bbAttachment;
currentAttachmentName = currentAttachment == null ? null : nameTable[bbAttachment];
} }
} }

View File

@ -26,7 +26,7 @@ struct VertexInput
#if defined(_NORMALMAP) #if defined(_NORMALMAP)
float4 tangent : TANGENT; float4 tangent : TANGENT;
#endif // _NORMALMAP #endif // _NORMALMAP
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
//////////////////////////////////////// ////////////////////////////////////////

View File

@ -12,7 +12,7 @@ struct VertexInput
float4 vertex : POSITION; float4 vertex : POSITION;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
fixed4 color : COLOR; fixed4 color : COLOR;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
struct VertexOutput struct VertexOutput

View File

@ -286,7 +286,7 @@ struct appdata {
float4 vertex : POSITION; float4 vertex : POSITION;
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -327,7 +327,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -370,7 +370,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;

View File

@ -283,7 +283,7 @@ struct appdata {
float4 vertex : POSITION; float4 vertex : POSITION;
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -324,7 +324,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -367,7 +367,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;

View File

@ -286,7 +286,7 @@ struct appdata {
float4 vertex : POSITION; float4 vertex : POSITION;
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -327,7 +327,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;
@ -370,7 +370,7 @@ struct appdata {
float3 normal : NORMAL; float3 normal : NORMAL;
fixed4 color : COLOR; fixed4 color : COLOR;
float4 texcoord : TEXCOORD0; float4 texcoord : TEXCOORD0;
UNITY_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
v2f vert( appdata v ) { v2f vert( appdata v ) {
v2f o; v2f o;

View File

@ -1,5 +1,3 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
#ifndef SHADER_SHARED_INCLUDED #ifndef SHADER_SHARED_INCLUDED
#define SHADER_SHARED_INCLUDED #define SHADER_SHARED_INCLUDED

View File

@ -1,5 +1,3 @@
// Upgrade NOTE: replaced 'UNITY_INSTANCE_ID' with 'UNITY_VERTEX_INPUT_INSTANCE_ID'
Shader "Hidden/Internal-SpriteDepthNormalsTexture" { Shader "Hidden/Internal-SpriteDepthNormalsTexture" {
// Use this shader to render a DepthNormals texture for a camera with correct sprite normals (using camera.RenderWithShader) // Use this shader to render a DepthNormals texture for a camera with correct sprite normals (using camera.RenderWithShader)

View File

@ -324,7 +324,7 @@ VertexOutput vert(VertexInput input)
output.color = calculateVertexColor(input.color); output.color = calculateVertexColor(input.color);
output.texcoord = float3(calculateTextureCoord(input.texcoord), 0); output.texcoord = float3(calculateTextureCoord(input.texcoord), 0);
float3 viewPos = mul(UNITY_MATRIX_MV, input.vertex); float3 viewPos = UnityObjectToViewPos(input.vertex);
#if defined(PER_PIXEL_LIGHTING) #if defined(PER_PIXEL_LIGHTING)

View File

@ -15,6 +15,8 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
_StencilReadMask ("Stencil Read Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15 _ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
} }
SubShader SubShader
@ -50,9 +52,11 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#include "UnityCG.cginc" #include "UnityCG.cginc"
fixed4 _Color; #include "UnityUI.cginc"
fixed4 _Black;
#pragma multi_compile __ UNITY_UI_ALPHACLIP
struct VertexInput { struct VertexInput {
float4 vertex : POSITION; float4 vertex : POSITION;
@ -60,6 +64,7 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
float2 texcoord : TEXCOORD0; float2 texcoord : TEXCOORD0;
float2 uv1 : TEXCOORD1; float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2; float2 uv2 : TEXCOORD2;
UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
struct VertexOutput { struct VertexOutput {
@ -68,17 +73,24 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
half2 texcoord : TEXCOORD0; half2 texcoord : TEXCOORD0;
float2 uv1 : TEXCOORD1; float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2; float2 uv2 : TEXCOORD2;
float4 worldPosition : TEXCOORD3;
UNITY_VERTEX_OUTPUT_STEREO
}; };
fixed4 _Color;
fixed4 _Black;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
VertexOutput vert (VertexInput IN) { VertexOutput vert (VertexInput IN) {
VertexOutput OUT; VertexOutput OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET UNITY_SETUP_INSTANCE_ID(IN);
OUT.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
#endif
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor. OUT.color = IN.color * float4(_Color.rgb * _Color.a, _Color.a); // Combine a PMA version of _Color with vertexColor.
OUT.uv1 = IN.uv1; OUT.uv1 = IN.uv1;
@ -90,8 +102,14 @@ Shader "Spine/SkeletonGraphic Tint Black (Premultiply Alpha)"
fixed4 frag (VertexOutput IN) : SV_Target fixed4 frag (VertexOutput IN) : SV_Target
{ {
float4 texColor = tex2D(_MainTex, IN.texcoord); half4 texColor = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd);
//clip(color.a - 0.01);
texColor.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP
clip (texColor.a - 0.001);
#endif
return (texColor * IN.color) + float4(((1-texColor.rgb) * texColor.a * (_Black.rgb + float3(IN.uv1.r, IN.uv1.g, IN.uv2.r))), 0); return (texColor * IN.color) + float4(((1-texColor.rgb) * texColor.a * (_Black.rgb + float3(IN.uv1.r, IN.uv1.g, IN.uv2.r))), 0);
} }
ENDCG ENDCG

View File

@ -1,4 +1,4 @@
// This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" to allow Unity UI stencil masking. // This is a premultiply-alpha adaptation of the built-in Unity shader "UI/Default" in Unity 5.6.2 to allow Unity UI stencil masking.
Shader "Spine/SkeletonGraphic (Premultiply Alpha)" Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
{ {
@ -14,6 +14,8 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
_StencilReadMask ("Stencil Read Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15 _ColorMask ("Color Mask", Float) = 15
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
} }
SubShader SubShader
@ -49,25 +51,40 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
CGPROGRAM CGPROGRAM
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc" #include "UnityCG.cginc"
fixed4 _Color; #include "UnityUI.cginc"
#pragma multi_compile __ UNITY_UI_ALPHACLIP
struct VertexInput { struct VertexInput {
float4 vertex : POSITION; float4 vertex : POSITION;
float4 color : COLOR; float4 color : COLOR;
float2 texcoord : TEXCOORD0; float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
}; };
struct VertexOutput { struct VertexOutput {
float4 vertex : SV_POSITION; float4 vertex : SV_POSITION;
fixed4 color : COLOR; fixed4 color : COLOR;
half2 texcoord : TEXCOORD0; half2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
}; };
fixed4 _Color;
fixed4 _TextureSampleAdd;
float4 _ClipRect;
VertexOutput vert (VertexInput IN) { VertexOutput vert (VertexInput IN) {
VertexOutput OUT; VertexOutput OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.worldPosition = IN.vertex;
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
OUT.texcoord = IN.texcoord; OUT.texcoord = IN.texcoord;
#ifdef UNITY_HALF_TEXEL_OFFSET #ifdef UNITY_HALF_TEXEL_OFFSET
@ -82,8 +99,14 @@ Shader "Spine/SkeletonGraphic (Premultiply Alpha)"
fixed4 frag (VertexOutput IN) : SV_Target fixed4 frag (VertexOutput IN) : SV_Target
{ {
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color; half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
//clip(color.a - 0.01);
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
#ifdef UNITY_UI_ALPHACLIP
clip (color.a - 0.001);
#endif
return color; return color;
} }
ENDCG ENDCG

View File

@ -1,5 +1,3 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/Spine/Bones" { Shader "Hidden/Spine/Bones" {
Properties { Properties {
_Color ("Color", Color) = (0.5,0.5,0.5,0.5) _Color ("Color", Color) = (0.5,0.5,0.5,0.5)

View File

@ -126,7 +126,7 @@ namespace Spine.Unity {
} }
#endregion #endregion
protected override void ClearState () { public override void ClearState () {
base.ClearState(); base.ClearState();
if (state != null) state.ClearTracks(); if (state != null) state.ClearTracks();
} }

View File

@ -149,7 +149,7 @@ namespace Spine.Unity {
rendererBuffers.Dispose(); rendererBuffers.Dispose();
} }
protected virtual void ClearState () { public virtual void ClearState () {
meshFilter.sharedMesh = null; meshFilter.sharedMesh = null;
currentInstructions.Clear(); currentInstructions.Clear();
if (skeleton != null) skeleton.SetToSetupPose(); if (skeleton != null) skeleton.SetToSetupPose();