void ABitPiece::AddPieceMesh(UStaticMesh *PieceMesh) { PieceMeshComponent->SetStaticMesh(PieceMesh); PieceMeshComponent->OnClicked.AddDynamic(this, &ABitPiece::PieceClicked); PieceMeshComponent->OnBeginCursorOver.AddDynamic(this, &ABitPiece::PieceMouseOver); PieceMeshComponent->OnEndCursorOver.AddDynamic(this, &ABitPiece::PieceMouseOut); FVector orgin; FVector boundsExtent; GetActorBounds(false, orgin, boundsExtent); // Update Width whenever is added a mesh to the piece; Width = boundsExtent.X * 2; //Setting the highlight effect PieceHighlightMeshComponent->SetStaticMesh(PieceMesh); auto world = GetWorld(); auto gameMode = (ABoardGameGameMode*)world->GetAuthGameMode(); PieceHighlightMeshComponent->SetRenderCustomDepth(true); PieceHighlightMeshComponent->SetMaterial(0, gameMode->HighlightMaterial); PieceHighlightMeshComponent->SetVisibility(false); }
void ABitPiece::SetData(const shared_ptr<GameBit> &data) { Super::SetData(data); FString bitName = data->get_bit_name().c_str(); uint32 collor = data->get_attr("Color").get_value(); auto world = GetWorld(); auto gameMode = (ABoardGameGameMode*)world->GetAuthGameMode(); FString meshKey = bitName + (collor == 0 ? TEXT("White") : TEXT("Black")); UStaticMesh* mesh = gameMode->LoadedMeshes[meshKey]; uint32 materialsNum = mesh->Materials.Num(); if (materialsNum > 1) { mesh->Materials.RemoveAt(1, materialsNum - 2); } AddPieceMesh(mesh); }
APlayerController* UWorld::SpawnPlayActor(UPlayer* NewPlayer, ENetRole RemoteRole, const FURL& InURL, const TSharedPtr<const FUniqueNetId>& UniqueId, FString& Error, uint8 InNetPlayerIndex) { Error = TEXT(""); // Make the option string. FString Options; for (int32 i = 0; i < InURL.Op.Num(); i++) { Options += TEXT('?'); Options += InURL.Op[i]; } AGameMode* GameMode = GetAuthGameMode(); // Give the GameMode a chance to accept the login APlayerController* const NewPlayerController = GameMode->Login(NewPlayer, RemoteRole, *InURL.Portal, Options, UniqueId, Error); if (NewPlayerController == NULL) { UE_LOG(LogSpawn, Warning, TEXT("Login failed: %s"), *Error); return NULL; } UE_LOG(LogSpawn, Log, TEXT("%s got player %s [%s]"), *NewPlayerController->GetName(), *NewPlayer->GetName(), UniqueId.IsValid() ? *UniqueId->ToString() : TEXT("Invalid")); // Possess the newly-spawned player. NewPlayerController->NetPlayerIndex = InNetPlayerIndex; NewPlayerController->Role = ROLE_Authority; NewPlayerController->SetReplicates(RemoteRole != ROLE_None); if (RemoteRole == ROLE_AutonomousProxy) { NewPlayerController->SetAutonomousProxy(true); } NewPlayerController->SetPlayer(NewPlayer); GameMode->PostLogin(NewPlayerController); return NewPlayerController; }