diff --git a/spine-ue4/Content/Maps/example.umap b/spine-ue4/Content/Maps/example.umap index 15d9a8aae..4af6b28c7 100644 Binary files a/spine-ue4/Content/Maps/example.umap and b/spine-ue4/Content/Maps/example.umap differ diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonAnimationComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonAnimationComponent.cpp index 88e579b4d..de407bd8c 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonAnimationComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonAnimationComponent.cpp @@ -5,7 +5,13 @@ void callback(spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) { USpineSkeletonAnimationComponent* component = (USpineSkeletonAnimationComponent*)state->rendererObject; - component->SpineAnimationStartEvent.Broadcast(231); + if (type == SP_ANIMATION_START) { + if (entry->rendererObject) { + UTrackEntry* uEntry = (UTrackEntry*)entry->rendererObject; + component->AnimationStartEvent.Broadcast(uEntry); + uEntry->AnimationStartEvent.Broadcast(uEntry); + } + } } USpineSkeletonAnimationComponent::USpineSkeletonAnimationComponent () { @@ -71,43 +77,43 @@ void USpineSkeletonAnimationComponent::FinishDestroy () { Super::FinishDestroy(); } -UTrackEntry USpineSkeletonAnimationComponent::SetAnimation (int trackIndex, FString animationName, bool loop) { +UTrackEntry* USpineSkeletonAnimationComponent::SetAnimation (int trackIndex, FString animationName, bool loop) { CheckState(); if (state && spSkeletonData_findAnimation(skeleton->data, TCHAR_TO_UTF8(*animationName))) { spTrackEntry* entry = spAnimationState_setAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0); - UTrackEntry* uEnty = NewObject(); - uEntry->entry = entry; + UTrackEntry* uEntry = NewObject(); + uEntry->SetTrackEntry(entry); return uEntry; } else return NewObject(); } -UTrackEntry USpineSkeletonAnimationComponent::AddAnimation (int trackIndex, FString animationName, bool loop, float delay) { +UTrackEntry* USpineSkeletonAnimationComponent::AddAnimation (int trackIndex, FString animationName, bool loop, float delay) { CheckState(); if (state && spSkeletonData_findAnimation(skeleton->data, TCHAR_TO_UTF8(*animationName))) { spTrackEntry* entry = spAnimationState_addAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0, delay); - UTrackEntry* uEnty = NewObject(); - uEntry->entry = entry; + UTrackEntry* uEntry = NewObject(); + uEntry->SetTrackEntry(entry); return uEntry; } else return NewObject(); } -UTrackEntry USpineSkeletonAnimationComponent::SetEmptyAnimation (int trackIndex, float mixDuration) { +UTrackEntry* USpineSkeletonAnimationComponent::SetEmptyAnimation (int trackIndex, float mixDuration) { CheckState(); if (state) { spTrackEntry* entry = spAnimationState_setEmptyAnimation(state, trackIndex, mixDuration); - UTrackEntry* uEnty = NewObject(); - uEntry->entry = entry; + UTrackEntry* uEntry = NewObject(); + uEntry->SetTrackEntry(entry); return uEntry; } else return NewObject(); } -UTrackEntry USpineSkeletonAnimationComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) { +UTrackEntry* USpineSkeletonAnimationComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) { CheckState(); if (state) { spTrackEntry* entry = spAnimationState_addEmptyAnimation(state, trackIndex, mixDuration, delay); - UTrackEntry* uEnty = NewObject(); - uEntry->entry = entry; + UTrackEntry* uEntry = NewObject(); + uEntry->SetTrackEntry(entry); return uEntry; } else return NewObject(); } diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonAnimationComponent.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonAnimationComponent.h index 57f27509f..22b2c50cb 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonAnimationComponent.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonAnimationComponent.h @@ -7,6 +7,8 @@ #include "spine/spine.h" #include "SpineSkeletonAnimationComponent.generated.h" +DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpineAnimationStartEvent, UTrackEntry*, entry); + UCLASS(ClassGroup=(Spine), meta=(BlueprintSpawnableComponent), BlueprintType) class SPINEPLUGIN_API UTrackEntry: public UObject { GENERATED_BODY () @@ -16,12 +18,18 @@ public: UTrackEntry () { } spTrackEntry* entry = nullptr; + + void SetTrackEntry(spTrackEntry* entry) { + this->entry = entry; + entry->rendererObject = (void*)this; + } UFUNCTION(BlueprintCallable, Category="Components|Spine") - int GetTrackIndex() { return entry ? entry->trackIndex : 0; } -}; + int GetTrackIndex() { return entry ? entry->trackIndex : 0; } -DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSpineAnimationStartEvent, UTrackEntry*, entry); + UPROPERTY(BlueprintAssignable, Category = "Components|Spine") + FSpineAnimationStartEvent AnimationStartEvent; +}; class USpineAtlasAsset; UCLASS(ClassGroup=(Spine), meta=(BlueprintSpawnableComponent))