Merge branch '4.0' into 4.1-beta

This commit is contained in:
Harald Csaszar 2021-11-03 19:52:46 +01:00
commit f2cf39cfb6
16 changed files with 55 additions and 44 deletions

View File

@ -198,10 +198,10 @@ float SkeletonBounds::getHeight() {
} }
void SkeletonBounds::aabbCompute() { void SkeletonBounds::aabbCompute() {
float minX = FLT_MIN; float minX = FLT_MAX;
float minY = FLT_MIN; float minY = FLT_MAX;
float maxX = FLT_MAX; float maxX = FLT_MIN;
float maxY = FLT_MAX; float maxY = FLT_MIN;
for (size_t i = 0, n = _polygons.size(); i < n; ++i) { for (size_t i = 0, n = _polygons.size(); i < n; ++i) {
spine::Polygon *polygon = _polygons[i]; spine::Polygon *polygon = _polygons[i];

View File

@ -53,8 +53,8 @@ namespace Spine.Unity.Examples {
#if UNITY_EDITOR #if UNITY_EDITOR
void OnValidate () { void OnValidate () {
if (Application.isPlaying) return; if (Application.isPlaying) return;
spineComponent = spineComponent ?? GetComponent<ISkeletonAnimation>(); if (spineComponent == null) spineComponent = GetComponent<ISkeletonAnimation>();
if (spineComponent == null) return; if (spineComponent.IsNullOrDestroyed()) return;
if (bone != null) bone.SetToSetupPose(); if (bone != null) bone.SetToSetupPose();
OverrideLocal(spineComponent); OverrideLocal(spineComponent);
} }

View File

@ -29,7 +29,7 @@
// Contributed by: Mitch Thompson // Contributed by: Mitch Thompson
#if UNITY_2019_2_OR_NEWER #if UNITY_2019_2 || UNITY_2019_3 || UNITY_2019_4 || UNITY_2020_1 || UNITY_2020_2 // note: 2020.3+ uses old bahavior again
#define HINGE_JOINT_NEW_BEHAVIOUR #define HINGE_JOINT_NEW_BEHAVIOUR
#endif #endif
@ -42,7 +42,7 @@ namespace Spine.Unity.Examples {
public class SkeletonRagdoll2D : MonoBehaviour { public class SkeletonRagdoll2D : MonoBehaviour {
static Transform parentSpaceHelper; static Transform parentSpaceHelper;
#region Inspector #region Inspector
[Header("Hierarchy")] [Header("Hierarchy")]
[SpineBone] [SpineBone]
public string startingBoneName = ""; public string startingBoneName = "";
@ -72,7 +72,7 @@ namespace Spine.Unity.Examples {
[Range(0, 1)] [Range(0, 1)]
public float mix = 1; public float mix = 1;
public bool oldRagdollBehaviour = false; public bool oldRagdollBehaviour = false;
#endregion #endregion
ISkeletonAnimation targetSkeletonComponent; ISkeletonAnimation targetSkeletonComponent;
Skeleton skeleton; Skeleton skeleton;
@ -110,7 +110,7 @@ namespace Spine.Unity.Examples {
} }
} }
#region API #region API
public Rigidbody2D[] RigidbodyArray { public Rigidbody2D[] RigidbodyArray {
get { get {
if (!isActive) if (!isActive)
@ -299,7 +299,7 @@ namespace Spine.Unity.Examples {
var bone = skeleton.FindBone(boneName); var bone = skeleton.FindBone(boneName);
return (bone != null && boneTable.ContainsKey(bone)) ? boneTable[bone].GetComponent<Rigidbody2D>() : null; return (bone != null && boneTable.ContainsKey(bone)) ? boneTable[bone].GetComponent<Rigidbody2D>() : null;
} }
#endregion #endregion
/// <summary>Generates the ragdoll simulation's Transform and joint setup.</summary> /// <summary>Generates the ragdoll simulation's Transform and joint setup.</summary>
void RecursivelyCreateBoneProxies (Bone b) { void RecursivelyCreateBoneProxies (Bone b) {

View File

@ -48,9 +48,11 @@ namespace Spine.Unity.Prototyping {
IAnimationStateComponent animationStateComponent; IAnimationStateComponent animationStateComponent;
void Start () { void Start () {
skeletonComponent = skeletonComponent ?? GetComponent<ISkeletonComponent>(); if (skeletonComponent == null)
skeletonComponent = GetComponent<ISkeletonComponent>();
if (skeletonComponent == null) return; if (skeletonComponent == null) return;
animationStateComponent = animationStateComponent ?? skeletonComponent as IAnimationStateComponent; if (animationStateComponent == null)
animationStateComponent = skeletonComponent as IAnimationStateComponent;
if (animationStateComponent == null) return; if (animationStateComponent == null) return;
var skeleton = skeletonComponent.Skeleton; var skeleton = skeletonComponent.Skeleton;
if (skeleton == null) return; if (skeleton == null) return;
@ -66,8 +68,8 @@ namespace Spine.Unity.Prototyping {
} }
void OnDestroy () { void OnDestroy () {
animationStateComponent = animationStateComponent ?? GetComponent<IAnimationStateComponent>(); if (animationStateComponent == null) animationStateComponent = GetComponent<IAnimationStateComponent>();
if (animationStateComponent == null) return; if (animationStateComponent.IsNullOrDestroyed()) return;
var state = animationStateComponent.AnimationState; var state = animationStateComponent.AnimationState;
foreach (var ep in events) { foreach (var ep in events) {

View File

@ -39,8 +39,16 @@ namespace Spine.Unity {
public delegate void UpdateBonesDelegate (ISkeletonAnimation animated); public delegate void UpdateBonesDelegate (ISkeletonAnimation animated);
public interface ISpineComponent { }
public static class ISpineComponentExtensions {
public static bool IsNullOrDestroyed (this ISpineComponent component) {
if (component == null) return true;
return (UnityEngine.Object)component == null;
}
}
/// <summary>A Spine-Unity Component that animates a Skeleton but not necessarily with a Spine.AnimationState.</summary> /// <summary>A Spine-Unity Component that animates a Skeleton but not necessarily with a Spine.AnimationState.</summary>
public interface ISkeletonAnimation { public interface ISkeletonAnimation : ISpineComponent {
event UpdateBonesDelegate UpdateLocal; event UpdateBonesDelegate UpdateLocal;
event UpdateBonesDelegate UpdateWorld; event UpdateBonesDelegate UpdateWorld;
event UpdateBonesDelegate UpdateComplete; event UpdateBonesDelegate UpdateComplete;
@ -48,13 +56,13 @@ namespace Spine.Unity {
} }
/// <summary>Holds a reference to a SkeletonDataAsset.</summary> /// <summary>Holds a reference to a SkeletonDataAsset.</summary>
public interface IHasSkeletonDataAsset { public interface IHasSkeletonDataAsset : ISpineComponent {
/// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary> /// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary>
SkeletonDataAsset SkeletonDataAsset { get; } SkeletonDataAsset SkeletonDataAsset { get; }
} }
/// <summary>A Spine-Unity Component that manages a Spine.Skeleton instance, instantiated from a SkeletonDataAsset.</summary> /// <summary>A Spine-Unity Component that manages a Spine.Skeleton instance, instantiated from a SkeletonDataAsset.</summary>
public interface ISkeletonComponent { public interface ISkeletonComponent : ISpineComponent {
/// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary> /// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary>
//[System.Obsolete] //[System.Obsolete]
SkeletonDataAsset SkeletonDataAsset { get; } SkeletonDataAsset SkeletonDataAsset { get; }
@ -64,18 +72,18 @@ namespace Spine.Unity {
} }
/// <summary>A Spine-Unity Component that uses a Spine.AnimationState to animate its skeleton.</summary> /// <summary>A Spine-Unity Component that uses a Spine.AnimationState to animate its skeleton.</summary>
public interface IAnimationStateComponent { public interface IAnimationStateComponent : ISpineComponent {
/// <summary>Gets the Spine.AnimationState of the animated Spine Component. This is equivalent to SkeletonAnimation.state.</summary> /// <summary>Gets the Spine.AnimationState of the animated Spine Component. This is equivalent to SkeletonAnimation.state.</summary>
AnimationState AnimationState { get; } AnimationState AnimationState { get; }
} }
/// <summary>A Spine-Unity Component that holds a reference to a SkeletonRenderer.</summary> /// <summary>A Spine-Unity Component that holds a reference to a SkeletonRenderer.</summary>
public interface IHasSkeletonRenderer { public interface IHasSkeletonRenderer : ISpineComponent {
SkeletonRenderer SkeletonRenderer { get; } SkeletonRenderer SkeletonRenderer { get; }
} }
/// <summary>A Spine-Unity Component that holds a reference to an ISkeletonComponent.</summary> /// <summary>A Spine-Unity Component that holds a reference to an ISkeletonComponent.</summary>
public interface IHasSkeletonComponent { public interface IHasSkeletonComponent : ISpineComponent {
ISkeletonComponent SkeletonComponent { get; } ISkeletonComponent SkeletonComponent { get; }
} }
} }

View File

@ -99,7 +99,6 @@ Shader "Spine/Sprite/Pixel Lit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fog #pragma multi_compile_fog
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment fragBase #pragma fragment fragBase
@ -134,7 +133,6 @@ Shader "Spine/Sprite/Pixel Lit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fog #pragma multi_compile_fog
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment fragAdd #pragma fragment fragAdd
@ -158,7 +156,6 @@ Shader "Spine/Sprite/Pixel Lit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster #pragma multi_compile_shadowcaster
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag

View File

@ -69,7 +69,6 @@ Shader "Spine/Sprite/Unlit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fog #pragma multi_compile_fog
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
@ -93,7 +92,6 @@ Shader "Spine/Sprite/Unlit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster #pragma multi_compile_shadowcaster
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag

View File

@ -99,7 +99,6 @@ Shader "Spine/Sprite/Vertex Lit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fog #pragma multi_compile_fog
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag
@ -123,7 +122,6 @@ Shader "Spine/Sprite/Vertex Lit"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster #pragma multi_compile_shadowcaster
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma vertex vert #pragma vertex vert
#pragma fragment frag #pragma fragment frag

View File

@ -75,7 +75,7 @@ namespace Spine.Unity.Playables {
} }
protected void HandlePause (Playable playable) { protected void HandlePause (Playable playable) {
if (animationStateComponent == null) return; if (animationStateComponent.IsNullOrDestroyed()) return;
TrackEntry current = animationStateComponent.AnimationState.GetCurrent(trackIndex); TrackEntry current = animationStateComponent.AnimationState.GetCurrent(trackIndex);
if (current != null && current == timelineStartedTrackEntry) { if (current != null && current == timelineStartedTrackEntry) {
@ -86,7 +86,7 @@ namespace Spine.Unity.Playables {
} }
protected void HandleResume (Playable playable) { protected void HandleResume (Playable playable) {
if (animationStateComponent == null) return; if (animationStateComponent.IsNullOrDestroyed()) return;
TrackEntry current = animationStateComponent.AnimationState.GetCurrent(trackIndex); TrackEntry current = animationStateComponent.AnimationState.GetCurrent(trackIndex);
if (current != null && current == pausedTrackEntry) { if (current != null && current == pausedTrackEntry) {
@ -95,7 +95,7 @@ namespace Spine.Unity.Playables {
} }
protected void HandleClipEnd () { protected void HandleClipEnd () {
if (animationStateComponent == null) return; if (animationStateComponent.IsNullOrDestroyed()) return;
var state = animationStateComponent.AnimationState; var state = animationStateComponent.AnimationState;
if (endAtClipEnd && if (endAtClipEnd &&
@ -116,7 +116,7 @@ namespace Spine.Unity.Playables {
var skeletonGraphic = playerData as SkeletonGraphic; var skeletonGraphic = playerData as SkeletonGraphic;
animationStateComponent = playerData as IAnimationStateComponent; animationStateComponent = playerData as IAnimationStateComponent;
var skeletonComponent = playerData as ISkeletonComponent; var skeletonComponent = playerData as ISkeletonComponent;
if (animationStateComponent == null || skeletonComponent == null) return; if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null) return;
var skeleton = skeletonComponent.Skeleton; var skeleton = skeletonComponent.Skeleton;
var state = animationStateComponent.AnimationState; var state = animationStateComponent.AnimationState;
@ -226,7 +226,7 @@ namespace Spine.Unity.Playables {
SkeletonAnimation skeletonAnimation, SkeletonGraphic skeletonGraphic) { SkeletonAnimation skeletonAnimation, SkeletonGraphic skeletonGraphic) {
if (Application.isPlaying) return; if (Application.isPlaying) return;
if (skeletonComponent == null || animationStateComponent == null) return; if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null) return;
int inputCount = playable.GetInputCount(); int inputCount = playable.GetInputCount();
int lastNonZeroWeightTrack = -1; int lastNonZeroWeightTrack = -1;

View File

@ -112,7 +112,18 @@
return main; return main;
#endif #endif
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv); half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
#if UNITY_VERSION < 202120
return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb, main.a); return half4(CombinedShapeLightShared(half4(main.rgb, 1), mask, i.lightingUV).rgb, main.a);
#else
SurfaceData2D surfaceData;
InputData2D inputData;
surfaceData.albedo = main.rgb;
surfaceData.alpha = 1;
surfaceData.mask = mask;
inputData.uv = i.uv;
inputData.lightingUV = i.lightingUV;
return half4(CombinedShapeLightShared(surfaceData, inputData).rgb, main.a);
#endif
} }
ENDHLSL ENDHLSL

View File

@ -88,7 +88,6 @@ Shader "Universal Render Pipeline/2D/Spine/Sprite"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
//-------------------------------------- //--------------------------------------
// GPU Instancing // GPU Instancing
@ -132,7 +131,6 @@ Shader "Universal Render Pipeline/2D/Spine/Sprite"
#pragma shader_feature _ALPHA_CLIP #pragma shader_feature _ALPHA_CLIP
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
//-------------------------------------- //--------------------------------------
// GPU Instancing // GPU Instancing

View File

@ -1,2 +1,3 @@
// Adapt this path accordingly if you have unpacked the Spine directory to another location. // Adapt this path accordingly if you have unpacked the Spine directory to another location.
#include "Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/ShaderShared.cginc" #include "Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/ShaderShared.cginc"
//#include "Packages/com.esotericsoftware.spine.spine-unity/Runtime/spine-unity/Shaders/Sprite/CGIncludes/ShaderShared.cginc"

View File

@ -1,2 +1,3 @@
// Adapt this path accordingly if you have unpacked the Spine directory to another location. // Adapt this path accordingly if you have unpacked the Spine directory to another location.
#include "Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Common.cginc" #include "Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Common.cginc"
//#include "Packages/com.esotericsoftware.spine.spine-unity/Runtime/spine-unity/Shaders/CGIncludes/Spine-Common.cginc"

View File

@ -1,2 +1,3 @@
// Adapt this path accordingly if you have unpacked the Spine directory to another location. // Adapt this path accordingly if you have unpacked the Spine directory to another location.
#include "Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Outline-Common.cginc" #include "Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Outline-Common.cginc"
//#include "Packages/com.esotericsoftware.spine.spine-unity/Runtime/spine-unity/Shaders/CGIncludes/Spine-Outline-Common.cginc"

View File

@ -1,2 +1,3 @@
// Adapt this path accordingly if you have unpacked the Spine directory to another location. // Adapt this path accordingly if you have unpacked the Spine directory to another location.
#include "Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc" #include "Assets/Spine/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc"
//#include "Packages/com.esotericsoftware.spine.spine-unity/Runtime/spine-unity/Shaders/Sprite/CGIncludes/SpriteLighting.cginc"

View File

@ -99,14 +99,10 @@ Shader "Universal Render Pipeline/Spine/Sprite"
#pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_fog #pragma multi_compile_fog
#pragma multi_compile _ PIXELSNAP_ON #pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
// ------------------------------------- // -------------------------------------
// Universal Pipeline keywords // Universal Pipeline keywords
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile _ MAIN_LIGHT_CALCULATE_SHADOWS
#pragma multi_compile _ REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _SHADOWS_SOFT
@ -116,9 +112,8 @@ Shader "Universal Render Pipeline/Spine/Sprite"
// Unity defined keywords // Unity defined keywords
#pragma multi_compile _ DIRLIGHTMAP_COMBINED #pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile_fog
//-------------------------------------- //--------------------------------------
// GPU Instancing // GPU Instancing
#pragma multi_compile_instancing #pragma multi_compile_instancing