Пример #1
0
FMatrix FSCSEditorViewportClient::GetWidgetCoordSystem() const
{
	FMatrix Matrix = FMatrix::Identity;
	if( GetWidgetCoordSystemSpace() == COORD_Local )
	{
		AActor* PreviewActor = GetPreviewActor();
		auto BlueprintEditor = BlueprintEditorPtr.Pin();
		if (PreviewActor && BlueprintEditor.IsValid())
		{
			TArray<FSCSEditorTreeNodePtrType> SelectedNodes = BlueprintEditor->GetSelectedSCSEditorTreeNodes();
			if(SelectedNodes.Num() > 0)
			{
				const auto SelectedNode = SelectedNodes.Last();
				USceneComponent* SceneComp = SelectedNode.IsValid() ? Cast<USceneComponent>(SelectedNode->FindComponentInstanceInActor(PreviewActor)) : NULL;
				if( SceneComp )
				{
					TSharedPtr<ISCSEditorCustomization> Customization = BlueprintEditor->CustomizeSCSEditor(SceneComp);
					FMatrix CustomTransform;
					if(Customization.IsValid() && Customization->HandleGetWidgetTransform(SceneComp, CustomTransform))
					{
						Matrix = CustomTransform;
					}					
					else
					{
						Matrix = FRotationMatrix( SceneComp->GetComponentRotation() );
					}
				}
			}
		}
	}

	if(!Matrix.Equals(FMatrix::Identity))
	{
		Matrix.RemoveScaling();
	}

	return Matrix;
}
Пример #2
0
void ALD35Character::OnFire()
{ 
	if (IsInAlternateForm)
	{
		FVector trgPos = FindComponentByClass<UCameraComponent>()->GetComponentLocation() + GetActorRotation().RotateVector(FVector(140, 0, 0));

		//DrawDebugSphere(GetWorld(), trgPos, 150, 8, FColor::Red, false, 0.5f);

		TArray<FOverlapResult> res;

		if (GetWorld()->OverlapMultiByChannel(res, trgPos, FQuat::Identity, ECollisionChannel::ECC_WorldDynamic, FCollisionShape::MakeSphere(150)))
		{
			for (auto& a : res)
			{
				if (a.Actor.Get() && a.Actor != this)
				{
					a.Actor->TakeDamage(1, FDamageEvent(), this->GetController(), this);
				}
			}
		}

		if (FMath::Rand() % 3 == 0)
		{
			UGameplayStatics::PlaySoundAtLocation(this, TransformSound, GetActorLocation());
		}

		return;
	}

	// try and fire a projectile
	if (ProjectileClass != NULL)
	{
		USceneComponent* cam = FindComponentByClass<UCameraComponent>();

		if (cam)
		{
			FRotator SpawnRotation = cam->GetComponentRotation();
			FVector SpawnLocation = cam->GetComponentLocation();

			TArray<UActorComponent*> childComponents = GetComponentsByTag(USceneComponent::StaticClass(), "Gun");

			for (auto& b : childComponents)
			{
				if (auto a = Cast<USceneComponent>(b))
				{
					if (a->ComponentHasTag(TEXT("Gun")))
					{
						SpawnRotation = a->GetComponentRotation();
						SpawnLocation = a->GetComponentLocation();

						//UE_LOG(LogTemp, Display, TEXT("NM %s %s %s %s %s"), *a->GetName(), *cam->GetName(), *SpawnLocation.ToString(), *cam->GetComponentLocation().ToString(), *a->GetRelativeTransform().ToString());
					}
				}
			}

			UWorld* const World = GetWorld();
			if (World != NULL)
			{
				// spawn the projectile at the muzzle

				FActorSpawnParameters params;
				params.Instigator = this;

				World->SpawnActor<ALD35Projectile>(ProjectileClass, SpawnLocation, SpawnRotation, params);
			}
		}
	}

	// try and play the sound if specified
	if (FireSound != NULL)
	{
		UGameplayStatics::PlaySoundAtLocation(this, ShootCrossbowSound, GetActorLocation());
	}

}