[ue4] Added blueprint node for SpineWidget and SpineSkeletonComponent. Expects an array of skin names. Creates a new spine::Skin internally from those skins and applies it to the skeleton. Closes #1416, closes #1534.

This commit is contained in:
badlogic 2019-12-19 16:02:46 +01:00
parent c9d871ab63
commit c0699e23a0
4 changed files with 58 additions and 1 deletions

View File

@ -41,6 +41,28 @@ USpineSkeletonComponent::USpineSkeletonComponent () {
bAutoActivate = true;
}
bool USpineSkeletonComponent::SetSkins(UPARAM(ref) TArray<FString>& SkinNames) {
CheckState();
if (skeleton) {
spine::Skin* newSkin = new spine::Skin("__spine-ue3_custom_skin");
for (auto& skinName : SkinNames) {
spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
if (!skin) {
delete newSkin;
return false;
}
newSkin->addSkin(skin);
}
skeleton->setSkin(newSkin);
if (customSkin != nullptr) {
delete customSkin;
}
customSkin = newSkin;
return true;
}
else return false;
}
bool USpineSkeletonComponent::SetSkin (const FString skinName) {
CheckState();
if (skeleton) {

View File

@ -185,6 +185,11 @@ void USpineWidget::DisposeState() {
skeleton = nullptr;
}
if (customSkin) {
delete customSkin;
customSkin = nullptr;
}
trackEntries.Empty();
}
@ -204,6 +209,28 @@ bool USpineWidget::SetSkin(const FString skinName) {
else return false;
}
bool USpineWidget::SetSkins(UPARAM(ref) TArray<FString>& SkinNames) {
CheckState();
if (skeleton) {
spine::Skin* newSkin = new spine::Skin("__spine-ue3_custom_skin");
for (auto& skinName : SkinNames) {
spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
if (!skin) {
delete newSkin;
return false;
}
newSkin->addSkin(skin);
}
skeleton->setSkin(newSkin);
if (customSkin != nullptr) {
delete customSkin;
}
customSkin = newSkin;
return true;
}
else return false;
}
void USpineWidget::GetSkins(TArray<FString> &Skins) {
CheckState();
if (skeleton) {

View File

@ -55,6 +55,9 @@ public:
UFUNCTION(BlueprintPure, Category = "Components|Spine|Skeleton")
void GetSkins(TArray<FString> &Skins);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetSkins(UPARAM(ref) TArray<FString>& SkinNames);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetSkin (const FString SkinName);
@ -138,5 +141,6 @@ protected:
spine::Skeleton* skeleton;
USpineAtlasAsset* lastAtlas = nullptr;
spine::Atlas* lastSpineAtlas = nullptr;
USpineSkeletonDataAsset* lastData = nullptr;
USpineSkeletonDataAsset* lastData = nullptr;
spine::Skin* customSkin = nullptr;
};

View File

@ -89,6 +89,9 @@ public:
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetSkin(const FString SkinName);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool SetSkins(UPARAM(ref) TArray<FString> &SkinNames);
UFUNCTION(BlueprintCallable, Category = "Components|Spine|Skeleton")
bool HasSkin(const FString SkinName);
@ -222,6 +225,7 @@ protected:
USpineAtlasAsset* lastAtlas = nullptr;
spine::Atlas* lastSpineAtlas = nullptr;
USpineSkeletonDataAsset* lastData = nullptr;
spine::Skin* customSkin = nullptr;
// Need to hold on to the dynamic instances, or the GC will kill us while updating them
UPROPERTY()