You've already forked LuckyWorld
Optimize gamemode and gamestate code
This commit is contained in:
@ -2,4 +2,54 @@
|
||||
|
||||
|
||||
#include "LuckyRobotsGameState.h"
|
||||
#include "SocketIOClientComponent.h"
|
||||
#include "LuckyRobotsFunctionLibrary.h"
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
|
||||
ALuckyRobotsGameState::ALuckyRobotsGameState()
|
||||
{
|
||||
SocketIOClientComponent = CreateDefaultSubobject<USocketIOClientComponent>(TEXT("SocketIOClientComponent"));
|
||||
}
|
||||
|
||||
void ALuckyRobotsGameState::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (SocketIOClientComponent)
|
||||
{
|
||||
SocketIOClientComponent->Connect(L"http://localhost:3000/");
|
||||
}
|
||||
}
|
||||
|
||||
void ALuckyRobotsGameState::DoSendMessage(FString SendValue)
|
||||
{
|
||||
if (SocketIOClientComponent)
|
||||
{
|
||||
if (SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
USIOJsonValue* SIOJsonValue = USIOJsonValue::ConstructJsonValueString(this, SendValue);
|
||||
SocketIOClientComponent->Emit("message", SIOJsonValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ALuckyRobotsGameState::DoSocketOnConnect(FString SocketId, FString SessionId, bool IsReconnection)
|
||||
{
|
||||
if (SocketIOClientComponent)
|
||||
{
|
||||
if (SocketIOClientComponent->bIsConnected)
|
||||
{
|
||||
SocketIOClientComponent->BindEventToGenericEvent("response");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ALuckyRobotsGameState::DoSocketOnGenericEvent(FString EventName, USIOJsonValue* EventData)
|
||||
{
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
LuckyRobotsGameInstance->DoGetDispatch(EventName, EventData);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user