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

This commit is contained in:
Harald Csaszar 2021-02-25 11:42:22 +01:00
parent 38d8a1362a
commit 0e5d7adf1c
3 changed files with 19 additions and 3 deletions

View File

@ -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**

View File

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

View File

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