CarlaWheeledVehicle: Added for curve/callbacks for timeline

For now, all the logic happens in the TimelineDefault.
This commit is contained in:
Daniel Santos-Olivan 2021-09-10 11:55:59 +02:00 committed by bernat
parent 4fb8476211
commit 9400f8f546
2 changed files with 33 additions and 5 deletions

View File

@ -45,6 +45,13 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti
BaseMovementComponent = CreateDefaultSubobject<UBaseCarlaMovementComponent>(TEXT("BaseMovementComponent")); BaseMovementComponent = CreateDefaultSubobject<UBaseCarlaMovementComponent>(TEXT("BaseMovementComponent"));
DoorTimelineDefault = CreateDefaultSubobject<UTimelineComponent>(TEXT("Timeline")); DoorTimelineDefault = CreateDefaultSubobject<UTimelineComponent>(TEXT("Timeline"));
InterpFunction.BindUFunction(this, FName("DoorTimelineUpdate"));
TimelineFinished.BindUFunction(this, FName("DoorTimelineFinished"));
// TimelineUpdate.BindUFunction(this, FName("DoorTimelineUpdate"));
//DoorTimelineDefault->SetTimelineLength(5.0f);
//DoorTimelineDefault->SetFloatCurve(CurveDoor, TEXT("DoorTimelineCurve"));
} }
ACarlaWheeledVehicle::~ACarlaWheeledVehicle() {} ACarlaWheeledVehicle::~ACarlaWheeledVehicle() {}
@ -597,16 +604,14 @@ void ACarlaWheeledVehicle::ConfigureAnimationData()
UE_LOG(LogTemp, Warning, TEXT("ACarlaWheeledVehicle::ConfigureAnimationData: DoorAnimAlpha: %d"), DoorAnimAlpha.Num()); UE_LOG(LogTemp, Warning, TEXT("ACarlaWheeledVehicle::ConfigureAnimationData: DoorAnimAlpha: %d"), DoorAnimAlpha.Num());
for (int i = 0; i < DoorAnimMaxAngle.Num(); i++) { for (int i = 0; i < DoorAnimMaxAngle.Num(); i++) {
//DoorAnimAlpha.Emplace(DoorAnimMaxAngle[i] * 2.0f);
//UE_LOG(LogTemp, Warning, TEXT(" DoorAnimAlpha: %d %d"), DoorAnimAlpha[i], DoorAnimAlpha.Num());
//UTimelineComponent* Timeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("Timeline_%d"), i);
FName NameTimeline = FName(TEXT("Timeline_%d"), i); FName NameTimeline = FName(TEXT("Timeline_%d"), i);
UTimelineComponent* Timeline = DuplicateObject<UTimelineComponent>(DoorTimelineDefault, nullptr); UTimelineComponent* Timeline = DuplicateObject<UTimelineComponent>(DoorTimelineDefault, nullptr);
DoorTimeline.Add(Timeline); DoorTimeline.Add(Timeline);
} }
UE_LOG(LogTemp, Warning, TEXT("ACarlaWheeledVehicle::ConfigureAnimationData: DoorTimeline: %d"), DoorTimeline.Num()); DoorTimelineDefault->AddInterpFloat(CurveDoor, InterpFunction);
DoorTimelineDefault->SetTimelinePostUpdateFunc(TimelineUpdate);
DoorTimelineDefault->SetTimelineFinishedFunc(TimelineFinished);
} }

View File

@ -18,6 +18,7 @@
#include "VehicleAnimInstance.h" #include "VehicleAnimInstance.h"
#include "MovementComponents/BaseCarlaMovementComponent.h" #include "MovementComponents/BaseCarlaMovementComponent.h"
#include "Components/TimelineComponent.h" #include "Components/TimelineComponent.h"
#include "Runtime/Engine/Classes/Curves/CurveFloat.h"
#include "CoreMinimal.h" #include "CoreMinimal.h"
@ -278,6 +279,28 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Door Animation") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Door Animation")
TArray<UTimelineComponent*> DoorTimeline; TArray<UTimelineComponent*> DoorTimeline;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Door Animation")
class UCurveFloat* CurveDoor;
FOnTimelineFloat InterpFunction{};
FOnTimelineEvent TimelineFinished{};
FOnTimelineEvent TimelineUpdate{};
UFUNCTION()
void DoorTimelineUpdate(float value)
{
UE_LOG(LogTemp, Warning, TEXT("DoorTimelineUpdate: %f"), value);
for(int i = 0; i < DoorAnimAlpha.Num(); i++)
DoorAnimAlpha[i] = value;
}
UFUNCTION()
void DoorTimelineFinished()
{
UE_LOG(LogTemp, Warning, TEXT("DoorTimelineFinished"));
}
private: private:
/// Current state of the vehicle controller (for debugging purposes). /// Current state of the vehicle controller (for debugging purposes).