初始化提交
This commit is contained in:
72
Source/BusyRabbit/Private/BusyGamePlayLibrary.cpp
Normal file
72
Source/BusyRabbit/Private/BusyGamePlayLibrary.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BusyGamePlayLibrary.h"
|
||||
#include "BusyDataAsset.h"
|
||||
|
||||
static inline const UBusyDataAsset* GetGameAsset() {
|
||||
FSoftObjectPath AssetPath(TEXT("BusyRabbit.BusyDataAsset'/Game/Data/BusyGameAsset.BusyGameAsset'"));
|
||||
return Cast<UBusyDataAsset>(AssetPath.TryLoad());
|
||||
}
|
||||
|
||||
template<typename RowStruct>
|
||||
static bool GetTableConfig(const FString& TableName, const FName& RowName, RowStruct& RowData) {
|
||||
UDataTable* Table = UBusyGamePlayLibrary::GetGameDataTable(TableName);
|
||||
RowStruct* Config = Table->FindRow<RowStruct>(
|
||||
RowName,
|
||||
*FString::Printf(TEXT("GetTableConfig, %s"), *RowName.ToString()),
|
||||
true
|
||||
);
|
||||
if (Config != nullptr) {
|
||||
RowData = *Config;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UDataTable* UBusyGamePlayLibrary::GetGameDataTable(const FString& TableName){
|
||||
const UBusyDataAsset* GameAsset = GetGameAsset();
|
||||
if (!GameAsset) return nullptr;
|
||||
auto Table = (GameAsset->DataTableMapping.Find(TableName));
|
||||
return Table ? Table->Get() : nullptr;
|
||||
}
|
||||
|
||||
UClass* UBusyGamePlayLibrary::GetGameClass(const FString& ClassName){
|
||||
const UBusyDataAsset* GameAsset = GetGameAsset();
|
||||
if (!GameAsset) return nullptr;
|
||||
auto Class = (GameAsset->ClassPathMapping.Find(ClassName));
|
||||
return Class ? Class->Get() : nullptr;
|
||||
}
|
||||
|
||||
UClass* UBusyGamePlayLibrary::GetGameUIClass(const FString& ClassName){
|
||||
const UBusyDataAsset* GameAsset = GetGameAsset();
|
||||
if (!GameAsset) return nullptr;
|
||||
auto Class = (GameAsset->UIPathMapping.Find(ClassName));
|
||||
return Class ? Class->Get() : nullptr;
|
||||
}
|
||||
|
||||
UWorld* UBusyGamePlayLibrary::K2_GetWorld(UObject* obj){
|
||||
return Cast<UWorld>(obj->GetOuter());
|
||||
}
|
||||
|
||||
bool UBusyGamePlayLibrary::GetLevelBaseConfig(const FName& RowName, FBusyLevelBaseConfig& RowData){
|
||||
return GetTableConfig<FBusyLevelBaseConfig>(TEXT("LevelBaseConfig"), RowName, RowData);
|
||||
}
|
||||
|
||||
bool UBusyGamePlayLibrary::GetLevelItemConfig(const FName& RowName, FBusyLevelItemConfig& RowData){
|
||||
return GetTableConfig<FBusyLevelItemConfig>(TEXT("LevelItems"), RowName, RowData);
|
||||
}
|
||||
|
||||
bool UBusyGamePlayLibrary::GetRoleConfig(const FName& RowName, FBusyRoleConfig& RowData){
|
||||
return GetTableConfig<FBusyRoleConfig>(TEXT("RoleConfig"), RowName, RowData);
|
||||
}
|
||||
|
||||
bool UBusyGamePlayLibrary::GetItemResourceConfig(const FName& RowName, FBusyLevelItemResourceConfig& RowData){
|
||||
return GetTableConfig<FBusyLevelItemResourceConfig>(TEXT("LevelItemResource"), RowName, RowData);
|
||||
}
|
||||
|
||||
bool UBusyGamePlayLibrary::GetLevelItemDescription(const FName& RowName, FBusyLevelItemDescription& RowData){
|
||||
return GetTableConfig<FBusyLevelItemDescription>(TEXT("LevelItemDesc"), RowName, RowData);
|
||||
}
|
||||
Reference in New Issue
Block a user