forked from reunono/CorgiEngineExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMInControl.cs
203 lines (164 loc) · 8.84 KB
/
MMInControl.cs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using InControl;
namespace MoreMountains.Tools
{
using UnityEngine;
public class MMInControl : MoreMountains.Tools.MMSingleton<MMInControl>
{
public MMInputActions playerActions;
string saveData;
public string MMPlayerPrefsKey = "MMInControlKeyBinds";
void OnEnable()
{
// See PlayerActions.cs for this setup.
playerActions = MMInputActions.CreateWithDefaultBindings();
//playerActions.Move.OnLastInputTypeChanged += ( lastInputType ) => Debug.Log( lastInputType );
LoadBindings();
}
void OnDisable()
{
// This properly disposes of the action set and unsubscribes it from
// update events so that it doesn't do additional processing unnecessarily.
playerActions.Destroy();
}
public void SaveBindings()
{
saveData = playerActions.Save();
PlayerPrefs.SetString( MMPlayerPrefsKey, saveData );
}
void LoadBindings()
{
if (PlayerPrefs.HasKey( MMPlayerPrefsKey ))
{
saveData = PlayerPrefs.GetString( MMPlayerPrefsKey );
playerActions.Load( saveData );
}
}
void OnApplicationQuit()
{
PlayerPrefs.Save();
}
}
public class MMInputActions : PlayerActionSet
{
public PlayerAction Jump ;
public PlayerAction Swim ;
public PlayerAction Glide ;
public PlayerAction Interact ;
public PlayerAction Jetpack ;
public PlayerAction Run ;
public PlayerAction Dash ;
public PlayerAction Roll ;
public PlayerAction Fly ;
public PlayerAction Shoot ;
public PlayerAction SecondaryShoot ;
public PlayerAction Reload ;
public PlayerAction SwitchWeapon ;
public PlayerAction Pause ;
public PlayerAction Push ;
public PlayerAction SwitchCharacter;
public PlayerAction TimeControl ;
public PlayerAction Grab ;
public PlayerAction Throw ;
public PlayerAction Left;
public PlayerAction Right;
public PlayerAction Up;
public PlayerAction Down;
public PlayerAction DLeft;
public PlayerAction DRight;
public PlayerAction DUp;
public PlayerAction DDown;
public PlayerOneAxisAction MoveHorizontal;
public PlayerOneAxisAction MoveVertical;
public PlayerOneAxisAction MoveHorizontalSecondary;
public PlayerOneAxisAction MoveVerticalSecondary;
public MMInputActions()
{
Jump = CreatePlayerAction( "Player1_Jump" );
Swim = CreatePlayerAction( "Player1_Swim" );
Glide = CreatePlayerAction( "Player1_Glide" );
Interact = CreatePlayerAction( "Player1_Interact" );
Jetpack = CreatePlayerAction( "Player1_Jetpack" );
Run = CreatePlayerAction( "Player1_Run" );
Dash = CreatePlayerAction( "Player1_Dash" );
Roll = CreatePlayerAction( "Player1_Roll" );
Fly = CreatePlayerAction( "Player1_Fly" );
Shoot = CreatePlayerAction( "Player1_Shoot" );
SecondaryShoot = CreatePlayerAction( "Player1_SecondaryShoot" );
Reload = CreatePlayerAction( "Player1_Reload" );
SwitchWeapon = CreatePlayerAction( "Player1_SwitchWeapon" );
Pause = CreatePlayerAction( "Player1_Pause" );
Push = CreatePlayerAction( "Player1_Push" );
SwitchCharacter = CreatePlayerAction( "Player1_SwitchCharacter" );
TimeControl = CreatePlayerAction( "Player1_TimeControl" );
Grab = CreatePlayerAction( "Player1_Grab" );
Throw = CreatePlayerAction( "Player1_Throw" );
Left = CreatePlayerAction( "Move Left" );
Right = CreatePlayerAction( "Move Right" );
Up = CreatePlayerAction( "Move Up" );
Down = CreatePlayerAction( "Move Down" );
DLeft = CreatePlayerAction( "Alt Move Left");
DRight = CreatePlayerAction( "Alt Move Right");
DUp = CreatePlayerAction( "Alt Move Up");
DDown = CreatePlayerAction( "Alt Move Down");
MoveHorizontal = CreateOneAxisPlayerAction(Left, Right);
MoveVertical = CreateOneAxisPlayerAction(Down, Up);
MoveHorizontalSecondary = CreateOneAxisPlayerAction(DLeft, DRight);
MoveVerticalSecondary = CreateOneAxisPlayerAction(DDown, DUp);
}
public static MMInputActions CreateWithDefaultBindings()
{
var playerActions = new MMInputActions();
// How to set up mutually exclusive keyboard bindings with a modifier key.
// playerActions.Back.AddDefaultBinding( Key.Shift, Key.Tab );
// playerActions.Next.AddDefaultBinding( KeyCombo.With( Key.Tab ).AndNot( Key.Shift ) );
playerActions.Shoot.AddDefaultBinding ( InputControlType.Action3 );
playerActions.Shoot.AddDefaultBinding ( Mouse.LeftButton );
playerActions.SecondaryShoot.AddDefaultBinding (InputControlType.RightBumper);
playerActions.SwitchCharacter.AddDefaultBinding(InputControlType.Action4);
playerActions.Jump.AddDefaultBinding ( Key.Space );
playerActions.Jump.AddDefaultBinding ( InputControlType.Action1 );
playerActions.Up.AddDefaultBinding ( Key.W );
playerActions.Down.AddDefaultBinding ( Key.S );
playerActions.Left.AddDefaultBinding ( Key.A );
playerActions.Right.AddDefaultBinding ( Key.D );
playerActions.Run.AddDefaultBinding (Key.Shift);
playerActions.Run.AddDefaultBinding (InputControlType.Action3);
playerActions.Pause.AddDefaultBinding (Key.Escape);
playerActions.Pause.AddDefaultBinding (InputControlType.Start);
playerActions.Grab.AddDefaultBinding (Key.Tab);
playerActions.Throw.AddDefaultBinding (InputControlType.Back);
playerActions.Left.AddDefaultBinding ( InputControlType.LeftStickLeft );
playerActions.Right.AddDefaultBinding ( InputControlType.LeftStickRight );
playerActions.Up.AddDefaultBinding ( InputControlType.LeftStickUp );
playerActions.Down.AddDefaultBinding ( InputControlType.LeftStickDown );
playerActions.DLeft.AddDefaultBinding ( InputControlType.DPadLeft );
playerActions.DRight.AddDefaultBinding ( InputControlType.DPadRight );
playerActions.DUp.AddDefaultBinding ( InputControlType.DPadUp );
playerActions.DDown.AddDefaultBinding ( InputControlType.DPadDown );
playerActions.ListenOptions.IncludeUnknownControllers = true;
playerActions.ListenOptions.MaxAllowedBindings = 2;
playerActions.ListenOptions.MaxAllowedBindingsPerType = 2;
playerActions.ListenOptions.AllowDuplicateBindingsPerSet = true;
// playerActions.ListenOptions.UnsetDuplicateBindingsOnSet = true;
playerActions.ListenOptions.IncludeMouseButtons = true;
playerActions.ListenOptions.IncludeMouseButtons = true;
playerActions.ListenOptions.IncludeMouseScrollWheel = true;
// playerActions.ListenOptions.IncludeModifiersAsFirstClassKeys = true;
playerActions.ListenOptions.OnBindingFound = ( action, binding ) => {
if (binding == new KeyBindingSource( Key.Escape ))
{
action.StopListeningForBinding();
return false;
}
return true;
};
playerActions.ListenOptions.OnBindingAdded += ( action, binding ) => {
Debug.Log( "Binding added... " + binding.DeviceName + ": " + binding.Name );
};
playerActions.ListenOptions.OnBindingRejected += ( action, binding, reason ) => {
Debug.Log( "Binding rejected... " + reason );
};
return playerActions;
}
}
}