Download LyraStarterGame/Source/LyraGame/UI/LyraJoystickWidget.cpp from Alexhas2/unitysamples: direct link, hf CLI and curl.
- Browser
- Download file 3.3 kB
-
https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/UI/LyraJoystickWidget.cpp
- Command line
-
hf download hf://datasets/Alexhas2/unitysamples/LyraStarterGame/Source/LyraGame/UI/LyraJoystickWidget.cpp
-
curl -L -o LyraJoystickWidget.cpp https://huggingface.co/datasets/Alexhas2/unitysamples/resolve/main/LyraStarterGame/Source/LyraGame/UI/LyraJoystickWidget.cpp
3.3 kB
| // Copyright Epic Games, Inc. All Rights Reserved. | |
| ULyraJoystickWidget::ULyraJoystickWidget(const FObjectInitializer& ObjectInitializer) | |
| : Super(ObjectInitializer) | |
| { | |
| SetConsumePointerInput(true); | |
| } | |
| FReply ULyraJoystickWidget::NativeOnTouchStarted(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) | |
| { | |
| Super::NativeOnTouchStarted(InGeometry, InGestureEvent); | |
| TouchOrigin = InGestureEvent.GetScreenSpacePosition(); | |
| FReply Reply = FReply::Handled(); | |
| if (!HasMouseCaptureByUser(InGestureEvent.GetUserIndex(), InGestureEvent.GetPointerIndex())) | |
| { | |
| Reply.CaptureMouse(GetCachedWidget().ToSharedRef()); | |
| } | |
| return Reply; | |
| } | |
| FReply ULyraJoystickWidget::NativeOnTouchMoved(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) | |
| { | |
| Super::NativeOnTouchMoved(InGeometry, InGestureEvent); | |
| HandleTouchDelta(InGeometry, InGestureEvent); | |
| FReply Reply = FReply::Handled(); | |
| if (!HasMouseCaptureByUser(InGestureEvent.GetUserIndex(), InGestureEvent.GetPointerIndex())) | |
| { | |
| Reply.CaptureMouse(GetCachedWidget().ToSharedRef()); | |
| } | |
| return Reply; | |
| } | |
| FReply ULyraJoystickWidget::NativeOnTouchEnded(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) | |
| { | |
| StopInputSimulation(); | |
| return FReply::Handled().ReleaseMouseCapture(); | |
| } | |
| void ULyraJoystickWidget::NativeOnMouseLeave(const FPointerEvent& InMouseEvent) | |
| { | |
| Super::NativeOnMouseLeave(InMouseEvent); | |
| StopInputSimulation(); | |
| } | |
| void ULyraJoystickWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) | |
| { | |
| Super::NativeTick(MyGeometry, InDeltaTime); | |
| if (!CommonVisibilityBorder || CommonVisibilityBorder->IsVisible()) | |
| { | |
| // Move the inner stick icon around with the vector | |
| if (JoystickForeground && JoystickBackground) | |
| { | |
| JoystickForeground->SetRenderTranslation( | |
| (bNegateYAxis ? FVector2D(1.0f, -1.0f) : FVector2D(1.0f)) * | |
| StickVector * | |
| (JoystickBackground->GetDesiredSize() * 0.5f) | |
| ); | |
| } | |
| InputKeyValue2D(StickVector); | |
| } | |
| } | |
| void ULyraJoystickWidget::HandleTouchDelta(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) | |
| { | |
| const FVector2D& ScreenSpacePos = InGestureEvent.GetScreenSpacePosition(); | |
| // The center of the geo locally is just its size | |
| FVector2D LocalStickCenter = InGeometry.GetAbsoluteSize(); | |
| FVector2D ScreenSpaceStickCenter = InGeometry.LocalToAbsolute(LocalStickCenter); | |
| // Get the offset from the origin | |
| FVector2D MoveStickOffset = (ScreenSpacePos - ScreenSpaceStickCenter); | |
| if (bNegateYAxis) | |
| { | |
| MoveStickOffset *= FVector2D(1.0f, -1.0f); | |
| } | |
| FVector2D MoveStickDir = FVector2D::ZeroVector; | |
| float MoveStickLength = 0.0f; | |
| MoveStickOffset.ToDirectionAndLength(MoveStickDir, MoveStickLength); | |
| MoveStickLength = FMath::Min(MoveStickLength, StickRange); | |
| MoveStickOffset = MoveStickDir * MoveStickLength; | |
| StickVector = MoveStickOffset / StickRange; | |
| } | |
| void ULyraJoystickWidget::StopInputSimulation() | |
| { | |
| TouchOrigin = FVector2D::ZeroVector; | |
| StickVector = FVector2D::ZeroVector; | |
| } | |