mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-13 18:48:44 +08:00
99 lines
2.5 KiB
C++
99 lines
2.5 KiB
C++
#include "SpinePluginPrivatePCH.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "Spine"
|
|
|
|
USpineSkeletonComponent::USpineSkeletonComponent () {
|
|
bWantsBeginPlay = true;
|
|
PrimaryComponentTick.bCanEverTick = true;
|
|
bTickInEditor = true;
|
|
bAutoActivate = true;
|
|
}
|
|
|
|
void USpineSkeletonComponent::BeginPlay() {
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
|
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
|
|
|
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 () {
|
|
if (stateData) {
|
|
spAnimationStateData_dispose(stateData);
|
|
stateData = nullptr;
|
|
}
|
|
|
|
if (state) {
|
|
spAnimationState_dispose(state);
|
|
state = nullptr;
|
|
}
|
|
|
|
if (skeleton) {
|
|
spSkeleton_dispose(skeleton);
|
|
skeleton = nullptr;
|
|
}
|
|
}
|
|
|
|
void USpineSkeletonComponent::FinishDestroy () {
|
|
DisposeState();
|
|
Super::FinishDestroy();
|
|
}
|
|
|
|
void USpineSkeletonComponent::SetAnimation (int trackIndex, FString animationName, bool loop) {
|
|
if (state) {
|
|
spAnimationState_setAnimationByName(state, trackIndex, TCHAR_TO_UTF8(*animationName), loop ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
void USpineSkeletonComponent::SetEmptyAnimation (int trackIndex, float mixDuration) {
|
|
if (state) {
|
|
spAnimationState_setEmptyAnimation(state, trackIndex, mixDuration);
|
|
}
|
|
}
|
|
|
|
void USpineSkeletonComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) {
|
|
if (state) {
|
|
spAnimationState_addAnimationByName(state, trackIndex, mixDuration, delay);
|
|
}
|
|
}
|
|
|
|
void USpineSkeletonComponent::ClearTracks () {
|
|
if (state) {
|
|
spAnimationState_clearTracks(state);
|
|
}
|
|
}
|
|
|
|
void USpineSkeletonComponent::ClearTrack (int trackIndex) {
|
|
if (state) {
|
|
spAnimationState_clearTrack(state, trackIndex);
|
|
}
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|