Key Binding
Standard
Inherit your ControllerPlayer to set the binding.
Joysticks
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
public class Kjoy : JoystickPlayer {
public Kjoy(Joystick joy) : base(joy) {
KeyBridge = new KeyBridge<int, ActionType>(
0,
1,
6
).Actions(
ActionType.Main,
ActionType.Secondary,
ActionType.ControllerStatus
);
}
}
}
Keyboards
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
public class Kboard_full : KeyboardPlayer {
public Kboard_full(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.A,
KeyCode.Z
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.UpArrow, KeyCode.RightArrow, KeyCode.DownArrow, KeyCode.LeftArrow);
}
}
}
From a user config
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
public class Kjoy : JoystickPlayer {
public Kjoy(Joystick joy) : base(joy) {
KeyBridge = KeyBridge<int, ActionType>.FromStorage("Kjoy" + joy.Id);
if (KeyBridge == null) {
KeyBridge = new KeyBridge<int, ActionType>(
0,
1,
6
).Actions(
ActionType.Main,
ActionType.Secondary,
ActionType.ControllerStatus
);
}
}
/// <summary>
/// Update and save actions
/// </summary>
public void SaveActions(ActionType[] actions) {
KeyBridge = new KeyBridge<int, ActionType>(0, 1, 6).Actions(actions);
KeyBridge.Save("Kjoy" + JoystickId);
}
}
}
Disable/Enable button
Add an event to disable or enable gamepad.
Probably not the best way (in this class we only want a code related to key binding), but easy.
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
public class Kjoy : JoystickPlayer {
float _sleepStatusDelay = 0f;
public Kjoy(Joystick joy) : base(joy) {
KeyBridge = new KeyBridge<int, ActionType>(
0,
1,
6
).Actions(
ActionType.Main,
ActionType.Secondary,
ActionType.ControllerStatus
);
joy.OnButtonPressed += b => {
if (b == 6) {
if (_sleepStatusDelay + 3f > Time.fixedTime) {
return;
}
if (!joy.Asleep) {
if (Player != null) {
_sleepStatusDelay = Time.fixedTime;
joy.Sleep();
} else {
_sleepStatusDelay = Time.fixedTime;
PlayersManager.Instance.AddController(this);
}
}
}
};
}
}
}
Multiple keyboard
There are more than 1 player on the keyboard.
using EODE.Wonderland;
using UnityEngine;
namespace MyProject {
#region 1 kb
public class Kboard_full : KeyboardPlayer {
public Kboard_full(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.A,
KeyCode.Z
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.UpArrow, KeyCode.RightArrow, KeyCode.DownArrow, KeyCode.LeftArrow);
}
}
#endregion
#region 2 kb
public class Kboard_2_left : KeyboardPlayer {
public Kboard_2_left(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.A,
KeyCode.Z
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.U, KeyCode.K, KeyCode.J, KeyCode.H);
}
}
public class Kboard_2_right : KeyboardPlayer {
public Kboard_2_right(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.LeftArrow,
KeyCode.DownArrow
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.Keypad8, KeyCode.Keypad6, KeyCode.Keypad5, KeyCode.Keypad4);
}
}
#endregion
#region 3 kb
public class Kboard_3_left : KeyboardPlayer {
public Kboard_3_left(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.A,
KeyCode.Z
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.R, KeyCode.G, KeyCode.F, KeyCode.D);
}
}
public class Kboard_3_center : KeyboardPlayer {
public Kboard_3_center(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.I,
KeyCode.O
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.RightBracket, KeyCode.Backslash, KeyCode.BackQuote, KeyCode.M);
}
}
public class Kboard_3_right : KeyboardPlayer {
public Kboard_3_right(int keyboardId) : base(new Keyboard(keyboardId)) {
KeyBridge = new KeyBridge<KeyCode, ActionType>(
KeyCode.LeftArrow,
KeyCode.DownArrow
).Actions(
ActionType.Main,
ActionType.Secondary
);
Keyboard.Arrows(KeyCode.Keypad8, KeyCode.Keypad6, KeyCode.Keypad5, KeyCode.Keypad4);
}
}
#endregion
}