|
2 | 2 | using SFS.Input; |
3 | 3 | using SFS.World; |
4 | 4 | using System; |
| 5 | +using UnityEngine; |
5 | 6 |
|
6 | 7 | namespace ModLoader.Helpers |
7 | 8 | { |
8 | 9 | /// <summary> |
9 | 10 | /// Use this class if you need add key events. |
10 | 11 | /// </summary> |
11 | | - static class KeybindingHelper |
| 12 | + public class KeybindingHelper |
12 | 13 | { |
13 | 14 |
|
14 | 15 | /// <summary> |
15 | 16 | /// Add onKeyDown on world and map |
16 | 17 | /// </summary> |
17 | 18 | /// <param name="key">key to trigger the event</param> |
18 | 19 | /// <param name="action"> is executed when the event occurs</param> |
| 20 | + /// <example> |
| 21 | + /// KeybindingHelper.AddOnKeyDownWorld(Keycode.T, this.myMethod); |
| 22 | + /// </example> |
19 | 23 | public static void AddOnKeyDownWorld(I_Key key, Action action) |
20 | 24 | { |
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"); |
23 | 32 | } |
24 | 33 |
|
25 | 34 | /// <summary> |
26 | 35 | /// Add onKeyDown on builder |
27 | 36 | /// </summary> |
28 | 37 | /// <param name="key">key to trigger the event</param> |
29 | 38 | /// <param name="action"> is executed when the event occurs</param> |
| 39 | + /// <example> |
| 40 | + /// KeybindingHelper.AddOnKeyDownBuilder(Keycode.T, this.myMethod); |
| 41 | + /// </example> |
30 | 42 | public static void AddOnKeyDownBuilder(I_Key key, Action action) |
31 | 43 | { |
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"); |
33 | 50 | } |
34 | 51 | } |
35 | 52 | } |
0 commit comments