diff --git a/spine-ue4/Content/Maps/example.umap b/spine-ue4/Content/Maps/example.umap index 11ad79945..6b180c935 100644 Binary files a/spine-ue4/Content/Maps/example.umap and b/spine-ue4/Content/Maps/example.umap differ diff --git a/spine-ue4/Content/Raptor_Blueprint.uasset b/spine-ue4/Content/Raptor_Blueprint.uasset new file mode 100644 index 000000000..b639f7fe0 Binary files /dev/null and b/spine-ue4/Content/Raptor_Blueprint.uasset differ diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp index 402718a04..786f4f723 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp @@ -2,6 +2,10 @@ #define LOCTEXT_NAMESPACE "Spine" +void callback(spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) { + USpineSkeletonComponent* component = (USpineSkeletonComponent*)entry->rendererObject; +} + USpineSkeletonComponent::USpineSkeletonComponent () { bWantsBeginPlay = true; PrimaryComponentTick.bCanEverTick = true; @@ -16,25 +20,29 @@ void USpineSkeletonComponent::BeginPlay() { void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + CheckState(); + + if (state) { + spAnimationState_update(state, DeltaTime); + spAnimationState_apply(state, skeleton); + spSkeleton_updateWorldTransform(skeleton); + } +} + +void USpineSkeletonComponent::CheckState () { if (lastAtlas != Atlas || lastData != SkeletonData) { DisposeState(); - + if (Atlas && SkeletonData) { spSkeletonData* data = SkeletonData->GetSkeletonData(Atlas->GetAtlas(false), false); skeleton = spSkeleton_create(data); stateData = spAnimationStateData_create(data); state = spAnimationState_create(stateData); } - + lastAtlas = Atlas; lastData = SkeletonData; } - - if (state) { - spAnimationState_update(state, DeltaTime); - spAnimationState_apply(state, skeleton); - spSkeleton_updateWorldTransform(skeleton); - } } void USpineSkeletonComponent::DisposeState () { @@ -59,37 +67,48 @@ void USpineSkeletonComponent::FinishDestroy () { Super::FinishDestroy(); } -void USpineSkeletonComponent::SetAnimation (int trackIndex, FString animationName, bool loop) { - if (state) { - spAnimationState_setAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0); - } +FTrackEntry USpineSkeletonComponent::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); + return FTrackEntry(entry); + } else return FTrackEntry(); + } -void USpineSkeletonComponent::AddAnimation (int trackIndex, FString animationName, bool loop, float delay) { - if (state) { - spAnimationState_addAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0, delay); - } +FTrackEntry USpineSkeletonComponent::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); + return FTrackEntry(entry); + } else return FTrackEntry(); } -void USpineSkeletonComponent::SetEmptyAnimation (int trackIndex, float mixDuration) { +FTrackEntry USpineSkeletonComponent::SetEmptyAnimation (int trackIndex, float mixDuration) { + CheckState(); if (state) { - spAnimationState_setEmptyAnimation(state, trackIndex, mixDuration); - } + spTrackEntry* entry = spAnimationState_setEmptyAnimation(state, trackIndex, mixDuration); + return FTrackEntry(entry); + } else return FTrackEntry(); } -void USpineSkeletonComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) { +FTrackEntry USpineSkeletonComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) { + CheckState(); if (state) { - spAnimationState_addAnimationByName(state, trackIndex, mixDuration, delay); - } + spTrackEntry* entry = spAnimationState_addEmptyAnimation(state, trackIndex, mixDuration, delay); + return FTrackEntry(entry); + } else return FTrackEntry(); } void USpineSkeletonComponent::ClearTracks () { + CheckState(); if (state) { spAnimationState_clearTracks(state); } } void USpineSkeletonComponent::ClearTrack (int trackIndex) { + CheckState(); if (state) { spAnimationState_clearTrack(state, trackIndex); } diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h index d15024e64..831206ff4 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h @@ -3,12 +3,23 @@ #pragma once #include "Components/ActorComponent.h" +#include "spine/spine.h" #include "SpineSkeletonComponent.generated.h" +USTRUCT(BlueprintType) +struct SPINEPLUGIN_API FTrackEntry { + GENERATED_BODY (); + + FTrackEntry (): entry(0) { } + + FTrackEntry (spTrackEntry* entry) { this->entry = entry; } + + spTrackEntry* entry; +}; + class USpineAtlasAsset; -UCLASS( ClassGroup=(Spine), meta=(BlueprintSpawnableComponent) ) -class SPINEPLUGIN_API USpineSkeletonComponent : public UActorComponent -{ +UCLASS(ClassGroup=(Spine), meta=(BlueprintSpawnableComponent)) +class SPINEPLUGIN_API USpineSkeletonComponent: public UActorComponent { GENERATED_BODY() public: @@ -34,16 +45,16 @@ public: // Blueprint functions UFUNCTION(BlueprintCallable, Category="Components|Spine") - void SetAnimation (int trackIndex, FString animationName, bool loop); + FTrackEntry SetAnimation (int trackIndex, FString animationName, bool loop); UFUNCTION(BlueprintCallable, Category="Components|Spine") - void AddAnimation (int trackIndex, FString animationName, bool loop, float delay); + FTrackEntry AddAnimation (int trackIndex, FString animationName, bool loop, float delay); UFUNCTION(BlueprintCallable, Category="Components|Spine") - void SetEmptyAnimation (int trackIndex, float mixDuration); + FTrackEntry SetEmptyAnimation (int trackIndex, float mixDuration); UFUNCTION(BlueprintCallable, Category="Components|Spine") - void AddEmptyAnimation (int trackIndex, float mixDuration, float delay); + FTrackEntry AddEmptyAnimation (int trackIndex, float mixDuration, float delay); UFUNCTION(BlueprintCallable, Category="Components|Spine") void ClearTracks (); @@ -51,8 +62,12 @@ public: UFUNCTION(BlueprintCallable, Category="Components|Spine") void ClearTrack (int trackIndex); + UFUNCTION(BlueprintImplentableEvent, category = "Components|Spine") + void AnimationEvent(int trackIndex, ); + protected: - void DisposeState(); + void CheckState (); + void DisposeState (); spAnimationStateData* stateData; spAnimationState* state;