unitysamples / LyraStarterGame /Source /LyraGame /UI /Common /LyraBoundActionButton.cpp
Alexhas2's picture
Add files using upload-large-folder tool
7fd553e verified
// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraBoundActionButton.h"
#include "CommonInputSubsystem.h"
#include "CommonInputTypeEnum.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraBoundActionButton)
class UCommonButtonStyle;
void ULyraBoundActionButton::NativeConstruct()
{
Super::NativeConstruct();
if (UCommonInputSubsystem* InputSubsystem = GetInputSubsystem())
{
InputSubsystem->OnInputMethodChangedNative.AddUObject(this, &ThisClass::HandleInputMethodChanged);
HandleInputMethodChanged(InputSubsystem->GetCurrentInputType());
}
}
void ULyraBoundActionButton::HandleInputMethodChanged(ECommonInputType NewInputMethod)
{
TSubclassOf<UCommonButtonStyle> NewStyle = nullptr;
if (NewInputMethod == ECommonInputType::Gamepad)
{
NewStyle = GamepadStyle;
}
else if (NewInputMethod == ECommonInputType::Touch)
{
NewStyle = TouchStyle;
}
else
{
NewStyle = KeyboardStyle;
}
if (NewStyle)
{
SetStyle(NewStyle);
}
}