A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
PixoVRInputAdapter.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "HeadMountedDisplayFunctionLibrary.h"
5#include "GameFramework/InputSettings.h"
6
7void UPixoVRInputAdapter::ResolveMappings(const UDataTable* MappingsTable)
8{
9 TArray<FPlatformInputSettings*> CustomMappings;
10 MappingsTable->GetAllRows(TEXT("[UPixoVRInputAdapter::ResolveMappings()] Expected RowStruct for this DT : FPlatformInputSettings"),CustomMappings);
12
13 AddMappings(CustomMappings);
14}
15
17{
18 const auto DeviceName = UHeadMountedDisplayFunctionLibrary::GetHMDDeviceName();
19
20 if (DeviceName == "SteamVR") { return EPlatform::VIVE; }
21 else if (DeviceName == "OculusHMD") { return EPlatform::QUEST; }
22 else if (DeviceName == "WaveVR") { return EPlatform::FOCUS_PLUS; }
23 else if (DeviceName == "PicoVR") { return EPlatform::PICO_NEO_2; }
24 return EPlatform::WINDOWS;
25}
26
28{
29 UInputSettings* InputSettings = UInputSettings::GetInputSettings();
30 TArray<FName> ActionNames;
31 InputSettings->GetActionNames(ActionNames);
32 for (const auto& ActionName : ActionNames)
33 {
34 TArray<FInputActionKeyMapping> ActionMappings;
35 InputSettings->GetActionMappingByName(ActionName,ActionMappings);
36 for (const auto& Mapping : ActionMappings)
37 {
38 InputSettings->RemoveActionMapping(Mapping);
39 }
40 }
41
42 TArray<FName> AxisNames;
43 InputSettings->GetAxisNames(AxisNames);
44 for (const auto& AxisName : AxisNames)
45 {
46 TArray<FInputAxisKeyMapping> AxisMappings;
47 InputSettings->GetAxisMappingByName(AxisName,AxisMappings);
48 for (const auto& Mapping : AxisMappings)
49 {
50 InputSettings->RemoveAxisMapping(Mapping);
51 }
52 }
53
54 InputSettings->ForceRebuildKeymaps();
55}
56
57void UPixoVRInputAdapter::AddMappings(const TArray<FPlatformInputSettings*>& CustomMappings)
58{
59 UInputSettings* InputSettings = UInputSettings::GetInputSettings();
60 for (const auto CustomMapping : CustomMappings)
61 {
62 for(const TPair<EPlatform, FKey>& Input : CustomMapping->InputMapping)
63 {
64 FInputActionKeyMapping InputKeyMapping;
65 InputKeyMapping.Key = Input.Value;
66 InputKeyMapping.ActionName = CustomMapping->InputName;
67 InputSettings->AddActionMapping(InputKeyMapping);
68 }
69 for(const FAxisKeyData& AxisInput : CustomMapping->AxisInputMapping)
70 {
71 for(const FInputAxisKeyMapping& InputKey : AxisInput.InputKeys)
72 {
73 FInputAxisKeyMapping InputKeyMapping;
74 InputKeyMapping.Key = InputKey.Key;
75 InputKeyMapping.Scale = InputKey.Scale;
76 InputKeyMapping.AxisName = CustomMapping->InputName;
77 InputSettings->AddAxisMapping(InputKeyMapping);
78 }
79 }
80 }
81
82 InputSettings->SaveKeyMappings();
83 const FString DefaultInputFilePath = FPaths::SourceConfigDir() + "DefaultInput.ini";
84 InputSettings->SaveConfig(CPF_Config, *DefaultInputFilePath);
85 InputSettings->ForceRebuildKeymaps();
86}
EPlatform
Enum representing different platforms.
TArray< FInputAxisKeyMapping > AxisMappings
EPlatform GetPlatformType() const
void AddMappings(const TArray< FPlatformInputSettings * > &CustomMappings)
void ResolveMappings(const UDataTable *MappingsTable)
Structure representing axis key data for different platforms.