diff --git a/Content/MyAssets/Blueprints/Bp_ToggleLight.uasset b/Content/MyAssets/Blueprints/Bp_ToggleLight.uasset new file mode 100644 index 0000000..1b091b8 Binary files /dev/null and b/Content/MyAssets/Blueprints/Bp_ToggleLight.uasset differ diff --git a/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap.umap b/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap.umap index 1265ac9..ac81d07 100644 Binary files a/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap.umap and b/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap.umap differ diff --git a/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap_BuiltData.uasset b/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap_BuiltData.uasset index 1052bbe..f55ce3a 100644 Binary files a/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap_BuiltData.uasset and b/Content/ThirdPersonBP/Maps/ThirdPersonExampleMap_BuiltData.uasset differ diff --git a/Source/ThirdPerson/Private/ToggleLight.cpp b/Source/ThirdPerson/Private/ToggleLight.cpp new file mode 100644 index 0000000..6157825 --- /dev/null +++ b/Source/ThirdPerson/Private/ToggleLight.cpp @@ -0,0 +1,59 @@ +// All content (c) Shaun Reed 2021, all rights reserved + + +#include "ToggleLight.h" + +#include "Components/PointLightComponent.h" +#include "Components/SphereComponent.h" + +// Sets default values +AToggleLight::AToggleLight() +{ + // 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; + + DesiredIntensity = 3000.0f; + + PointLight1 = CreateDefaultSubobject(TEXT("PointLight1")); + PointLight1->Intensity = DesiredIntensity; + // PointLight1->bVisible = true; + RootComponent = PointLight1; + + Sphere1 = CreateDefaultSubobject(TEXT("Sphere1")); + Sphere1->InitSphereRadius(Radius); + Sphere1->SetupAttachment(RootComponent); + + Sphere1->OnComponentBeginOverlap.AddDynamic(this, &AToggleLight::OnOverlapBegin); // set up a notification for when this component overlaps something + Sphere1->OnComponentEndOverlap.AddDynamic(this, &AToggleLight::OnOverlapEnd); // set up a notification for when this component overlaps something +} + +void AToggleLight::OnOverlapBegin_Implementation(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + if (OtherActor && (OtherActor != this) && OtherComp) + { + ToggleLight(); + } +} + +void AToggleLight::OnOverlapEnd_Implementation(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (OtherActor && (OtherActor != this) && OtherComp) + { + ToggleLight(); + } +} + +void AToggleLight::ToggleLight() +{ + PointLight1->ToggleVisibility(); +} + +void AToggleLight::Tick(float DeltaTime) +{ + if (Radius != Sphere1->GetUnscaledSphereRadius()) + { + Sphere1->SetSphereRadius(Radius); + } + +} + diff --git a/Source/ThirdPerson/Public/ToggleLight.h b/Source/ThirdPerson/Public/ToggleLight.h new file mode 100644 index 0000000..b43c91d --- /dev/null +++ b/Source/ThirdPerson/Public/ToggleLight.h @@ -0,0 +1,53 @@ +// All content (c) Shaun Reed 2021, all rights reserved + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "ToggleLight.generated.h" + +UCLASS() +class THIRDPERSON_API AToggleLight : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AToggleLight(); + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Switch Components") + class UPointLightComponent* PointLight1; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Switch Components") + class USphereComponent* Sphere1; + + // Radius of the trigger to toggle the light + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables") + float Radius = 50.0f; + + /** the desired intensity for the light */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Switch Variables") + float DesiredIntensity; + + /** Toggles the light component's visibility*/ + UFUNCTION() + void ToggleLight(); + + // + // Trigger functions + + /** called when something enters the sphere component */ + UFUNCTION(BlueprintNativeEvent, Category = "Switch Functions") + void OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); + void OnOverlapBegin_Implementation(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); + + /** called when something leaves the sphere component */ + UFUNCTION(BlueprintNativeEvent, Category = "Switch Functions") + void OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); + void OnOverlapEnd_Implementation(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); + + // + // Update functions + + virtual void Tick(float DeltaTime) override; +};