Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void APawnWithPlanetHorizon::MouseLeftClick()
- {
- FVector posStart = CameraFPS->GetComponentLocation();
- FVector posFinish = posStart + CameraFPS->GetForwardVector() * 100;
- ServerRPC_TraceAndClickActor(posStart, posFinish);
- }
- void APawnWithPlanetHorizon::ServerRPC_TraceAndClickActor_Implementation(FVector posStart, FVector posFinish)
- {
- if (isHoldingSmth)
- {
- IMainActionInterface* holdedActor = Cast<IMainActionInterface>(whatActorHolding);
- holdedActor->mouseLeftClick(this, nullptr);
- }
- else
- {
- FHitResult hitResult;
- FCollisionQueryParams collisionParams;
- TArray<UPrimitiveComponent*> componentsToIgnore;
- collisionParams.AddIgnoredActor(this);
- collisionParams.bTraceComplex = false;
- bool smthIsHit = GetWorld()->LineTraceSingleByChannel(hitResult, posStart, posFinish, ECC_Visibility, collisionParams);
- if (smthIsHit)
- {
- //print("Hitted: " + hitResult.Actor->GetName() + " ::: " + hitResult.Component->GetName());
- //DrawDebugLine(GetWorld(), posStart, posFinish, FColor::Green, false, 5.f, 0, 1);
- IMainActionInterface* hittedActor = Cast<IMainActionInterface>(hitResult.Actor);
- if (hittedActor)
- {
- hittedActor->mouseLeftClick(this, hitResult.Component.Get());
- }
- }
- }
- }
- void AInteractiveStaticActor::mouseLeftClick(APawn* PawnWhoClicked, UPrimitiveComponent* hitComponent)
- {
- if (hitComponent == VisibleMeshMovingPart)
- {
- if (isToogle)
- {
- isOn = !isOn;
- if (isOn)
- {
- SendMainActionSignal();
- reactGraphicallyToPress(true);
- }
- else
- {
- reactGraphicallyToPress(false);
- }
- }
- else
- {
- SendMainActionSignal();
- reactGraphicallyToPress();
- }
- }
- }
- void AInteractiveStaticActor::SendMainActionSignal()
- {
- if (IMainActionInterface* actorWithInterfaceToCall = Cast<IMainActionInterface>(ActorToCallMainAction))
- {
- actorWithInterfaceToCall->mainAction();
- }
- }
- void AInteractiveButton::ResetPositionOfButtonToDefault()
- {
- VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonDefault->GetComponentLocation());
- }
- void AInteractiveButton::reactGraphicallyToPress(bool switchingOn)
- {
- MulticastRPC_reactGraphicallyToPress(switchingOn);
- }
- void AInteractiveButton::MulticastRPC_reactGraphicallyToPress_Implementation(bool switchingOn = true)
- {
- if (!HasAuthority())
- {
- if (isToogle)
- {
- if (switchingOn)
- {
- VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonWhenPressed->GetComponentLocation());
- }
- else
- {
- VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonDefault->GetComponentLocation());
- }
- }
- else
- {
- VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonWhenPressed->GetComponentLocation());
- FTimerHandle timerHandle;
- GetWorldTimerManager().SetTimer(timerHandle, this, &AInteractiveButton::ResetPositionOfButtonToDefault, 1.0, false, 0.5);
- }
- }
- }
- void ASpawner::mainAction()
- {
- FActorSpawnParameters param = FActorSpawnParameters();
- param.bNoFail = true;
- if (WhatToSpawn)
- {
- if (bIsNotOnCooldown)
- {
- AActor* spawnedActor = GetWorld()->SpawnActor(WhatToSpawn, &GetTransform(), param);
- FTimerHandle timerHandle;
- GetWorldTimerManager().SetTimer(timerHandle, this, &ASpawner::EndOfCooldown, 1.0, false, CooldownLength);
- MulticastRPC_SetVisibilityOfTextRender(true);
- bIsNotOnCooldown = false;
- }
- }
- else
- {
- print("Class of WhatToSpawn not defined in Spawner");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment