Browse Source

[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.

badlogic 5 years ago
parent
commit
c0699e23a0

+ 22 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonComponent.cpp

@@ -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) {

+ 27 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp

@@ -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) {

+ 5 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineSkeletonComponent.h

@@ -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;
 };

+ 4 - 0
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineWidget.h

@@ -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()