[ue4] Fixed up PR #1251.

This commit is contained in:
badlogic 2019-01-23 16:42:38 +01:00
commit 8fe981cfe1
6 changed files with 52 additions and 6 deletions

View File

@ -78,6 +78,7 @@ USpineSkeletonAnimationComponent::USpineSkeletonAnimationComponent () {
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
bTickInEditor = true; bTickInEditor = true;
bAutoActivate = true; bAutoActivate = true;
bAutoPlaying = true;
} }
void USpineSkeletonAnimationComponent::BeginPlay() { void USpineSkeletonAnimationComponent::BeginPlay() {
@ -94,7 +95,7 @@ void USpineSkeletonAnimationComponent::TickComponent(float DeltaTime, ELevelTick
void USpineSkeletonAnimationComponent::InternalTick(float DeltaTime, bool CallDelegates) { void USpineSkeletonAnimationComponent::InternalTick(float DeltaTime, bool CallDelegates) {
CheckState(); CheckState();
if (state) { if (state && bAutoPlaying) {
state->update(DeltaTime); state->update(DeltaTime);
state->apply(*skeleton); state->apply(*skeleton);
if (CallDelegates) BeforeUpdateWorldTransform.Broadcast(this); if (CallDelegates) BeforeUpdateWorldTransform.Broadcast(this);
@ -160,6 +161,36 @@ void USpineSkeletonAnimationComponent::FinishDestroy () {
Super::FinishDestroy(); Super::FinishDestroy();
} }
void USpineSkeletonAnimationComponent::SetAutoPlay(bool bInAutoPlays)
{
bAutoPlaying = bInAutoPlays;
}
void USpineSkeletonAnimationComponent::SetPlaybackTime(float InPlaybackTime, bool bCallDelegates)
{
CheckState();
if (state && state->getCurrent(0)) {
spine::Animation* CurrentAnimation = state->getCurrent(0)->getAnimation();
const float CurrentTime = state->getCurrent(0)->getTrackTime();
InPlaybackTime = FMath::Clamp(InPlaybackTime, 0.0f, CurrentAnimation->getDuration());
const float DeltaTime = InPlaybackTime - CurrentTime;
state->update(DeltaTime);
state->apply(*skeleton);
//Call delegates and perform the world transform
if (bCallDelegates)
{
BeforeUpdateWorldTransform.Broadcast(this);
}
skeleton->updateWorldTransform();
if (bCallDelegates)
{
AfterUpdateWorldTransform.Broadcast(this);
}
}
}
void USpineSkeletonAnimationComponent::SetTimeScale(float timeScale) { void USpineSkeletonAnimationComponent::SetTimeScale(float timeScale) {
CheckState(); CheckState();
if (state) state->setTimeScale(timeScale); if (state) state->setTimeScale(timeScale);

View File

@ -195,6 +195,16 @@ public:
virtual void FinishDestroy () override; virtual void FinishDestroy () override;
//Added functions for manual configuration
/* Manages if this skeleton should update automatically or is paused. */
UFUNCTION(BlueprintCallable, Category="Components|Spine|Animation")
void SetAutoPlay(bool bInAutoPlays);
/* Directly set the time of the current animation, will clamp to animation range. */
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Animation")
void SetPlaybackTime(float InPlaybackTime, bool bCallDelegates = true);
// Blueprint functions // Blueprint functions
UFUNCTION(BlueprintCallable, Category="Components|Spine|Animation") UFUNCTION(BlueprintCallable, Category="Components|Spine|Animation")
void SetTimeScale(float timeScale); void SetTimeScale(float timeScale);
@ -255,4 +265,9 @@ protected:
// in transit within a blueprint // in transit within a blueprint
UPROPERTY() UPROPERTY()
TSet<UTrackEntry*> trackEntries; TSet<UTrackEntry*> trackEntries;
private:
/* If the animation should update automatically. */
UPROPERTY()
bool bAutoPlaying;
}; };