Added LineIcon
This commit is contained in:
@@ -33,17 +33,35 @@ void AGestureAction_Ruler::InitAction_Implementation(AHandActor* Hand, const FGe
|
||||
}
|
||||
RulerPoints.Add(FVector::ZeroVector);
|
||||
RulerPoints.Add(FVector::ZeroVector);
|
||||
|
||||
if (LabelIconClass)
|
||||
{
|
||||
LabelIcon = GetWorld()->SpawnActor<ATableIconLabelActor>(LabelIconClass, StartPoint, FRotator::ZeroRotator, SpawnParams);
|
||||
|
||||
if (LabelIcon)
|
||||
{
|
||||
LabelIcon->OwningAction = this;
|
||||
LabelIcon->bPersistOnActionEnd = true;
|
||||
LabelIcon->UpdateLabel(StartPoint, 0.f);
|
||||
Icons.Add(LabelIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AGestureAction_Ruler::UpdateAction_Implementation()
|
||||
{
|
||||
if (!HandA || !IsValid(LineIcon)) return;
|
||||
if (!HandA || !IsValid(LineIcon) || !IsValid(LabelIcon)) return;
|
||||
const FVector Current = HandA->Points[8];
|
||||
|
||||
//if (FVector::DistSquared(Current, RulerPoints[RulerPoints.Num() - 1]) < FMath::Square(UEUnitsPerUnit)) return;
|
||||
RulerPoints[RulerPoints.Num() - 1] = Current - StartPoint;
|
||||
RulerPoints[RulerPoints.Num() - 1].Z = 0;
|
||||
RulerPoints.Last() = Current - StartPoint;
|
||||
RulerPoints.Last().Z = 0;
|
||||
LineIcon->SetPoints(RulerPoints);
|
||||
|
||||
// RulerPoints are local to the line actor, so convert back to world
|
||||
FVector LabelPosition = StartPoint + (RulerPoints.Last() * 0.5f);
|
||||
LabelPosition.Z = 10;
|
||||
LabelIcon->UpdateLabel(LabelPosition, GetSnappedUnits(GetTotalLength()));
|
||||
}
|
||||
|
||||
float AGestureAction_Ruler::GetSnappedUnits(float RawDistance) const
|
||||
|
||||
@@ -98,17 +98,14 @@ void ATableIconLineActor::BuildLineMesh()
|
||||
MeshComponent->CreateMeshSection(0, Vertices, Triangles, Normals, UVs, Colors, Tangents, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
ATableIconWidgetActor::ATableIconWidgetActor()
|
||||
{
|
||||
USceneComponent* Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
|
||||
SetRootComponent(Root);
|
||||
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("WidgetComponent"));
|
||||
WidgetComponent->SetupAttachment(RootComponent);
|
||||
@@ -120,22 +117,8 @@ ATableIconWidgetActor::ATableIconWidgetActor()
|
||||
WidgetInteraction->SetupAttachment(RootComponent);
|
||||
WidgetInteraction->InteractionSource = EWidgetInteractionSource::Custom;
|
||||
WidgetInteraction->InteractionDistance = 10.f;
|
||||
}
|
||||
|
||||
void ATableIconWidgetActor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
APlayerCameraManager* CamManager = UGameplayStatics::GetPlayerCameraManager(this, 0);
|
||||
if (!CamManager) return;
|
||||
|
||||
FVector CamLocation = CamManager->GetCameraLocation();
|
||||
FVector ToCamera = (CamLocation - GetActorLocation()).GetSafeNormal();
|
||||
|
||||
// Only rotate on yaw � keeps widget flat relative to table
|
||||
ToCamera.Z = 0.f;
|
||||
if (!ToCamera.IsNearlyZero())
|
||||
SetActorRotation(ToCamera.ToOrientationRotator());
|
||||
SetWidgetClass(LabelWidgetClass);
|
||||
}
|
||||
|
||||
void ATableIconWidgetActor::SetWidgetClass(TSubclassOf<UUserWidget> InWidgetClass)
|
||||
@@ -150,10 +133,10 @@ UUserWidget* ATableIconWidgetActor::GetWidget() const
|
||||
return WidgetComponent->GetUserWidgetObject();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void ATableIconLabelActor::SetDistance(float RealWorldUnits, const FString& UnitSuffix)
|
||||
void ATableIconLabelActor::UpdateLabel(const FVector& WorldLocation, float Value)
|
||||
{
|
||||
int32 Snapped = FMath::RoundToInt(RealWorldUnits);
|
||||
SetLabelText(FString::Printf(TEXT("%d%s"), Snapped, *UnitSuffix));
|
||||
}
|
||||
SetActorLocation(WorldLocation);
|
||||
SetLabelText(FString::Printf(TEXT("%.1f%s"), Value, *UnitSuffix));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ruler") TSubclassOf<ATableIconLabelActor> LabelIconClass;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Ruler") FString UnitSuffix = TEXT("\"");
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ruler") TArray<FVector> RulerPoints;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Line") float DesiredHeight = -650.f;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ruler") float DesiredHeight = -650.f;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure) float GetTotalLength() const;
|
||||
UFUNCTION(BlueprintCallable) void AddRulerPoint();
|
||||
|
||||
@@ -11,15 +11,6 @@
|
||||
|
||||
class UWidgetComponent;
|
||||
class UWidgetInteractionComponent;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TABLE_API AMyTableIconActors : public ATableIconActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
||||
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
@@ -46,6 +37,7 @@ private:
|
||||
void BuildLineMesh();
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
@@ -56,22 +48,26 @@ class TABLE_API ATableIconWidgetActor : public ATableIconActor
|
||||
public:
|
||||
ATableIconWidgetActor();
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetComponent* WidgetComponent;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetInteractionComponent* WidgetInteraction;
|
||||
UFUNCTION(BlueprintCallable) void SetWidgetClass(TSubclassOf<UUserWidget> InWidgetClass);
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure) UUserWidget* GetWidget() const;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetComponent* WidgetComponent;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly) UWidgetInteractionComponent* WidgetInteraction;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly) TSubclassOf<UUserWidget> LabelWidgetClass;
|
||||
|
||||
UFUNCTION(BlueprintCallable) void SetWidgetClass(TSubclassOf<UUserWidget> InWidgetClass);
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure) UUserWidget* GetWidget() const;
|
||||
|
||||
protected:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
UCLASS(Blueprintable)
|
||||
class TABLE_API ATableIconLabelActor : public ATableIconWidgetActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable) void SetLabelText(const FString& Text);
|
||||
UFUNCTION(BlueprintCallable) void SetDistance(float RealWorldUnits, const FString& UnitSuffix = TEXT("\""));
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Label") FString UnitSuffix = TEXT("\"");
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Label") void SetLabelText(const FString& Text);
|
||||
UFUNCTION(BlueprintCallable, Category = "Label") void UpdateLabel(const FVector& WorldLocation, float Value);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user