“初始化俯视角工程,带puerts,未编过”

This commit is contained in:
2024-12-01 02:11:25 +08:00
parent 04698dd585
commit 850d76173c
1491 changed files with 271579 additions and 0 deletions
@@ -0,0 +1,89 @@
#include "SoftObjectWrapper.h"
#include "V8Utils.h"
#include "ObjectMapper.h"
namespace PUERTS_NAMESPACE
{
v8::Local<v8::FunctionTemplate> FSoftObjectWrapper::ToFunctionTemplate(v8::Isolate* Isolate)
{
auto Result = v8::FunctionTemplate::New(Isolate);
Result->InstanceTemplate()->SetInternalFieldCount(6);
Result->PrototypeTemplate()->Set(
FV8Utils::ToV8String(Isolate, "LoadSynchronous"), v8::FunctionTemplate::New(Isolate, &LoadSynchronous));
Result->PrototypeTemplate()->Set(FV8Utils::ToV8String(Isolate, "Get"), v8::FunctionTemplate::New(Isolate, &Get));
return Result;
}
typedef UObject* (*FSoftObjectPtrObjectGetter)(FSoftObjectPtr* Ptr);
static void GenericObjectGet(const v8::FunctionCallbackInfo<v8::Value>& Info, FSoftObjectPtrObjectGetter Getter)
{
auto Isolate = Info.GetIsolate();
auto Context = Isolate->GetCurrentContext();
FSoftObjectPtr* Ptr = FV8Utils::GetPointerFast<FSoftObjectPtr>(Info.Holder());
if (!Ptr)
{
FV8Utils::ThrowException(Isolate, "passing a invalid object for FSoftObjectPtr");
return;
}
auto Obj = Getter(Ptr);
if (Obj)
{
UClass* PropertyClass = nullptr;
if (UObject* Object = FV8Utils::GetUObject(Info.Holder(), 1))
{
if (FV8Utils::IsReleasedPtr(Object))
{
FV8Utils::ThrowException(Isolate, "passing a invalid object");
return;
}
PropertyClass = Cast<UClass>(Object);
}
UClass* MetaClass = nullptr;
if (UObject* Object = FV8Utils::GetUObject(Info.Holder(), 2))
{
if (FV8Utils::IsReleasedPtr(Object))
{
FV8Utils::ThrowException(Isolate, "passing a invalid object");
return;
}
MetaClass = Cast<UClass>(Object);
}
if (PropertyClass && !Obj->GetClass()->IsChildOf(PropertyClass))
{
// FV8Utils::ThrowException(Isolate, "invalid type");
return;
}
if (MetaClass)
{
auto Class = Cast<UClass>(Obj);
if (!Class)
{
// FV8Utils::ThrowException(Isolate, "not a class");
return;
}
if (!Class->IsChildOf(MetaClass))
{
// FV8Utils::ThrowException(Isolate, "not a expect class");
return;
}
}
Info.GetReturnValue().Set(FV8Utils::IsolateData<IObjectMapper>(Isolate)->FindOrAdd(Isolate, Context, Obj->GetClass(), Obj));
}
}
void FSoftObjectWrapper::LoadSynchronous(const v8::FunctionCallbackInfo<v8::Value>& Info)
{
GenericObjectGet(Info, [](FSoftObjectPtr* Ptr) { return Ptr->LoadSynchronous(); });
}
void FSoftObjectWrapper::Get(const v8::FunctionCallbackInfo<v8::Value>& Info)
{
GenericObjectGet(Info, [](FSoftObjectPtr* Ptr) { return Ptr->Get(); });
}
} // namespace PUERTS_NAMESPACE