net.dreditor.input 0.0.0-stage → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.attestation.p7m +0 -0
- package/AnyInputDetector.cs +132 -0
- package/AnyInputDetector.cs.meta +2 -0
- package/DREditor.Input.asmdef +18 -0
- package/DREditor.Input.asmdef.meta +7 -0
- package/IInputManager.cs +51 -0
- package/IInputManager.cs.meta +2 -0
- package/PlayerInputHandler.cs +307 -0
- package/PlayerInputHandler.cs.meta +11 -0
- package/Samples~/Player_Input_Handler.prefab +135 -0
- package/Samples~/Player_Input_Handler.prefab.meta +7 -0
- package/Samples~/Set_Scheme_From_Device.prefab +46 -0
- package/Samples~/Set_Scheme_From_Device.prefab.meta +7 -0
- package/SetSchemeFromDevice.cs +146 -0
- package/SetSchemeFromDevice.cs.meta +11 -0
- package/package.json +38 -4
- package/package.json.meta +7 -0
- package/README.md +0 -3
package/.attestation.p7m
ADDED
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using UnityEngine;
|
|
3
|
+
using UnityEngine.InputSystem;
|
|
4
|
+
using UnityEngine.InputSystem.Controls;
|
|
5
|
+
using UnityEngine.InputSystem.LowLevel;
|
|
6
|
+
|
|
7
|
+
namespace DREditor.Input
|
|
8
|
+
{
|
|
9
|
+
/// <summary>
|
|
10
|
+
///
|
|
11
|
+
/// </summary>
|
|
12
|
+
public abstract class AnyInputDetector : MonoBehaviour
|
|
13
|
+
{
|
|
14
|
+
/// <summary>
|
|
15
|
+
///
|
|
16
|
+
/// </summary>
|
|
17
|
+
protected InputEventPtr eventPtr;
|
|
18
|
+
|
|
19
|
+
/// <summary>
|
|
20
|
+
///
|
|
21
|
+
/// </summary>
|
|
22
|
+
protected InputDevice device;
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
///
|
|
26
|
+
/// </summary>
|
|
27
|
+
protected ButtonControl currentControl;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
///
|
|
32
|
+
/// </summary>
|
|
33
|
+
/// <remarks></remarks>
|
|
34
|
+
public virtual void Subscribe() => InputSystem.onEvent += OnAnyInputNoticed;
|
|
35
|
+
|
|
36
|
+
/// <summary>
|
|
37
|
+
///
|
|
38
|
+
/// </summary>
|
|
39
|
+
/// <remarks></remarks>
|
|
40
|
+
public virtual void Unsubscribe() => InputSystem.onEvent -= OnAnyInputNoticed;
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
///
|
|
44
|
+
/// </summary>
|
|
45
|
+
/// <param name="eventPtr"></param>
|
|
46
|
+
/// <param name="device"></param>
|
|
47
|
+
protected virtual void OnAnyInputNoticed(InputEventPtr eventPtr, InputDevice device)
|
|
48
|
+
{
|
|
49
|
+
InitializeInputData(eventPtr, device);
|
|
50
|
+
|
|
51
|
+
CheckNoticedKey();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
///
|
|
56
|
+
/// </summary>
|
|
57
|
+
/// <param name="eventPtr"></param>
|
|
58
|
+
/// <param name="device"></param>
|
|
59
|
+
protected virtual void InitializeInputData(InputEventPtr eventPtr, InputDevice device)
|
|
60
|
+
{
|
|
61
|
+
this.eventPtr = eventPtr;
|
|
62
|
+
|
|
63
|
+
this.device = device;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// <summary>
|
|
67
|
+
///
|
|
68
|
+
/// </summary>
|
|
69
|
+
protected virtual void CheckNoticedKey()
|
|
70
|
+
{
|
|
71
|
+
if (ValidKeyNoticed())
|
|
72
|
+
OnInputsDetected();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// <summary>
|
|
76
|
+
///
|
|
77
|
+
/// </summary>
|
|
78
|
+
/// <returns></returns>
|
|
79
|
+
protected virtual bool ValidKeyNoticed() => eventPtr.IsA<StateEvent>() || eventPtr.IsA<DeltaStateEvent>();
|
|
80
|
+
|
|
81
|
+
/// <summary>
|
|
82
|
+
///
|
|
83
|
+
/// </summary>
|
|
84
|
+
protected virtual void OnInputsDetected()
|
|
85
|
+
{
|
|
86
|
+
for (var i = 0; i < device.allControls.Count; ++i)
|
|
87
|
+
if (AssignCurrentControlInvalid(device.allControls[i], out currentControl))
|
|
88
|
+
continue;
|
|
89
|
+
else if (FoundValidInput())
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// <summary>
|
|
94
|
+
///
|
|
95
|
+
/// </summary>
|
|
96
|
+
/// <returns></returns>
|
|
97
|
+
protected virtual bool FoundValidInput()
|
|
98
|
+
{
|
|
99
|
+
bool result = CurrentControlIsValid();
|
|
100
|
+
|
|
101
|
+
if (result)
|
|
102
|
+
OnValidInputFound();
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// <summary>
|
|
108
|
+
///
|
|
109
|
+
/// </summary>
|
|
110
|
+
/// <returns></returns>
|
|
111
|
+
protected virtual bool CurrentControlIsValid() =>
|
|
112
|
+
currentControl.ReadValueFromEvent(eventPtr, out var value) && value >= 1;
|
|
113
|
+
|
|
114
|
+
/// <summary>
|
|
115
|
+
///
|
|
116
|
+
/// </summary>
|
|
117
|
+
protected abstract void OnValidInputFound();
|
|
118
|
+
|
|
119
|
+
/// <summary>
|
|
120
|
+
///
|
|
121
|
+
/// </summary>
|
|
122
|
+
/// <param name="control"></param>
|
|
123
|
+
/// <param name="buttonControl"></param>
|
|
124
|
+
/// <returns></returns>
|
|
125
|
+
protected virtual bool AssignCurrentControlInvalid(InputControl control, out ButtonControl buttonControl)
|
|
126
|
+
{
|
|
127
|
+
buttonControl = control as ButtonControl;
|
|
128
|
+
|
|
129
|
+
return buttonControl == null || buttonControl.synthetic || buttonControl.noisy;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DREditor.Input",
|
|
3
|
+
"rootNamespace": "",
|
|
4
|
+
"references": [
|
|
5
|
+
"Unity.InputSystem",
|
|
6
|
+
"DREditor",
|
|
7
|
+
"DREditor.Controls"
|
|
8
|
+
],
|
|
9
|
+
"includePlatforms": [],
|
|
10
|
+
"excludePlatforms": [],
|
|
11
|
+
"allowUnsafeCode": false,
|
|
12
|
+
"overrideReferences": false,
|
|
13
|
+
"precompiledReferences": [],
|
|
14
|
+
"autoReferenced": true,
|
|
15
|
+
"defineConstraints": [],
|
|
16
|
+
"versionDefines": [],
|
|
17
|
+
"noEngineReferences": false
|
|
18
|
+
}
|
package/IInputManager.cs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using UnityEngine.InputSystem;
|
|
3
|
+
|
|
4
|
+
namespace DREditor.Input
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
///
|
|
8
|
+
/// </summary>
|
|
9
|
+
public interface IInputManager
|
|
10
|
+
{
|
|
11
|
+
/// <summary>
|
|
12
|
+
///
|
|
13
|
+
/// </summary>
|
|
14
|
+
void Enable();
|
|
15
|
+
|
|
16
|
+
/// <summary>
|
|
17
|
+
///
|
|
18
|
+
/// </summary>
|
|
19
|
+
void Disable();
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
///
|
|
23
|
+
/// </summary>
|
|
24
|
+
/// <returns></returns>
|
|
25
|
+
bool UsingGamepadScheme();
|
|
26
|
+
|
|
27
|
+
/// <summary>
|
|
28
|
+
///
|
|
29
|
+
/// </summary>
|
|
30
|
+
/// <param name="device"></param>
|
|
31
|
+
void SetSchemeByDevice(InputDevice device);
|
|
32
|
+
|
|
33
|
+
/// <summary>
|
|
34
|
+
///
|
|
35
|
+
/// </summary>
|
|
36
|
+
/// <returns></returns>
|
|
37
|
+
string GetCurrentScheme();
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
///
|
|
41
|
+
/// </summary>
|
|
42
|
+
/// <returns></returns>
|
|
43
|
+
InputAction GetLeave();
|
|
44
|
+
|
|
45
|
+
/// <summary>
|
|
46
|
+
///
|
|
47
|
+
/// </summary>
|
|
48
|
+
/// <returns></returns>
|
|
49
|
+
InputAction GetCancel();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Services;
|
|
3
|
+
using System;
|
|
4
|
+
using System.Linq;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.InputSystem;
|
|
7
|
+
|
|
8
|
+
namespace DREditor.Input
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
///
|
|
12
|
+
/// </summary>
|
|
13
|
+
[DefaultExecutionOrder(-1)]
|
|
14
|
+
[ClassHeader(nameof(ServiceHolder<IInputManager>) + " for type: " + nameof(IInputManager) +
|
|
15
|
+
"\n\n")]
|
|
16
|
+
public class PlayerInputHandler : ServiceHolder<IInputManager>, IInputManager
|
|
17
|
+
{
|
|
18
|
+
/// <summary>
|
|
19
|
+
///
|
|
20
|
+
/// </summary>
|
|
21
|
+
[Tooltip("")]
|
|
22
|
+
[SerializeField] protected InputActionAsset controls = null;
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
///
|
|
26
|
+
/// </summary>
|
|
27
|
+
[Tooltip("")]
|
|
28
|
+
[SerializeField] protected InputActionReference cancel = null;
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
///
|
|
32
|
+
/// </summary>
|
|
33
|
+
[Tooltip("")]
|
|
34
|
+
[SerializeField] protected InputActionReference leave = null;
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/// <summary>
|
|
38
|
+
///
|
|
39
|
+
/// </summary>
|
|
40
|
+
[Header("")]
|
|
41
|
+
[Divider]
|
|
42
|
+
[Tooltip("")]
|
|
43
|
+
[SerializeField] protected bool debugInputControls = false;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/// <summary>
|
|
47
|
+
///
|
|
48
|
+
/// </summary>
|
|
49
|
+
[Header("")]
|
|
50
|
+
[Divider]
|
|
51
|
+
[Tooltip("")]
|
|
52
|
+
[SerializeField] protected string keyboardScheme = "Keyboard&Mouse";
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
///
|
|
56
|
+
/// </summary>
|
|
57
|
+
[Tooltip("")]
|
|
58
|
+
[SerializeField] protected string gamepadScheme = "Gamepad";
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
///
|
|
63
|
+
/// </summary>
|
|
64
|
+
/// <remarks></remarks>
|
|
65
|
+
protected DRControls Actions;
|
|
66
|
+
|
|
67
|
+
/// <summary>
|
|
68
|
+
///
|
|
69
|
+
/// </summary>
|
|
70
|
+
protected PlayerInput playerInput;
|
|
71
|
+
|
|
72
|
+
/// <summary>
|
|
73
|
+
///
|
|
74
|
+
/// </summary>
|
|
75
|
+
protected bool active = false;
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
///
|
|
79
|
+
/// </summary>
|
|
80
|
+
protected string currentScheme = "";
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
///
|
|
84
|
+
/// </summary>
|
|
85
|
+
protected readonly string NullName = "null";
|
|
86
|
+
|
|
87
|
+
/// <summary>
|
|
88
|
+
///
|
|
89
|
+
/// </summary>
|
|
90
|
+
protected readonly string MouseName = "Mouse";
|
|
91
|
+
|
|
92
|
+
/// <summary>
|
|
93
|
+
///
|
|
94
|
+
/// </summary>
|
|
95
|
+
protected readonly string SwitchName = "Switch";
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
/// <inheritdoc/>
|
|
99
|
+
protected override void Awake()
|
|
100
|
+
{
|
|
101
|
+
InitializePlayerInput();
|
|
102
|
+
|
|
103
|
+
if (controls == null)
|
|
104
|
+
UnityEngine.Debug.LogError($"ALERT: You MUST assign the {nameof(controls)} field!");
|
|
105
|
+
|
|
106
|
+
base.Awake();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// <summary>
|
|
110
|
+
///
|
|
111
|
+
/// </summary>
|
|
112
|
+
protected virtual void InitializePlayerInput()
|
|
113
|
+
{
|
|
114
|
+
if (playerInput != null)
|
|
115
|
+
playerInput.neverAutoSwitchControlSchemes = true;
|
|
116
|
+
else
|
|
117
|
+
playerInput = (PlayerInput)FindAnyObjectByType(typeof(PlayerInput));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// <inheritdoc/>
|
|
121
|
+
protected override void InitializeService()
|
|
122
|
+
{
|
|
123
|
+
Actions ??= new();
|
|
124
|
+
|
|
125
|
+
Enable();
|
|
126
|
+
|
|
127
|
+
ServiceInitializer.HardInitialize<IInputManager>(this, dontDestroyOnLoad);
|
|
128
|
+
|
|
129
|
+
if (ServiceLocator.GetService<IInputManager>() == this as IInputManager)
|
|
130
|
+
ServiceLocator.Register(Actions);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
/// <inheritdoc/>
|
|
135
|
+
public virtual void SetSchemeByDevice(InputDevice device)
|
|
136
|
+
{
|
|
137
|
+
// This had to be added because it was possible for this gameobject to be destroyed and still call this function.
|
|
138
|
+
if (ToString() == NullName)
|
|
139
|
+
return;
|
|
140
|
+
|
|
141
|
+
if (device != null)
|
|
142
|
+
EvaluateSchemeByDevice(device);
|
|
143
|
+
else
|
|
144
|
+
UnityEngine.Debug.Log($"REPORT: {ToString()}: Device was Null");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// <summary>
|
|
148
|
+
///
|
|
149
|
+
/// </summary>
|
|
150
|
+
/// <param name="device"></param>
|
|
151
|
+
protected virtual void EvaluateSchemeByDevice(InputDevice device)
|
|
152
|
+
{
|
|
153
|
+
if (debugInputControls)
|
|
154
|
+
UnityEngine.Debug.Log($"{ToString()}: Device is: {device.name} ");
|
|
155
|
+
|
|
156
|
+
var scheme = InputControlScheme.FindControlSchemeForDevice(device, Actions.controlSchemes);
|
|
157
|
+
|
|
158
|
+
if (currentScheme != gamepadScheme && device.name == "Core (Plus) Wired Controller")
|
|
159
|
+
SetDeviceScheme(gamepadScheme);
|
|
160
|
+
|
|
161
|
+
if (scheme != null && currentScheme == scheme.Value.name)
|
|
162
|
+
return;
|
|
163
|
+
|
|
164
|
+
if (scheme != null)
|
|
165
|
+
SetDeviceScheme(scheme.Value.name);
|
|
166
|
+
else if (device.name == MouseName && currentScheme != keyboardScheme)
|
|
167
|
+
SetDeviceScheme(keyboardScheme);
|
|
168
|
+
else if (device.name.Contains(SwitchName) && currentScheme != gamepadScheme)
|
|
169
|
+
SetDeviceScheme(gamepadScheme);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// <summary>
|
|
173
|
+
///
|
|
174
|
+
/// </summary>
|
|
175
|
+
/// <param name="scheme"></param>
|
|
176
|
+
protected virtual void SetDeviceScheme(string scheme)
|
|
177
|
+
{
|
|
178
|
+
if (debugInputControls)
|
|
179
|
+
UnityEngine.Debug.Log($"{ToString()}: Setting Scheme to: " + scheme);
|
|
180
|
+
|
|
181
|
+
currentScheme = scheme;
|
|
182
|
+
|
|
183
|
+
try
|
|
184
|
+
{
|
|
185
|
+
var bindingGroup = Actions.controlSchemes.First(x => x.name == scheme).bindingGroup;
|
|
186
|
+
|
|
187
|
+
Actions.bindingMask = InputBinding.MaskByGroup(bindingGroup);
|
|
188
|
+
}
|
|
189
|
+
catch (Exception e)
|
|
190
|
+
{
|
|
191
|
+
UnityEngine.Debug.LogWarning("ALERT: Could not set scheme to: " + scheme);
|
|
192
|
+
|
|
193
|
+
UnityEngine.Debug.LogWarning("ANALYSIS: " + e.ToString());
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/// <summary>
|
|
198
|
+
///
|
|
199
|
+
/// </summary>
|
|
200
|
+
/// <param name="device"></param>
|
|
201
|
+
/// <param name="deviceChange"></param>
|
|
202
|
+
protected virtual void InputSystemOnDeviceChange(InputDevice device, InputDeviceChange deviceChange)
|
|
203
|
+
{
|
|
204
|
+
switch (deviceChange)
|
|
205
|
+
{
|
|
206
|
+
case InputDeviceChange.Added:
|
|
207
|
+
UnityEngine.Debug.Log("A new device has been added! Device is: " + device.displayName);
|
|
208
|
+
|
|
209
|
+
//TODO: Change pairing from Keyboard to Xbox and dont allow/disable any other schemes
|
|
210
|
+
//var bindingGroup = playerInputActions.controlSchemes.First(x => x.name == "Switch").bindingGroup;
|
|
211
|
+
//playerInputActions.bindingMask = InputBinding.MaskByGroup(bindingGroup);
|
|
212
|
+
|
|
213
|
+
SetSchemeByDevice(device);
|
|
214
|
+
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
case InputDeviceChange.Removed:
|
|
218
|
+
|
|
219
|
+
UnityEngine.Debug.Log(device.displayName + "has been removed!");
|
|
220
|
+
|
|
221
|
+
break;
|
|
222
|
+
|
|
223
|
+
case InputDeviceChange.Disconnected:
|
|
224
|
+
|
|
225
|
+
UnityEngine.Debug.Log(device.displayName + " has been disconnected!");
|
|
226
|
+
|
|
227
|
+
SetDeviceScheme(keyboardScheme);
|
|
228
|
+
|
|
229
|
+
break;
|
|
230
|
+
|
|
231
|
+
case InputDeviceChange.Reconnected:
|
|
232
|
+
break;
|
|
233
|
+
case InputDeviceChange.Enabled:
|
|
234
|
+
break;
|
|
235
|
+
case InputDeviceChange.Disabled:
|
|
236
|
+
break;
|
|
237
|
+
case InputDeviceChange.UsageChanged:
|
|
238
|
+
break;
|
|
239
|
+
case InputDeviceChange.ConfigurationChanged:
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/// <inheritdoc/>
|
|
246
|
+
public virtual string GetCurrentScheme() => currentScheme;
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
/// <inheritdoc/>
|
|
250
|
+
protected override void OnDestroy()
|
|
251
|
+
{
|
|
252
|
+
base.OnDestroy();
|
|
253
|
+
|
|
254
|
+
if (ServiceLocator.HasService<IInputManager>(out var input) && input == this as IInputManager)
|
|
255
|
+
ServiceLocator.Unregister(Actions);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
/// <inheritdoc/>
|
|
261
|
+
public void Enable()
|
|
262
|
+
{
|
|
263
|
+
if (BlockedUpdatingActiveTo(true))
|
|
264
|
+
return;
|
|
265
|
+
|
|
266
|
+
InputSystem.onDeviceChange += InputSystemOnDeviceChange;
|
|
267
|
+
|
|
268
|
+
Actions?.Enable();
|
|
269
|
+
|
|
270
|
+
controls.Enable();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// <inheritdoc/>
|
|
274
|
+
public void Disable()
|
|
275
|
+
{
|
|
276
|
+
if (BlockedUpdatingActiveTo(false))
|
|
277
|
+
return;
|
|
278
|
+
|
|
279
|
+
InputSystem.onDeviceChange -= InputSystemOnDeviceChange;
|
|
280
|
+
|
|
281
|
+
Actions?.Disable();
|
|
282
|
+
|
|
283
|
+
controls.Disable();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
protected virtual bool BlockedUpdatingActiveTo(bool active)
|
|
288
|
+
{
|
|
289
|
+
if (active == this.active)
|
|
290
|
+
return true;
|
|
291
|
+
else
|
|
292
|
+
this.active = active;
|
|
293
|
+
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
/// <inheritdoc/>
|
|
299
|
+
public virtual bool UsingGamepadScheme() => GetCurrentScheme() == gamepadScheme;
|
|
300
|
+
|
|
301
|
+
/// <inheritdoc/>
|
|
302
|
+
public virtual InputAction GetLeave() => leave.action;
|
|
303
|
+
|
|
304
|
+
/// <inheritdoc/>
|
|
305
|
+
public virtual InputAction GetCancel() => cancel.action;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
%YAML 1.1
|
|
2
|
+
%TAG !u! tag:unity3d.com,2011:
|
|
3
|
+
--- !u!1 &8723461378049438731
|
|
4
|
+
GameObject:
|
|
5
|
+
m_ObjectHideFlags: 0
|
|
6
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
7
|
+
m_PrefabInstance: {fileID: 0}
|
|
8
|
+
m_PrefabAsset: {fileID: 0}
|
|
9
|
+
serializedVersion: 6
|
|
10
|
+
m_Component:
|
|
11
|
+
- component: {fileID: 8723461378049438728}
|
|
12
|
+
- component: {fileID: 8723461378049438729}
|
|
13
|
+
m_Layer: 0
|
|
14
|
+
m_Name: Player_Input_Handler
|
|
15
|
+
m_TagString: Untagged
|
|
16
|
+
m_Icon: {fileID: 0}
|
|
17
|
+
m_NavMeshLayer: 0
|
|
18
|
+
m_StaticEditorFlags: 0
|
|
19
|
+
m_IsActive: 1
|
|
20
|
+
--- !u!4 &8723461378049438728
|
|
21
|
+
Transform:
|
|
22
|
+
m_ObjectHideFlags: 0
|
|
23
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
24
|
+
m_PrefabInstance: {fileID: 0}
|
|
25
|
+
m_PrefabAsset: {fileID: 0}
|
|
26
|
+
m_GameObject: {fileID: 8723461378049438731}
|
|
27
|
+
serializedVersion: 2
|
|
28
|
+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
29
|
+
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
30
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
31
|
+
m_ConstrainProportionsScale: 0
|
|
32
|
+
m_Children:
|
|
33
|
+
- {fileID: 743431406258650647}
|
|
34
|
+
m_Father: {fileID: 0}
|
|
35
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
36
|
+
--- !u!114 &8723461378049438729
|
|
37
|
+
MonoBehaviour:
|
|
38
|
+
m_ObjectHideFlags: 0
|
|
39
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
40
|
+
m_PrefabInstance: {fileID: 0}
|
|
41
|
+
m_PrefabAsset: {fileID: 0}
|
|
42
|
+
m_GameObject: {fileID: 8723461378049438731}
|
|
43
|
+
m_Enabled: 1
|
|
44
|
+
m_EditorHideFlags: 0
|
|
45
|
+
m_Script: {fileID: 11500000, guid: 1f056034e0fa1e8489c0bf07951fd261, type: 3}
|
|
46
|
+
m_Name:
|
|
47
|
+
m_EditorClassIdentifier:
|
|
48
|
+
registerService: 1
|
|
49
|
+
dontDestroyOnLoad: 0
|
|
50
|
+
controls: {fileID: -944628639613478452, guid: 5db4984853779e74db3e8e6c0ebb48c9,
|
|
51
|
+
type: 3}
|
|
52
|
+
cancel: {fileID: 5075748910933613326, guid: 5db4984853779e74db3e8e6c0ebb48c9, type: 3}
|
|
53
|
+
leave: {fileID: 6619799291428089638, guid: 5db4984853779e74db3e8e6c0ebb48c9, type: 3}
|
|
54
|
+
debugInputControls: 1
|
|
55
|
+
keyboardScheme: Keyboard&Mouse
|
|
56
|
+
gamepadScheme: Gamepad
|
|
57
|
+
--- !u!1001 &7806534550335460611
|
|
58
|
+
PrefabInstance:
|
|
59
|
+
m_ObjectHideFlags: 0
|
|
60
|
+
serializedVersion: 2
|
|
61
|
+
m_Modification:
|
|
62
|
+
serializedVersion: 3
|
|
63
|
+
m_TransformParent: {fileID: 8723461378049438728}
|
|
64
|
+
m_Modifications:
|
|
65
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
66
|
+
type: 3}
|
|
67
|
+
propertyPath: m_RootOrder
|
|
68
|
+
value: 0
|
|
69
|
+
objectReference: {fileID: 0}
|
|
70
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
71
|
+
type: 3}
|
|
72
|
+
propertyPath: m_LocalPosition.x
|
|
73
|
+
value: 0
|
|
74
|
+
objectReference: {fileID: 0}
|
|
75
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
76
|
+
type: 3}
|
|
77
|
+
propertyPath: m_LocalPosition.y
|
|
78
|
+
value: 0
|
|
79
|
+
objectReference: {fileID: 0}
|
|
80
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
81
|
+
type: 3}
|
|
82
|
+
propertyPath: m_LocalPosition.z
|
|
83
|
+
value: 0
|
|
84
|
+
objectReference: {fileID: 0}
|
|
85
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
86
|
+
type: 3}
|
|
87
|
+
propertyPath: m_LocalRotation.w
|
|
88
|
+
value: 1
|
|
89
|
+
objectReference: {fileID: 0}
|
|
90
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
91
|
+
type: 3}
|
|
92
|
+
propertyPath: m_LocalRotation.x
|
|
93
|
+
value: -0
|
|
94
|
+
objectReference: {fileID: 0}
|
|
95
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
96
|
+
type: 3}
|
|
97
|
+
propertyPath: m_LocalRotation.y
|
|
98
|
+
value: -0
|
|
99
|
+
objectReference: {fileID: 0}
|
|
100
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
101
|
+
type: 3}
|
|
102
|
+
propertyPath: m_LocalRotation.z
|
|
103
|
+
value: -0
|
|
104
|
+
objectReference: {fileID: 0}
|
|
105
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
106
|
+
type: 3}
|
|
107
|
+
propertyPath: m_LocalEulerAnglesHint.x
|
|
108
|
+
value: 0
|
|
109
|
+
objectReference: {fileID: 0}
|
|
110
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
111
|
+
type: 3}
|
|
112
|
+
propertyPath: m_LocalEulerAnglesHint.y
|
|
113
|
+
value: 0
|
|
114
|
+
objectReference: {fileID: 0}
|
|
115
|
+
- target: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
116
|
+
type: 3}
|
|
117
|
+
propertyPath: m_LocalEulerAnglesHint.z
|
|
118
|
+
value: 0
|
|
119
|
+
objectReference: {fileID: 0}
|
|
120
|
+
- target: {fileID: 7351936437549624085, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
121
|
+
type: 3}
|
|
122
|
+
propertyPath: m_Name
|
|
123
|
+
value: Set_Scheme_From_Device
|
|
124
|
+
objectReference: {fileID: 0}
|
|
125
|
+
m_RemovedComponents: []
|
|
126
|
+
m_RemovedGameObjects: []
|
|
127
|
+
m_AddedGameObjects: []
|
|
128
|
+
m_AddedComponents: []
|
|
129
|
+
m_SourcePrefab: {fileID: 100100000, guid: f5ba66ec914d24b42bf69d3b2f94cbc4, type: 3}
|
|
130
|
+
--- !u!4 &743431406258650647 stripped
|
|
131
|
+
Transform:
|
|
132
|
+
m_CorrespondingSourceObject: {fileID: 7351936437549624084, guid: f5ba66ec914d24b42bf69d3b2f94cbc4,
|
|
133
|
+
type: 3}
|
|
134
|
+
m_PrefabInstance: {fileID: 7806534550335460611}
|
|
135
|
+
m_PrefabAsset: {fileID: 0}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
%YAML 1.1
|
|
2
|
+
%TAG !u! tag:unity3d.com,2011:
|
|
3
|
+
--- !u!1 &7351936437549624085
|
|
4
|
+
GameObject:
|
|
5
|
+
m_ObjectHideFlags: 0
|
|
6
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
7
|
+
m_PrefabInstance: {fileID: 0}
|
|
8
|
+
m_PrefabAsset: {fileID: 0}
|
|
9
|
+
serializedVersion: 6
|
|
10
|
+
m_Component:
|
|
11
|
+
- component: {fileID: 7351936437549624084}
|
|
12
|
+
- component: {fileID: 7351936437549624087}
|
|
13
|
+
m_Layer: 0
|
|
14
|
+
m_Name: Set_Scheme_From_Device
|
|
15
|
+
m_TagString: Untagged
|
|
16
|
+
m_Icon: {fileID: 0}
|
|
17
|
+
m_NavMeshLayer: 0
|
|
18
|
+
m_StaticEditorFlags: 0
|
|
19
|
+
m_IsActive: 1
|
|
20
|
+
--- !u!4 &7351936437549624084
|
|
21
|
+
Transform:
|
|
22
|
+
m_ObjectHideFlags: 0
|
|
23
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
24
|
+
m_PrefabInstance: {fileID: 0}
|
|
25
|
+
m_PrefabAsset: {fileID: 0}
|
|
26
|
+
m_GameObject: {fileID: 7351936437549624085}
|
|
27
|
+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
28
|
+
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
29
|
+
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
30
|
+
m_ConstrainProportionsScale: 0
|
|
31
|
+
m_Children: []
|
|
32
|
+
m_Father: {fileID: 0}
|
|
33
|
+
m_RootOrder: 0
|
|
34
|
+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
35
|
+
--- !u!114 &7351936437549624087
|
|
36
|
+
MonoBehaviour:
|
|
37
|
+
m_ObjectHideFlags: 0
|
|
38
|
+
m_CorrespondingSourceObject: {fileID: 0}
|
|
39
|
+
m_PrefabInstance: {fileID: 0}
|
|
40
|
+
m_PrefabAsset: {fileID: 0}
|
|
41
|
+
m_GameObject: {fileID: 7351936437549624085}
|
|
42
|
+
m_Enabled: 1
|
|
43
|
+
m_EditorHideFlags: 0
|
|
44
|
+
m_Script: {fileID: 11500000, guid: c161be8ecfd9f584d875b14094e10917, type: 3}
|
|
45
|
+
m_Name:
|
|
46
|
+
m_EditorClassIdentifier:
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
//Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
|
|
2
|
+
using DREditor.Services;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine.InputSystem;
|
|
5
|
+
|
|
6
|
+
namespace DREditor.Input
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
///
|
|
10
|
+
/// </summary>
|
|
11
|
+
[ClassHeader(nameof(AnyInputDetector) +
|
|
12
|
+
"\n\n")]
|
|
13
|
+
public class SetSchemeFromDevice : AnyInputDetector
|
|
14
|
+
{
|
|
15
|
+
/// <summary>
|
|
16
|
+
///
|
|
17
|
+
/// </summary>
|
|
18
|
+
protected InputDevice latestDevice = null;
|
|
19
|
+
|
|
20
|
+
/// <summary>
|
|
21
|
+
///
|
|
22
|
+
/// </summary>
|
|
23
|
+
protected IInputManager inputManager = null;
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
///
|
|
27
|
+
/// </summary>
|
|
28
|
+
protected readonly Dictionary<string, List<string>> schemeDevices = new();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/// <summary>
|
|
32
|
+
///
|
|
33
|
+
/// </summary>
|
|
34
|
+
protected virtual void OnEnable() => Subscribe();
|
|
35
|
+
|
|
36
|
+
/// <summary>
|
|
37
|
+
///
|
|
38
|
+
/// </summary>
|
|
39
|
+
protected virtual void OnDisable() => Unsubscribe();
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/// <summary>
|
|
43
|
+
///
|
|
44
|
+
/// </summary>
|
|
45
|
+
protected override void OnValidInputFound()
|
|
46
|
+
{
|
|
47
|
+
if (SchemeShouldChange())
|
|
48
|
+
ChangeScheme();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// <summary>
|
|
52
|
+
///
|
|
53
|
+
/// </summary>
|
|
54
|
+
/// <returns></returns>
|
|
55
|
+
protected virtual bool SchemeShouldChange() =>
|
|
56
|
+
InputManagerValid() && DeviceIsValid() && !DeviceEntryAlreadyRegistered();
|
|
57
|
+
|
|
58
|
+
/// <summary>
|
|
59
|
+
///
|
|
60
|
+
/// </summary>
|
|
61
|
+
/// <returns></returns>
|
|
62
|
+
protected virtual bool InputManagerValid() => ServiceLocator.HasService(out inputManager);
|
|
63
|
+
|
|
64
|
+
/// <summary>
|
|
65
|
+
///
|
|
66
|
+
/// </summary>
|
|
67
|
+
/// <returns></returns>
|
|
68
|
+
protected virtual bool DeviceIsValid() => device != null && device != latestDevice;
|
|
69
|
+
|
|
70
|
+
/// <summary>
|
|
71
|
+
///
|
|
72
|
+
/// </summary>
|
|
73
|
+
/// <returns></returns>
|
|
74
|
+
protected virtual bool DeviceEntryAlreadyRegistered() => SchemeRegistered() && RegisteredSchemeMatchesDevice();
|
|
75
|
+
|
|
76
|
+
/// <summary>
|
|
77
|
+
///
|
|
78
|
+
/// </summary>
|
|
79
|
+
/// <returns></returns>
|
|
80
|
+
protected virtual bool SchemeRegistered() => schemeDevices.ContainsKey(inputManager.GetCurrentScheme());
|
|
81
|
+
|
|
82
|
+
/// <summary>
|
|
83
|
+
///
|
|
84
|
+
/// </summary>
|
|
85
|
+
/// <returns></returns>
|
|
86
|
+
protected virtual bool RegisteredSchemeMatchesDevice() =>
|
|
87
|
+
schemeDevices[inputManager.GetCurrentScheme()].Contains(device.name);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/// <summary>
|
|
91
|
+
///
|
|
92
|
+
/// </summary>
|
|
93
|
+
protected virtual void ChangeScheme()
|
|
94
|
+
{
|
|
95
|
+
LogUpdatedDevice();
|
|
96
|
+
|
|
97
|
+
UpdateSchemeUsingDevice();
|
|
98
|
+
|
|
99
|
+
UpdateRegistryWithLatest();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// <summary>
|
|
103
|
+
///
|
|
104
|
+
/// </summary>
|
|
105
|
+
protected virtual void LogUpdatedDevice()
|
|
106
|
+
{
|
|
107
|
+
string log = latestDevice != null ?
|
|
108
|
+
device.name + " from: " + latestDevice.name :
|
|
109
|
+
device.name;
|
|
110
|
+
|
|
111
|
+
UnityEngine.Debug.Log($"{ToString()}: Input Detect Update: " + log);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// <summary>
|
|
115
|
+
///
|
|
116
|
+
/// </summary>
|
|
117
|
+
protected virtual void UpdateSchemeUsingDevice()
|
|
118
|
+
{
|
|
119
|
+
latestDevice = device;
|
|
120
|
+
|
|
121
|
+
inputManager.SetSchemeByDevice(latestDevice);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// <summary>
|
|
125
|
+
///
|
|
126
|
+
/// </summary>
|
|
127
|
+
protected virtual void UpdateRegistryWithLatest()
|
|
128
|
+
{
|
|
129
|
+
if (SchemeRegistered())
|
|
130
|
+
UpdateScheme();
|
|
131
|
+
else
|
|
132
|
+
RegisterScheme();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// <summary>
|
|
136
|
+
///
|
|
137
|
+
/// </summary>
|
|
138
|
+
protected virtual void UpdateScheme() => schemeDevices[inputManager.GetCurrentScheme()].Add(device.name);
|
|
139
|
+
|
|
140
|
+
/// <summary>
|
|
141
|
+
///
|
|
142
|
+
/// </summary>
|
|
143
|
+
protected virtual void RegisterScheme() =>
|
|
144
|
+
schemeDevices.Add(inputManager.GetCurrentScheme(), new List<string>() { device.name });
|
|
145
|
+
}
|
|
146
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "net.dreditor.input",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"displayName": "DREditor Input",
|
|
5
|
+
"description": "The beta for DREditor. A tool to create death game style projects without having to code.",
|
|
6
|
+
"unity": "6000.4",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"com.unity.inputsystem": "1.19.0",
|
|
9
|
+
"net.dreditor.core": "0.1.7"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Benjamin \"Sweden\" Jillson",
|
|
16
|
+
"email": "dreditortool@gmail.com",
|
|
17
|
+
"url": "https://dreditor.net"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"editor",
|
|
21
|
+
"tool",
|
|
22
|
+
"dreditor"
|
|
23
|
+
],
|
|
24
|
+
"samples": [
|
|
25
|
+
{
|
|
26
|
+
"displayName": "Samples",
|
|
27
|
+
"description": "",
|
|
28
|
+
"path": "Samples~"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"documentationUrl": "https://dreditor.net",
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"licensesUrl": "https://dreditor.net/docs/LICENSE.html",
|
|
34
|
+
"changelogUrl": "https://dreditor.net/docs/CHANGELOG.html",
|
|
35
|
+
"repository": {
|
|
36
|
+
"url": "https://github.com/CertifiedSharp/DREditor",
|
|
37
|
+
"type": "git",
|
|
38
|
+
"revision": "14ca252fbb33eb6f53557ecaed1c10902877698f"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/README.md
DELETED