void ATGProjectCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
UE_LOG(MYLog____ATGProjectCharacter, Log, TEXT("---PossessedBy---32323232323"));
if (GetNetMode() == NM_DedicatedServer)
{
if (UTGProjectGameInstance* GI = GetGameInstance<UTGProjectGameInstance>())
{
if (ATGProjectPlayerState* PS = GetPlayerState<ATGProjectPlayerState>())
{
//读存档
bool IsNeedDataTable = true;
if (UTGSettings::Get().bSaveGame)
{
UTGSaveGame* SaveGame = Cast<UTGSaveGame>(UGameplayStatics::LoadGameFromSlot(FString("TGSaveGame_" + PS->GetPlayerName()), 0));
if (SaveGame)
{
PS->SetPlayerCurHP(SaveGame->SG_CurHP);
PS->SetPlayerMaxHP(SaveGame->SG_MaxHP);
IsNeedDataTable = false;
}
}
//读表
if (IsNeedDataTable)
{
if (GI->PlayerInitData)
{
FTGPlayerInitData* PlayerData = GI->PlayerInitData->FindRow<FTGPlayerInitData>(PlayerInitRowName, TEXT(""));
if (ensure(PS))
{
PS->SetPlayerCurHP(PlayerData->MaxHP);
PS->SetPlayerMaxHP(PlayerData->MaxHP);
}
}
}
}
}
}
}