[ue4] First few steps with blueprints.

This commit is contained in:
badlogic 2016-12-01 16:51:13 +01:00
parent f31c298528
commit fc1676c592
4 changed files with 64 additions and 30 deletions

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,10 @@
#define LOCTEXT_NAMESPACE "Spine" #define LOCTEXT_NAMESPACE "Spine"
void callback(spAnimationState* state, spEventType type, spTrackEntry* entry, spEvent* event) {
USpineSkeletonComponent* component = (USpineSkeletonComponent*)entry->rendererObject;
}
USpineSkeletonComponent::USpineSkeletonComponent () { USpineSkeletonComponent::USpineSkeletonComponent () {
bWantsBeginPlay = true; bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bCanEverTick = true;
@ -16,6 +20,16 @@ void USpineSkeletonComponent::BeginPlay() {
void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
Super::TickComponent(DeltaTime, TickType, 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) { if (lastAtlas != Atlas || lastData != SkeletonData) {
DisposeState(); DisposeState();
@ -29,12 +43,6 @@ void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickTyp
lastAtlas = Atlas; lastAtlas = Atlas;
lastData = SkeletonData; lastData = SkeletonData;
} }
if (state) {
spAnimationState_update(state, DeltaTime);
spAnimationState_apply(state, skeleton);
spSkeleton_updateWorldTransform(skeleton);
}
} }
void USpineSkeletonComponent::DisposeState () { void USpineSkeletonComponent::DisposeState () {
@ -59,37 +67,48 @@ void USpineSkeletonComponent::FinishDestroy () {
Super::FinishDestroy(); Super::FinishDestroy();
} }
void USpineSkeletonComponent::SetAnimation (int trackIndex, FString animationName, bool loop) { FTrackEntry USpineSkeletonComponent::SetAnimation (int trackIndex, FString animationName, bool loop) {
if (state) { CheckState();
spAnimationState_setAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0); 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) { FTrackEntry USpineSkeletonComponent::AddAnimation (int trackIndex, FString animationName, bool loop, float delay) {
if (state) { CheckState();
spAnimationState_addAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0, delay); 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) { 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) { 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 () { void USpineSkeletonComponent::ClearTracks () {
CheckState();
if (state) { if (state) {
spAnimationState_clearTracks(state); spAnimationState_clearTracks(state);
} }
} }
void USpineSkeletonComponent::ClearTrack (int trackIndex) { void USpineSkeletonComponent::ClearTrack (int trackIndex) {
CheckState();
if (state) { if (state) {
spAnimationState_clearTrack(state, trackIndex); spAnimationState_clearTrack(state, trackIndex);
} }

View File

@ -3,12 +3,23 @@
#pragma once #pragma once
#include "Components/ActorComponent.h" #include "Components/ActorComponent.h"
#include "spine/spine.h"
#include "SpineSkeletonComponent.generated.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; class USpineAtlasAsset;
UCLASS( ClassGroup=(Spine), meta=(BlueprintSpawnableComponent) ) UCLASS(ClassGroup=(Spine), meta=(BlueprintSpawnableComponent))
class SPINEPLUGIN_API USpineSkeletonComponent : public UActorComponent class SPINEPLUGIN_API USpineSkeletonComponent: public UActorComponent {
{
GENERATED_BODY() GENERATED_BODY()
public: public:
@ -34,16 +45,16 @@ public:
// Blueprint functions // Blueprint functions
UFUNCTION(BlueprintCallable, Category="Components|Spine") 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") 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") UFUNCTION(BlueprintCallable, Category="Components|Spine")
void SetEmptyAnimation (int trackIndex, float mixDuration); FTrackEntry SetEmptyAnimation (int trackIndex, float mixDuration);
UFUNCTION(BlueprintCallable, Category="Components|Spine") 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") UFUNCTION(BlueprintCallable, Category="Components|Spine")
void ClearTracks (); void ClearTracks ();
@ -51,8 +62,12 @@ public:
UFUNCTION(BlueprintCallable, Category="Components|Spine") UFUNCTION(BlueprintCallable, Category="Components|Spine")
void ClearTrack (int trackIndex); void ClearTrack (int trackIndex);
UFUNCTION(BlueprintImplentableEvent, category = "Components|Spine")
void AnimationEvent(int trackIndex, );
protected: protected:
void DisposeState(); void CheckState ();
void DisposeState ();
spAnimationStateData* stateData; spAnimationStateData* stateData;
spAnimationState* state; spAnimationState* state;