You've already forked LuckyWorld
Optimize code to unreal style
This commit is contained in:
@ -8,7 +8,6 @@
|
||||
void ALuckyRobotsGameMode::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
ULuckyRobotsFunctionLibrary::UpdateQualitySettings(this);
|
||||
}
|
||||
|
||||
@ -17,24 +16,21 @@ UClass* ALuckyRobotsGameMode::GetDefaultPawnClassForController_Implementation(AC
|
||||
UClass* RobotClass = Super::GetDefaultPawnClassForController_Implementation(InController);
|
||||
|
||||
ERobotsName CurrentRobot = ERobotsName::None;
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance());
|
||||
if (LuckyRobotsGameInstance)
|
||||
if (ULuckyRobotsGameInstance* GameInstance = Cast<ULuckyRobotsGameInstance>(GetGameInstance()))
|
||||
{
|
||||
CurrentRobot = LuckyRobotsGameInstance->CurrentSelectRobot;
|
||||
CurrentRobot = GameInstance->CurrentSelectRobot;
|
||||
}
|
||||
if (CurrentRobot != ERobotsName::None)
|
||||
{
|
||||
TArray<FRobotData> ActiveRobotDataList = ULuckyRobotsFunctionLibrary::GetActiveRobotDataList(this);
|
||||
for (auto ActiveRobotData : ActiveRobotDataList)
|
||||
for (const FRobotData& RobotData : ActiveRobotDataList)
|
||||
{
|
||||
if (ActiveRobotData.Name == CurrentRobot)
|
||||
if (RobotData.Name == CurrentRobot)
|
||||
{
|
||||
RobotClass = ActiveRobotData.RobotClass;
|
||||
RobotClass = RobotData.RobotClass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RobotClass;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ ALuckyRobotsGameState::ALuckyRobotsGameState()
|
||||
void ALuckyRobotsGameState::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (SocketIOClientComponent)
|
||||
{
|
||||
SocketIOClientComponent->Connect(L"http://localhost:3000/");
|
||||
@ -23,33 +22,25 @@ void ALuckyRobotsGameState::BeginPlay()
|
||||
|
||||
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
|
||||
{
|
||||
if (SocketIOClientComponent)
|
||||
if (SocketIOClientComponent && SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
if (SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
|
||||
SocketIOClientComponent->Emit("message", SIOJsonValue);
|
||||
}
|
||||
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
|
||||
SocketIOClientComponent->Emit(TEXT("message"), SIOJsonValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
|
||||
{
|
||||
if (SocketIOClientComponent)
|
||||
if (SocketIOClientComponent && SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
if (SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
SocketIOClientComponent->BindEventToGenericEvent("response");
|
||||
}
|
||||
SocketIOClientComponent->BindEventToGenericEvent(TEXT("response"));
|
||||
}
|
||||
}
|
||||
|
||||
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
|
||||
{
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
|
||||
if (LuckyRobotsGameInstance)
|
||||
if (ULuckyRobotsGameInstance* GameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this))
|
||||
{
|
||||
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
|
||||
GameInstance->DoGetDispatch(EventName, EventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user