[unity] Use scale instead of flip for SkeletonFlip timeline mixer.

This commit is contained in:
pharan 2018-10-06 02:37:38 +08:00
parent bb73f7d6e4
commit 6e7370f603

View File

@ -38,7 +38,8 @@ using Spine.Unity;
namespace Spine.Unity.Playables { namespace Spine.Unity.Playables {
public class SpineSkeletonFlipMixerBehaviour : PlayableBehaviour { public class SpineSkeletonFlipMixerBehaviour : PlayableBehaviour {
bool defaultFlipX, defaultFlipY; float originalScaleX, originalScaleY;
float baseScaleX, baseScaleY;
SpinePlayableHandleBase playableHandle; SpinePlayableHandleBase playableHandle;
bool m_FirstFrameHappened; bool m_FirstFrameHappened;
@ -52,8 +53,10 @@ namespace Spine.Unity.Playables {
var skeleton = playableHandle.Skeleton; var skeleton = playableHandle.Skeleton;
if (!m_FirstFrameHappened) { if (!m_FirstFrameHappened) {
defaultFlipX = skeleton.FlipX; originalScaleX = skeleton.ScaleX;
defaultFlipY = skeleton.FlipY; originalScaleY = skeleton.ScaleY;
baseScaleX = Mathf.Abs(originalScaleX);
baseScaleY = Mathf.Abs(originalScaleY);
m_FirstFrameHappened = true; m_FirstFrameHappened = true;
} }
@ -71,8 +74,7 @@ namespace Spine.Unity.Playables {
totalWeight += inputWeight; totalWeight += inputWeight;
if (inputWeight > greatestWeight) { if (inputWeight > greatestWeight) {
skeleton.FlipX = input.flipX; SetSkeletonScaleFromFlip(skeleton, input.flipX, input.flipY);
skeleton.FlipY = input.flipY;
greatestWeight = inputWeight; greatestWeight = inputWeight;
} }
@ -81,11 +83,16 @@ namespace Spine.Unity.Playables {
} }
if (currentInputs != 1 && 1f - totalWeight > greatestWeight) { if (currentInputs != 1 && 1f - totalWeight > greatestWeight) {
skeleton.FlipX = defaultFlipX; skeleton.scaleX = originalScaleX;
skeleton.FlipY = defaultFlipY; skeleton.scaleY = originalScaleY;
} }
} }
public void SetSkeletonScaleFromFlip (Skeleton skeleton, bool flipX, bool flipY) {
skeleton.scaleX = flipX ? -baseScaleX : baseScaleX;
skeleton.scaleY = flipY ? -baseScaleY : baseScaleY;
}
public override void OnGraphStop (Playable playable) { public override void OnGraphStop (Playable playable) {
m_FirstFrameHappened = false; m_FirstFrameHappened = false;
@ -93,8 +100,8 @@ namespace Spine.Unity.Playables {
return; return;
var skeleton = playableHandle.Skeleton; var skeleton = playableHandle.Skeleton;
skeleton.FlipX = defaultFlipX; skeleton.scaleX = originalScaleX;
skeleton.FlipY = defaultFlipY; skeleton.scaleY = originalScaleY;
} }
} }