mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[UE4] UBoneDriverComponent and UBoneFollowerComponent as USceneComponent (#1175)
* bone driver component as scene component * bone follower component as scene component
This commit is contained in:
parent
e7058b225c
commit
566afe6c57
@ -41,9 +41,14 @@ void USpineBoneDriverComponent::BeginPlay () {
|
||||
}
|
||||
|
||||
void USpineBoneDriverComponent::BeforeUpdateWorldTransform(USpineSkeletonComponent* skeleton) {
|
||||
AActor* owner = GetOwner();
|
||||
if (owner && skeleton == lastBoundComponent) {
|
||||
skeleton->SetBoneWorldPosition(BoneName, owner->GetActorLocation() );
|
||||
if (skeleton == lastBoundComponent) {
|
||||
if (UseComponentTransform) {
|
||||
skeleton->SetBoneWorldPosition(BoneName, GetComponentLocation());
|
||||
}
|
||||
else {
|
||||
AActor* owner = GetOwner();
|
||||
if (owner) skeleton->SetBoneWorldPosition(BoneName, owner->GetActorLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -43,14 +43,23 @@ void USpineBoneFollowerComponent::BeginPlay () {
|
||||
void USpineBoneFollowerComponent::TickComponent ( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) {
|
||||
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
|
||||
|
||||
AActor* owner = GetOwner();
|
||||
if (Target && owner) {
|
||||
if (Target) {
|
||||
USpineSkeletonComponent* skeleton = static_cast<USpineSkeletonComponent*>(Target->GetComponentByClass(USpineSkeletonComponent::StaticClass()));
|
||||
if (skeleton) {
|
||||
FTransform transform = skeleton->GetBoneWorldTransform(BoneName);
|
||||
if (UsePosition) owner->SetActorLocation(transform.GetLocation());
|
||||
if (UseRotation) owner->SetActorRotation(transform.GetRotation());
|
||||
if (UseScale) owner->SetActorScale3D(transform.GetScale3D());
|
||||
if (UseComponentTransform) {
|
||||
if (UsePosition) SetWorldLocation(transform.GetLocation());
|
||||
if (UseRotation) SetWorldRotation(transform.GetRotation());
|
||||
if (UseScale) SetWorldScale3D(transform.GetScale3D());
|
||||
}
|
||||
else {
|
||||
AActor* owner = GetOwner();
|
||||
if (owner) {
|
||||
if (UsePosition) owner->SetActorLocation(transform.GetLocation());
|
||||
if (UseRotation) owner->SetActorRotation(transform.GetRotation());
|
||||
if (UseScale) owner->SetActorScale3D(transform.GetScale3D());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,13 +30,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Components/SceneComponent.h"
|
||||
#include "SpineBoneDriverComponent.generated.h"
|
||||
|
||||
class USpineSkeletonComponent;
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class SPINEPLUGIN_API USpineBoneDriverComponent : public UActorComponent {
|
||||
class SPINEPLUGIN_API USpineBoneDriverComponent : public USceneComponent {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
@ -46,6 +46,10 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FString BoneName;
|
||||
|
||||
//Uses just this component when set to true. Updates owning actor otherwise.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool UseComponentTransform = false;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool UsePosition = true;
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class SPINEPLUGIN_API USpineBoneFollowerComponent : public UActorComponent {
|
||||
class SPINEPLUGIN_API USpineBoneFollowerComponent : public USceneComponent {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
@ -45,6 +45,10 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FString BoneName;
|
||||
|
||||
//Updates just this component when set to true. Updates owning actor otherwise.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool UseComponentTransform = false;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool UsePosition = true;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user