Actor with time management(C++ modification)
You may need to display the time actor was created and the time it was changed. If several people are working together, you will need it more.
C ++ code work is required.
ActorWithTimeManagement.h
ActorWithTimeManagement.cpp
Implementation
ActorWithTimeManagement.h
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "ActorWithTimeManagement.generated.h" UCLASS() class TEST02_API AActorWithTimeManagement : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AActorWithTimeManagement(); UPROPERTY() FDateTime BirthTime; UPROPERTY() FDateTime LastModifiedTime; UPROPERTY(VisibleInstanceOnly, Category = "Time", Transient) FString Birth; UPROPERTY(VisibleInstanceOnly, Category = "Time", Transient) FString Modified; UPROPERTY(VisibleInstanceOnly, Category = "Time", Transient) FString Passed; protected: // Called when the game starts or when spawned virtual void BeginPlay() override; virtual void PostInitProperties() override; virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; void ValidateTime(); public: // Called every frame virtual void Tick(float DeltaTime) override; };
ActorWithTimeManagement.cpp
// Fill out your copyright notice in the Description page of Project Settings. #include "ActorWithTimeManagement.h" // Sets default values AActorWithTimeManagement::AActorWithTimeManagement() { // 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; } // Called when the game starts or when spawned void AActorWithTimeManagement::BeginPlay() { Super::BeginPlay(); } // Called every frame void AActorWithTimeManagement::Tick(float DeltaTime) { Super::Tick(DeltaTime); } void AActorWithTimeManagement::PostInitProperties() { Super::PostInitProperties(); ValidateTime(); } void AActorWithTimeManagement::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { LastModifiedTime = FDateTime::Now(); ValidateTime(); Super::PostEditChangeProperty(PropertyChangedEvent); } void AActorWithTimeManagement::ValidateTime() { if (BirthTime.GetYear() < 2018) { BirthTime = FDateTime::Now(); LastModifiedTime = FDateTime::Now(); } Birth.Empty(); Birth.Append(BirthTime.ToString(TEXT("%Y.%m.%d - %h:%M %A"))); Modified.Empty(); Modified.Append(LastModifiedTime.ToString(TEXT("%Y.%m.%d - %h:%M %A"))); Passed.Empty(); Passed.Append( FString::FromInt( (int32)( FDateTime::Now() - BirthTime ).GetTotalHours() ) ); Passed.Append(TEXT(" hour(s) passed.")); }
Code highlight by http://hilite.me/
Thank you!
Comments
Post a Comment