mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[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:
parent
c9d871ab63
commit
c0699e23a0
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user