mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[ue4] First few steps with blueprints.
This commit is contained in:
parent
f31c298528
commit
fc1676c592
Binary file not shown.
BIN
spine-ue4/Content/Raptor_Blueprint.uasset
Normal file
BIN
spine-ue4/Content/Raptor_Blueprint.uasset
Normal file
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user