Lua向C#逻辑迁移 一期 #13

将整个插件代码上传
This commit is contained in:
2025-10-26 21:48:39 +08:00
parent 56994b3927
commit 648386cd73
785 changed files with 53683 additions and 2 deletions

View File

@ -0,0 +1,57 @@
#include "CSBindsManager.h"
#include "UnrealSharpBinds.h"
FCSBindsManager* FCSBindsManager::BindsManagerInstance = nullptr;
FCSBindsManager* FCSBindsManager::Get()
{
if (!BindsManagerInstance)
{
BindsManagerInstance = new FCSBindsManager();
}
return BindsManagerInstance;
}
void FCSBindsManager::RegisterExportedFunction(const FName& ClassName, const FCSExportedFunction& ExportedFunction)
{
FCSBindsManager* Instance = Get();
TArray<FCSExportedFunction>& ExportedFunctions = Instance->ExportedFunctionsMap.FindOrAdd(ClassName);
ExportedFunctions.Add(ExportedFunction);
}
void* FCSBindsManager::GetBoundFunction(const TCHAR* InOuterName, const TCHAR* InFunctionName, int32 ManagedFunctionSize)
{
TRACE_CPUPROFILER_EVENT_SCOPE(UCSBindsManager::GetBoundFunction);
FCSBindsManager* Instance = Get();
FName ManagedOuterName = FName(InOuterName);
FName ManagedFunctionName = FName(InFunctionName);
TArray<FCSExportedFunction>* ExportedFunctions = Instance->ExportedFunctionsMap.Find(ManagedOuterName);
if (!ExportedFunctions)
{
UE_LOG(LogUnrealSharpBinds, Error, TEXT("Failed to get BoundNativeFunction: No exported functions found for %s"), InOuterName);
return nullptr;
}
for (FCSExportedFunction& NativeFunction : *ExportedFunctions)
{
if (NativeFunction.Name != ManagedFunctionName)
{
continue;
}
if (NativeFunction.Size != ManagedFunctionSize)
{
UE_LOG(LogUnrealSharpBinds, Error, TEXT("Failed to get BoundNativeFunction: Function size mismatch for %s::%s."), InOuterName, InFunctionName);
return nullptr;
}
return NativeFunction.FunctionPointer;
}
UE_LOG(LogUnrealSharpBinds, Error, TEXT("Failed to get BoundNativeFunction: No function found for %s.%s"), *ManagedOuterName.ToString(), *ManagedFunctionName.ToString());
return nullptr;
}

View File

@ -0,0 +1,11 @@
#include "CSExportedFunction.h"
#include "CSBindsManager.h"
FCSExportedFunction::FCSExportedFunction(const FName& OuterName, const FName& Name, void* InFunctionPointer, int32 InSize):
Name(Name),
FunctionPointer(InFunctionPointer),
Size(InSize)
{
FCSBindsManager::RegisterExportedFunction(OuterName, *this);
}

View File

@ -0,0 +1,18 @@
#include "UnrealSharpBinds.h"
#define LOCTEXT_NAMESPACE "FUnrealSharpBindsModule"
DEFINE_LOG_CATEGORY(LogUnrealSharpBinds);
void FUnrealSharpBindsModule::StartupModule()
{
}
void FUnrealSharpBindsModule::ShutdownModule()
{
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FUnrealSharpBindsModule, UnrealSharpBinds)