Sfoglia il codice sorgente

[UE4] UBoneDriverComponent and UBoneFollowerComponent as USceneComponent (#1175)

* bone driver component as scene component

* bone follower component as scene component
przemyslawlis 7 anni fa
parent
commit
566afe6c57

+ 8 - 3
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineBoneDriverComponent.cpp

@@ -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());
+		}
 	}
 }
 

+ 14 - 5
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineBoneFollowerComponent.cpp

@@ -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());
+				}
+			}
 		}
 	}
 }

+ 6 - 2
spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Public/SpineBoneDriverComponent.h

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

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

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