75 lines
1.9 KiB
C++
75 lines
1.9 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "TangibleManager.h"
|
|
#include "TangibleInterface.h"
|
|
#include "IntegrationGameState.h"
|
|
#include "TangibleComponent.h"
|
|
#include "DebugPrint.h"
|
|
|
|
using namespace DebugPrint;
|
|
|
|
UTangibleManager::UTangibleManager() {
|
|
World = nullptr;
|
|
ClassTangibleActor = nullptr;
|
|
Player = 0;
|
|
Near = IdView();
|
|
}
|
|
|
|
void UTangibleManager::Init(UWorld *world, UClass* tanact) {
|
|
World = world;
|
|
ClassTangibleActor = tanact;
|
|
Player = 0;
|
|
Near = IdView();
|
|
}
|
|
|
|
UTangibleComponent *UTangibleManager::GetTangible(int64 id) {
|
|
AActor **p = IdToActor.Find(id);
|
|
if (p == nullptr) {
|
|
return nullptr;
|
|
} else {
|
|
AActor* a = *p;
|
|
UTangibleComponent* comp = a->FindComponentByClass<UTangibleComponent>();
|
|
check(comp != nullptr);
|
|
return comp;
|
|
}
|
|
}
|
|
|
|
UTangibleComponent *UTangibleManager::MakeTangible(int64 id) {
|
|
AActor *& p = IdToActor.FindOrAdd(id);
|
|
if (p == nullptr) {
|
|
FActorSpawnParameters params;
|
|
FVector location(0, 0, 0);
|
|
FRotator rotation(0, 0, 0);
|
|
UWorld* w = GetWorld();
|
|
AActor* a = w->SpawnActor(ClassTangibleActor, &location, &rotation, params);
|
|
check(a != nullptr);
|
|
check(a->GetClass()->ImplementsInterface(UlxTangibleInterface::StaticClass()));
|
|
// Insert a TangibleComponent into the actor.
|
|
UActorComponent* ac = a->AddComponentByClass(UTangibleComponent::StaticClass(), false, FTransform::Identity, false);
|
|
UTangibleComponent* tc = Cast<UTangibleComponent>(ac);
|
|
check(tc != nullptr);
|
|
tc->Init(this, a, id);
|
|
p = a;
|
|
return tc;
|
|
} else {
|
|
UTangibleComponent* comp = p->FindComponentByClass<UTangibleComponent>();
|
|
check(comp != nullptr);
|
|
return comp;
|
|
}
|
|
}
|
|
|
|
void UTangibleManager::DeleteTangible(int64 id) {
|
|
// IMPLEMENT ME
|
|
}
|
|
|
|
UTangibleManager::IdArray UTangibleManager::GetLive() {
|
|
IdArray result;
|
|
result.SetNum(IdToActor.Num());
|
|
int next = 0;
|
|
for (auto &pair : IdToActor) {
|
|
result[next++] = pair.Key;
|
|
}
|
|
return result;
|
|
}
|