// Fill out your copyright notice in the Description page of Project Settings. #include "LuckyRobotsFunctionLibrary.h" #include "LuckyRobotsGameInstance.h" #include "GameFramework/GameUserSettings.h" ULuckyRobotsGameInstance* ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(const UObject* WorldContextObject) { return Cast(WorldContextObject->GetWorld()->GetGameInstance()); } TArray ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(const UObject* WorldContextObject) { TArray RobotDataList; ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject); if (LuckyRobotsGameInstance) { if (LuckyRobotsGameInstance->RobotDataDataTable) { FString ContextString; TArray RowNames = LuckyRobotsGameInstance->RobotDataDataTable->GetRowNames(); for (auto RowString : RowNames) { FRobotData* pRow = LuckyRobotsGameInstance->RobotDataDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { RobotDataList.Add(*pRow); } } } } } return RobotDataList; } TArray ULuckyRobotsFunctionLibrary::GetActiveLevelDataList(const UObject* WorldContextObject) { TArray LevelDataList; ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject); if (LuckyRobotsGameInstance) { if (LuckyRobotsGameInstance->LevelDataTable) { FString ContextString; TArray RowNames = LuckyRobotsGameInstance->LevelDataTable->GetRowNames(); for (auto RowString : RowNames) { FLevelData* pRow = LuckyRobotsGameInstance->LevelDataTable->FindRow(FName(RowString), ContextString); if (pRow) { if (pRow->bActive) { LevelDataList.Add(*pRow); } } } } } return LevelDataList; } void ULuckyRobotsFunctionLibrary::UpdateQualitySettings(const UObject* WorldContextObject) { ULuckyRobotsGameInstance* LuckyRobotsGameInstance = GetLuckyRobotsGameInstance(WorldContextObject); if (LuckyRobotsGameInstance) { // Load game user settings and apply UGameUserSettings* GameUserSettings = GEngine->GetGameUserSettings(); if (GameUserSettings) { GameUserSettings->SetOverallScalabilityLevel(int(LuckyRobotsGameInstance->CurrentSelectQuality)); GameUserSettings->SaveSettings(); GameUserSettings->ApplySettings(true); } } }