Assuming that you wish to change which function is called for different joystick inputs based on a configuration file then you could use something like the code shown below. You might want to try a more elegant solution if there are a lot of alternatives since otherwise the
if then else if
will become confusing to read and very repetitive.
{
"button1": "FunctionA",
"button2": "FunctionB"
}
And then :
using Newtonsoft.Json;
using System.IO;
void FunctionA()
{
Console.WriteLine("Function A is called.");
}
void FunctionB()
{
Console.WriteLine("Function B is called.");
}
var config = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("config.json"));
while (true)
{
joystick.Poll();
var datas = joystick.GetBufferedData();
foreach (var state in datas)
{
if (state.Offset == JoystickOffset.Buttons0 && state.Value != 0)
{
if (config["button1"] == "FunctionA")
FunctionA();
else if (config["button1"] == "FunctionB")
FunctionB();
}
else if (state.Offset == JoystickOffset.Buttons1 && state.Value != 0)
{
if (config["button2"] == "FunctionA")
FunctionA();
else if (config["button2"] == "FunctionB")
FunctionB();
}
}
}