Documentation for the Unreal C++ Plugin
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 else if (DeviceName == "Monado") { return EPlatform::LENOVO_VRX; }
25
26 // default to quest, unless compiling on windows
27 // this is for unknown headsets like the VRX
28#if PLATFORM_WINDOWS
29 return EPlatform::WINDOWS;
30#else
31 return EPlatform::QUEST;
32#endif
33}
34
36{
37 UInputSettings* InputSettings = UInputSettings::GetInputSettings();
38 TArray<FName> ActionNames;
39 InputSettings->GetActionNames(ActionNames);
40 for (const auto& ActionName : ActionNames)
41 {
42 TArray<FInputActionKeyMapping> ActionMappings;
43 InputSettings->GetActionMappingByName(ActionName,ActionMappings);
44 for (const auto& Mapping : ActionMappings)
45 {
46 InputSettings->RemoveActionMapping(Mapping);
47 }
48 }
49
50 TArray<FName> AxisNames;
51 InputSettings->GetAxisNames(AxisNames);
52 for (const auto& AxisName : AxisNames)
53 {
54 TArray<FInputAxisKeyMapping> AxisMappings;
55 InputSettings->GetAxisMappingByName(AxisName,AxisMappings);
56 for (const auto& Mapping : AxisMappings)
57 {
58 InputSettings->RemoveAxisMapping(Mapping);
59 }
60 }
61
62 InputSettings->ForceRebuildKeymaps();
63}
64
65void UPixoVRInputAdapter::AddMappings(const TArray<FPlatformInputSettings*>& CustomMappings)
66{
67 UInputSettings* InputSettings = UInputSettings::GetInputSettings();
68 for (const auto CustomMapping : CustomMappings)
69 {
70 for(const TPair<EPlatform, FKey>& Input : CustomMapping->InputMapping)
71 {
72 FInputActionKeyMapping InputKeyMapping;
73 InputKeyMapping.Key = Input.Value;
74 InputKeyMapping.ActionName = CustomMapping->InputName;
75 InputSettings->AddActionMapping(InputKeyMapping);
76 }
77 for(const FAxisKeyData& AxisInput : CustomMapping->AxisInputMapping)
78 {
79 for(const FInputAxisKeyMapping& InputKey : AxisInput.InputKeys)
80 {
81 FInputAxisKeyMapping InputKeyMapping;
82 InputKeyMapping.Key = InputKey.Key;
83 InputKeyMapping.Scale = InputKey.Scale;
84 InputKeyMapping.AxisName = CustomMapping->InputName;
85 InputSettings->AddAxisMapping(InputKeyMapping);
86 }
87 }
88 }
89
90 InputSettings->SaveKeyMappings();
91 const FString DefaultInputFilePath = FPaths::SourceConfigDir() + "DefaultInput.ini";
92 InputSettings->SaveConfig(CPF_Config, *DefaultInputFilePath);
93 InputSettings->ForceRebuildKeymaps();
94}
EPlatform
Enum representing different platforms.
EPlatform GetPlatformType() const
void AddMappings(const TArray< FPlatformInputSettings * > &CustomMappings)
void ResolveMappings(const UDataTable *MappingsTable)
Structure representing axis key data for different platforms.