2023-09-26 17:00:30 -04:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Tangible.h"
|
|
|
|
|
#include "TangibleManager.h"
|
|
|
|
|
|
|
|
|
|
UlxTangible::UlxTangible()
|
|
|
|
|
{
|
2023-09-28 14:32:48 -04:00
|
|
|
Manager = nullptr;
|
2023-09-26 19:26:09 -04:00
|
|
|
TangibleId = -1;
|
2023-09-28 14:32:48 -04:00
|
|
|
CurrentActor = nullptr;
|
|
|
|
|
ActorBlueprint = nullptr;
|
2023-09-26 19:26:09 -04:00
|
|
|
NearAccordingToLuprex = false;
|
2023-09-28 14:32:48 -04:00
|
|
|
NearAccordingToUnreal = false;
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::Init(UlxTangibleManager* tm, int64 id)
|
|
|
|
|
{
|
|
|
|
|
Manager = tm;
|
|
|
|
|
TangibleId = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool UlxTangible::BlueprintIsTangible(TSubclassOf<AActor> bp) {
|
|
|
|
|
if (bp == nullptr) return true;
|
|
|
|
|
return bp->ImplementsInterface(UlxTangibleInterface::StaticClass());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::SetActorBlueprintClass(TSubclassOf<AActor> bp) {
|
|
|
|
|
// If we're already of the right class, do nothing.
|
|
|
|
|
if (ActorBlueprint == bp) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sanity check the blueprint. Nullptr is allowed.
|
|
|
|
|
check(BlueprintIsTangible(bp));
|
|
|
|
|
|
|
|
|
|
// If there's already an actor, delete it.
|
|
|
|
|
if (CurrentActor != nullptr) {
|
|
|
|
|
// Remove the tangible component. This is probably
|
|
|
|
|
// unnecessary, but it makes it more likely that we'll
|
|
|
|
|
// catch bugs early.
|
|
|
|
|
UlxTangibleComponent* comp = CurrentActor->GetComponentByClass<UlxTangibleComponent>();
|
|
|
|
|
if (comp != nullptr) {
|
|
|
|
|
comp->DestroyComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now destroy the actor itself. According to various
|
|
|
|
|
// documents I've read online, it may be necessary to take
|
|
|
|
|
// further steps to delete the object. Not clear.
|
|
|
|
|
CurrentActor->Destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the blueprint reference.
|
|
|
|
|
ActorBlueprint = bp;
|
|
|
|
|
|
|
|
|
|
// Now create a new actor, unless the BP is nullptr.
|
|
|
|
|
if (ActorBlueprint != nullptr) {
|
|
|
|
|
// Create the actor.
|
|
|
|
|
FActorSpawnParameters params;
|
|
|
|
|
FVector location(0, 0, 0);
|
|
|
|
|
FRotator rotation(0, 0, 0);
|
|
|
|
|
UWorld* w = Manager->GetWorld();
|
|
|
|
|
AActor* a = w->SpawnActor(ActorBlueprint, &location, &rotation, params);
|
|
|
|
|
|
|
|
|
|
// Insert a TangibleComponent into the actor.
|
|
|
|
|
UActorComponent* ac = a->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
|
|
|
|
|
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
|
|
|
|
|
check(tc != nullptr);
|
|
|
|
|
|
|
|
|
|
// Make the tangible point to the actor and vice versa.
|
|
|
|
|
tc->Tangible = this;
|
|
|
|
|
CurrentActor = a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 14:32:48 -04:00
|
|
|
void UlxTangible::UpdateAnimationQueue(std::string_view aq) {
|
|
|
|
|
AnimTracker.Update(aq);
|
|
|
|
|
TArray<uint64> aborted = AnimTracker.GetAborted();
|
|
|
|
|
for (uint64 hash : aborted) {
|
|
|
|
|
IlxTangibleInterface::Execute_AbortAnimation(GetActor(), hash);
|
|
|
|
|
}
|
|
|
|
|
FlxAnimationStep step;
|
|
|
|
|
ElxAnimationMode mode = AnimTracker.GetNextStep(step);
|
|
|
|
|
if (mode != ElxAnimationMode::INVALID) {
|
|
|
|
|
bool started = IlxTangibleInterface::Execute_StartAnimation(GetActor(), mode, step);
|
|
|
|
|
if (started) {
|
|
|
|
|
AnimTracker.StartedStep(step.Hash);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVector UlxTangible::GetLocation() const {
|
|
|
|
|
if (CurrentActor == nullptr) {
|
|
|
|
|
return FVector(0,0,0);
|
|
|
|
|
} else {
|
|
|
|
|
return CurrentActor->GetActorLocation();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::Destroy() {
|
|
|
|
|
SetActorBlueprintClass(nullptr);
|
|
|
|
|
Manager = nullptr;
|
|
|
|
|
TangibleId = -1;
|
|
|
|
|
CurrentActor = nullptr;
|
|
|
|
|
ActorBlueprint = nullptr;
|
|
|
|
|
AnimTracker.Clear();
|
|
|
|
|
NearAccordingToLuprex = false;
|
|
|
|
|
NearAccordingToUnreal = false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 17:00:30 -04:00
|
|
|
FString UlxTangible::GetTangiblePlane(AActor* actor) {
|
|
|
|
|
UlxTangibleComponent* comp = actor->GetComponentByClass<UlxTangibleComponent>();
|
|
|
|
|
check(comp != nullptr);
|
2023-09-28 14:32:48 -04:00
|
|
|
return comp->Tangible->Plane.ToString();
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxTangible::SetTangiblePlane(AActor* actor, const FString& plane) {
|
|
|
|
|
UlxTangibleComponent* comp = actor->GetComponentByClass<UlxTangibleComponent>();
|
|
|
|
|
check(comp != nullptr);
|
2023-09-28 14:32:48 -04:00
|
|
|
comp->Tangible->Plane = FName(plane);
|
2023-09-26 17:00:30 -04:00
|
|
|
}
|
|
|
|
|
|