Browse Source

[ue4] Added preview skin / initial skin functionality for USpineWidget. Closes #1845.

Harald Csaszar 4 năm trước cách đây
mục cha
commit
0e5d7adf1c

+ 2 - 1
CHANGELOG.md

@@ -110,7 +110,8 @@
 * Removed dependency on `RHI`, `RenderCore`, and `ShaderCore`.
 * Removed dependency on `RHI`, `RenderCore`, and `ShaderCore`.
 * Re-importing atlases and their textures now works consistently in all situations.
 * Re-importing atlases and their textures now works consistently in all situations.
 * Added mix-and-match example to demonstrate the new Skin API.
 * Added mix-and-match example to demonstrate the new Skin API.
-* Materials on `SkeletonRendererComponent` are now blueprint read and writeable. This allows setting dynamic material instances at runtime
+* Materials on `SkeletonRendererComponent` are now blueprint read and writeable. This allows setting dynamic material instances at runtime.
+* Added `InitialSkin` property to `USpineWidget`. This allows previewing different skins in the UMG Designer. Initial skins can still be overridden via blueprint events such as `On Initialized`.
 
 
 ## C# ##
 ## C# ##
 * **Breaking changes**
 * **Breaking changes**

+ 12 - 1
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineWidget.cpp

@@ -99,6 +99,15 @@ void USpineWidget::SynchronizeProperties() {
 	if (slateWidget.IsValid()) {
 	if (slateWidget.IsValid()) {
 		CheckState();
 		CheckState();
 		if (skeleton) {
 		if (skeleton) {
+			if (!bSkinInitialized) { // blueprint On Initialized may be called beforehand
+				if (InitialSkin != "") SetSkin(InitialSkin);
+#if WITH_EDITOR
+				if (IsDesignTime()) {
+					if (InitialSkin == "") SetSkin("default");
+					bSkinInitialized = false; // allow multiple edits in editor
+				}
+#endif
+			}
 			Tick(0, false);
 			Tick(0, false);
 			slateWidget->SetData(this);
 			slateWidget->SetData(this);
 		} else {
 		} else {
@@ -204,6 +213,7 @@ bool USpineWidget::SetSkin(const FString skinName) {
 		spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
 		spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
 		if (!skin) return false;
 		if (!skin) return false;
 		skeleton->setSkin(skin);
 		skeleton->setSkin(skin);
+		bSkinInitialized = true;
 		return true;
 		return true;
 	}
 	}
 	else return false;
 	else return false;
@@ -211,7 +221,7 @@ bool USpineWidget::SetSkin(const FString skinName) {
 
 
 bool USpineWidget::SetSkins(UPARAM(ref) TArray<FString>& SkinNames) {
 bool USpineWidget::SetSkins(UPARAM(ref) TArray<FString>& SkinNames) {
 	CheckState();
 	CheckState();
-	if (skeleton) {	
+	if (skeleton) {
 		spine::Skin* newSkin = new spine::Skin("__spine-ue3_custom_skin");
 		spine::Skin* newSkin = new spine::Skin("__spine-ue3_custom_skin");
 		for (auto& skinName : SkinNames) {
 		for (auto& skinName : SkinNames) {
 			spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
 			spine::Skin* skin = skeleton->getData()->findSkin(TCHAR_TO_UTF8(*skinName));
@@ -222,6 +232,7 @@ bool USpineWidget::SetSkins(UPARAM(ref) TArray<FString>& SkinNames) {
 			newSkin->addSkin(skin);
 			newSkin->addSkin(skin);
 		}
 		}
 		skeleton->setSkin(newSkin);
 		skeleton->setSkin(newSkin);
+		bSkinInitialized = true;
 		if (customSkin != nullptr) {
 		if (customSkin != nullptr) {
 			delete customSkin;
 			delete customSkin;
 		}
 		}

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

@@ -53,6 +53,9 @@ public:
 	UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
 	UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
 	float Scale = 1;
 	float Scale = 1;
 
 
+	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
+	FString InitialSkin;
+
 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
 	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
 	USpineAtlasAsset* Atlas;
 	USpineAtlasAsset* Atlas;
 
 
@@ -218,7 +221,7 @@ protected:
 	virtual void CheckState();
 	virtual void CheckState();
 	virtual void DisposeState();
 	virtual void DisposeState();
 
 
-	TSharedPtr<SSpineWidget> slateWidget;	
+	TSharedPtr<SSpineWidget> slateWidget;
 
 
 	spine::Skeleton* skeleton;
 	spine::Skeleton* skeleton;
 	spine::AnimationState* state;
 	spine::AnimationState* state;
@@ -256,4 +259,5 @@ private:
 	/* If the animation should update automatically. */
 	/* If the animation should update automatically. */
 	UPROPERTY()
 	UPROPERTY()
 	bool bAutoPlaying;
 	bool bAutoPlaying;
+	bool bSkinInitialized = false;
 };
 };