Vanilla_Fury

Untitled

Dec 26th, 2021
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 KB | None | 0 0
  1. void APawnWithPlanetHorizon::MouseLeftClick()
  2. {
  3.     FVector posStart = CameraFPS->GetComponentLocation();
  4.     FVector posFinish = posStart + CameraFPS->GetForwardVector() * 100;
  5.     ServerRPC_TraceAndClickActor(posStart, posFinish);
  6. }
  7.  
  8. void APawnWithPlanetHorizon::ServerRPC_TraceAndClickActor_Implementation(FVector posStart, FVector posFinish)
  9. {
  10.     if (isHoldingSmth)
  11.     {
  12.         IMainActionInterface* holdedActor = Cast<IMainActionInterface>(whatActorHolding);
  13.         holdedActor->mouseLeftClick(this, nullptr);
  14.     }
  15.     else
  16.     {
  17.         FHitResult hitResult;
  18.         FCollisionQueryParams collisionParams;
  19.         TArray<UPrimitiveComponent*> componentsToIgnore;
  20.         collisionParams.AddIgnoredActor(this);
  21.         collisionParams.bTraceComplex = false;
  22.  
  23.  
  24.         bool smthIsHit = GetWorld()->LineTraceSingleByChannel(hitResult, posStart, posFinish, ECC_Visibility, collisionParams);
  25.  
  26.         if (smthIsHit)
  27.         {
  28.             //print("Hitted: " + hitResult.Actor->GetName() + " ::: " + hitResult.Component->GetName());
  29.             //DrawDebugLine(GetWorld(), posStart, posFinish, FColor::Green, false, 5.f, 0, 1);
  30.             IMainActionInterface* hittedActor = Cast<IMainActionInterface>(hitResult.Actor);
  31.             if (hittedActor)
  32.             {
  33.                 hittedActor->mouseLeftClick(this, hitResult.Component.Get());
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. void AInteractiveStaticActor::mouseLeftClick(APawn* PawnWhoClicked, UPrimitiveComponent* hitComponent)
  40. {
  41.     if (hitComponent == VisibleMeshMovingPart)
  42.     {
  43.         if (isToogle)
  44.         {
  45.             isOn = !isOn;
  46.             if (isOn)
  47.             {
  48.                 SendMainActionSignal();
  49.                 reactGraphicallyToPress(true);
  50.             }
  51.             else
  52.             {
  53.                 reactGraphicallyToPress(false);
  54.             }
  55.         }
  56.         else
  57.         {
  58.             SendMainActionSignal();
  59.             reactGraphicallyToPress();
  60.         }
  61.  
  62.     }
  63. }
  64.  
  65. void AInteractiveStaticActor::SendMainActionSignal()
  66. {
  67.     if (IMainActionInterface* actorWithInterfaceToCall = Cast<IMainActionInterface>(ActorToCallMainAction))
  68.     {
  69.         actorWithInterfaceToCall->mainAction();
  70.     }
  71. }
  72.  
  73. void AInteractiveButton::ResetPositionOfButtonToDefault()
  74. {
  75.     VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonDefault->GetComponentLocation());
  76. }
  77.  
  78. void AInteractiveButton::reactGraphicallyToPress(bool switchingOn)
  79. {
  80.     MulticastRPC_reactGraphicallyToPress(switchingOn);
  81. }
  82.  
  83. void AInteractiveButton::MulticastRPC_reactGraphicallyToPress_Implementation(bool switchingOn = true)
  84. {
  85.     if (!HasAuthority())
  86.     {
  87.         if (isToogle)
  88.         {
  89.             if (switchingOn)
  90.             {
  91.                 VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonWhenPressed->GetComponentLocation());
  92.             }
  93.             else
  94.             {
  95.                 VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonDefault->GetComponentLocation());
  96.             }
  97.         }
  98.         else
  99.         {
  100.             VisibleMeshMovingPart->SetWorldLocation(PlaceOfButtonWhenPressed->GetComponentLocation());
  101.             FTimerHandle timerHandle;
  102.             GetWorldTimerManager().SetTimer(timerHandle, this, &AInteractiveButton::ResetPositionOfButtonToDefault, 1.0, false, 0.5);
  103.         }
  104.     }
  105. }
  106.  
  107. void ASpawner::mainAction()
  108. {
  109.     FActorSpawnParameters param = FActorSpawnParameters();
  110.     param.bNoFail = true;
  111.     if (WhatToSpawn)
  112.     {
  113.         if (bIsNotOnCooldown)
  114.         {
  115.             AActor* spawnedActor = GetWorld()->SpawnActor(WhatToSpawn, &GetTransform(), param);
  116.  
  117.             FTimerHandle timerHandle;
  118.  
  119.             GetWorldTimerManager().SetTimer(timerHandle, this, &ASpawner::EndOfCooldown, 1.0, false, CooldownLength);
  120.  
  121.             MulticastRPC_SetVisibilityOfTextRender(true);
  122.             bIsNotOnCooldown = false;
  123.         }
  124.     }
  125.     else
  126.     {
  127.         print("Class of WhatToSpawn not defined in Spawner");
  128.     }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment