Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 0b0babd

Browse files
committed
Fix KeybindingHelper accessibillity
1 parent a4099bd commit 0b0babd

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

ModLoader/Helpers/KeybindingHelper.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,51 @@
22
using SFS.Input;
33
using SFS.World;
44
using System;
5+
using UnityEngine;
56

67
namespace ModLoader.Helpers
78
{
89
/// <summary>
910
/// Use this class if you need add key events.
1011
/// </summary>
11-
static class KeybindingHelper
12+
public class KeybindingHelper
1213
{
1314

1415
/// <summary>
1516
/// Add onKeyDown on world and map
1617
/// </summary>
1718
/// <param name="key">key to trigger the event</param>
1819
/// <param name="action"> is executed when the event occurs</param>
20+
/// <example>
21+
/// KeybindingHelper.AddOnKeyDownWorld(Keycode.T, this.myMethod);
22+
/// </example>
1923
public static void AddOnKeyDownWorld(I_Key key, Action action)
2024
{
21-
GameManager.main.world_Input.keysNode.AddOnKeyDown(key, action);
22-
GameManager.main.map_Input.keysNode.AddOnKeyDown(key, action);
25+
if (GameManager.main != null)
26+
{
27+
GameManager.main.world_Input.keysNode.AddOnKeyDown(key, action);
28+
GameManager.main.map_Input.keysNode.AddOnKeyDown(key, action);
29+
return;
30+
}
31+
Debug.LogError("This method only works in World Scene");
2332
}
2433

2534
/// <summary>
2635
/// Add onKeyDown on builder
2736
/// </summary>
2837
/// <param name="key">key to trigger the event</param>
2938
/// <param name="action"> is executed when the event occurs</param>
39+
/// <example>
40+
/// KeybindingHelper.AddOnKeyDownBuilder(Keycode.T, this.myMethod);
41+
/// </example>
3042
public static void AddOnKeyDownBuilder(I_Key key, Action action)
3143
{
32-
BuildManager.main.build_Input.keysNode.AddOnKeyDown(key, action);
44+
if (BuildManager.main != null)
45+
{
46+
BuildManager.main.build_Input.keysNode.AddOnKeyDown(key, action);
47+
return;
48+
}
49+
Debug.LogError("This method only works in Builder Scene");
3350
}
3451
}
3552
}

0 commit comments

Comments
 (0)