1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
using System;
using InControl;
public class PlayerActions : PlayerActionSet
{
public PlayerAction Fire;
public PlayerAction Block;
public PlayerAction Jump;
public PlayerAction Left;
public PlayerAction Right;
public PlayerAction Up;
public PlayerAction Down;
public PlayerTwoAxisAction Move;
public PlayerTwoAxisAction Aim;
public PlayerAction AimLeft;
public PlayerAction AimRight;
public PlayerAction AimUp;
public PlayerAction AimDown;
public PlayerAction Start;
public PlayerActions()
{
Fire = CreatePlayerAction("Fire");
Start = CreatePlayerAction("Start");
Block = CreatePlayerAction("Block");
Jump = CreatePlayerAction("Jump");
Left = CreatePlayerAction("Move Left");
Right = CreatePlayerAction("Move Right");
Up = CreatePlayerAction("Move Up");
Down = CreatePlayerAction("Move Down");
AimLeft = CreatePlayerAction("Aim Left");
AimRight = CreatePlayerAction("Aim Right");
AimUp = CreatePlayerAction("Aim Up");
AimDown = CreatePlayerAction("Aim Down");
Move = CreateTwoAxisPlayerAction(Left, Right, Down, Up);
Aim = CreateTwoAxisPlayerAction(AimLeft, AimRight, AimDown, AimUp);
}
public static PlayerActions CreateWithKeyboardBindings()
{
PlayerActions playerActions = new PlayerActions();
playerActions.Fire.AddDefaultBinding(Mouse.LeftButton);
playerActions.Block.AddDefaultBinding(Mouse.RightButton);
playerActions.Jump.AddDefaultBinding(Key.Space);
playerActions.Up.AddDefaultBinding(Key.W);
playerActions.Down.AddDefaultBinding(Key.S);
playerActions.Left.AddDefaultBinding(Key.A);
playerActions.Right.AddDefaultBinding(Key.D);
playerActions.Start.AddDefaultBinding(Key.Return);
playerActions.ListenOptions.IncludeUnknownControllers = true;
playerActions.ListenOptions.MaxAllowedBindings = 4u;
playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
playerActions.ListenOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding)
{
if (binding == new KeyBindingSource(Key.Escape))
{
action.StopListeningForBinding();
return false;
}
return true;
};
BindingListenOptions bindingListenOptions = playerActions.ListenOptions;
bindingListenOptions.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(bindingListenOptions.OnBindingAdded, (Action<PlayerAction, BindingSource>)delegate(PlayerAction action, BindingSource binding)
{
Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name);
});
BindingListenOptions bindingListenOptions2 = playerActions.ListenOptions;
bindingListenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(bindingListenOptions2.OnBindingRejected, (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)delegate(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason)
{
Debug.Log("Binding rejected... " + reason);
});
return playerActions;
}
public static PlayerActions CreateWithControllerBindings()
{
PlayerActions playerActions = new PlayerActions();
playerActions.Fire.AddDefaultBinding(InputControlType.Action3);
playerActions.Fire.AddDefaultBinding(InputControlType.RightTrigger);
playerActions.Block.AddDefaultBinding(InputControlType.Action2);
playerActions.Block.AddDefaultBinding(InputControlType.LeftTrigger);
playerActions.Jump.AddDefaultBinding(InputControlType.Action1);
playerActions.Jump.AddDefaultBinding(InputControlType.LeftBumper);
playerActions.Jump.AddDefaultBinding(InputControlType.RightBumper);
playerActions.Start.AddDefaultBinding(InputControlType.Start);
playerActions.Left.AddDefaultBinding(InputControlType.LeftStickLeft);
playerActions.Right.AddDefaultBinding(InputControlType.LeftStickRight);
playerActions.Up.AddDefaultBinding(InputControlType.LeftStickUp);
playerActions.Down.AddDefaultBinding(InputControlType.LeftStickDown);
playerActions.AimLeft.AddDefaultBinding(InputControlType.RightStickLeft);
playerActions.AimRight.AddDefaultBinding(InputControlType.RightStickRight);
playerActions.AimUp.AddDefaultBinding(InputControlType.RightStickUp);
playerActions.AimDown.AddDefaultBinding(InputControlType.RightStickDown);
playerActions.ListenOptions.IncludeUnknownControllers = true;
playerActions.ListenOptions.MaxAllowedBindings = 4u;
playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
playerActions.ListenOptions.OnBindingFound = delegate(PlayerAction action, BindingSource binding)
{
if (binding == new KeyBindingSource(Key.Escape))
{
action.StopListeningForBinding();
return false;
}
return true;
};
BindingListenOptions bindingListenOptions = playerActions.ListenOptions;
bindingListenOptions.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(bindingListenOptions.OnBindingAdded, (Action<PlayerAction, BindingSource>)delegate(PlayerAction action, BindingSource binding)
{
Debug.Log("Binding added... " + binding.DeviceName + ": " + binding.Name);
});
BindingListenOptions bindingListenOptions2 = playerActions.ListenOptions;
bindingListenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(bindingListenOptions2.OnBindingRejected, (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)delegate(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason)
{
Debug.Log("Binding rejected... " + reason);
});
return playerActions;
}
}
|