Add an option for refreshing the weather automatically
This commit is contained in:
parent
b411eb6c0c
commit
97885dfdb4
|
@ -68,6 +68,22 @@ ADynamicWeather::ADynamicWeather(const FObjectInitializer& ObjectInitializer)
|
|||
#endif // WITH_EDITORONLY_DATA
|
||||
}
|
||||
|
||||
void ADynamicWeather::OnConstruction(const FTransform &Transform)
|
||||
{
|
||||
Super::OnConstruction(Transform);
|
||||
#if WITH_EDITOR
|
||||
Update();
|
||||
#endif // WITH_EDITOR
|
||||
}
|
||||
|
||||
void ADynamicWeather::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
#if WITH_EDITOR
|
||||
Update();
|
||||
#endif // WITH_EDITOR
|
||||
}
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
void ADynamicWeather::PostEditChangeProperty(FPropertyChangedEvent &Event)
|
||||
|
@ -121,16 +137,6 @@ FVector ADynamicWeather::GetSunDirection() const
|
|||
return - SphericalCoords.SphericalToUnitCartesian();
|
||||
}
|
||||
|
||||
void ADynamicWeather::Update()
|
||||
{
|
||||
// Modify this actor's rotation according to Sun position.
|
||||
if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) {
|
||||
UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor"));
|
||||
}
|
||||
|
||||
RefreshWeather();
|
||||
}
|
||||
|
||||
void ADynamicWeather::AdjustSunPositionBasedOnActorRotation()
|
||||
{
|
||||
const FVector Direction = - GetActorQuat().GetForwardVector();
|
||||
|
@ -141,6 +147,18 @@ void ADynamicWeather::AdjustSunPositionBasedOnActorRotation()
|
|||
|
||||
#if WITH_EDITOR
|
||||
|
||||
void ADynamicWeather::Update()
|
||||
{
|
||||
// Modify this actor's rotation according to Sun position.
|
||||
if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) {
|
||||
UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor"));
|
||||
}
|
||||
|
||||
if (bRefreshAutomatically) {
|
||||
RefreshWeather();
|
||||
}
|
||||
}
|
||||
|
||||
bool ADynamicWeather::LoadFromConfigFile()
|
||||
{
|
||||
FString FileName;
|
||||
|
|
|
@ -20,6 +20,10 @@ public:
|
|||
|
||||
ADynamicWeather(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
virtual void OnConstruction(const FTransform &Transform) override;
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
|
||||
|
@ -47,12 +51,12 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
void Update();
|
||||
|
||||
void AdjustSunPositionBasedOnActorRotation();
|
||||
|
||||
#if WITH_EDITOR
|
||||
|
||||
void Update();
|
||||
|
||||
bool LoadFromConfigFile();
|
||||
|
||||
bool SaveToConfigFile() const;
|
||||
|
@ -64,9 +68,17 @@ private:
|
|||
UPROPERTY()
|
||||
UArrowComponent *ArrowComponent;
|
||||
|
||||
/** If true, the weather is refreshed on construction and at begin play.
|
||||
* Useful for editing the weather (Editor only).
|
||||
*/
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
bool bRefreshAutomatically = false;
|
||||
|
||||
/** Load the section with the currently set name. */
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
bool bLoadFromConfigFile = false;
|
||||
|
||||
/** Save current settings to disk. */
|
||||
UPROPERTY(Category = "Weather Description", EditAnywhere)
|
||||
bool bSaveToConfigFile = false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue