-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultipleCurveActor.cpp
More file actions
53 lines (38 loc) · 1.68 KB
/
MultipleCurveActor.cpp
File metadata and controls
53 lines (38 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Fill out your copyright notice in the Description page of Project Settings.
#include "TimelinePluginDemo.h"
#include "MultipleCurveActor.h"
void AMultipleCurveActor::RotateActor(FRotator NewRotator)
{
SetActorRotation(NewRotator);
}
void AMultipleCurveActor::ChangeColor(FLinearColor NewColor)
{
//Dummy code
UMaterialInstanceDynamic* Material = SM->CreateAndSetMaterialInstanceDynamic(0);
Material->SetVectorParameterValue(FName("BaseColor"), NewColor);
}
// Sets default values
AMultipleCurveActor::AMultipleCurveActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SM = CreateDefaultSubobject<UStaticMeshComponent>(FName("SM"));
TimelineHandleComp = CreateDefaultSubobject<UTimelineHandleComponent>(FName("TimelineHandleComp"));
}
// Called when the game starts or when spawned
void AMultipleCurveActor::BeginPlay()
{
Super::BeginPlay();
//Adding a float curve
TimelineHandleComp->AddCurve(FloatCurve);
//Adding a linear color curve
TimelineHandleComp->AddCurve(LinearColorCurve);
//Set interpolation values for the float curve
TimelineHandleComp->SetInitialAndTargetValues(GetActorRotation(), GetActorRotation() + FRotator(180, 0, 180));
//Binding the function that will fire in each tick of the float curve
TimelineHandleComp->OnFloatCurveRotatorTickFunction.AddDynamic(this, &AMultipleCurveActor::RotateActor);
//Binding the function that will fire in each tick of the linearcolor curve
TimelineHandleComp->OnLinearColorCurveTickFunction.AddDynamic(this, &AMultipleCurveActor::ChangeColor);
//Play from start and loop
TimelineHandleComp->PlayTimelineFromStart(true);
}