1
- #region [License]
1
+ #region [License]
2
2
// The MIT License (MIT)
3
3
//
4
4
// Copyright (c) 2017, Unity Technologies
26
26
#endregion
27
27
using UnityEngine;
28
28
using UnityEngine.EventSystems;
29
- using UnityEngine.Serialization;
30
- using System;
31
29
32
30
namespace Luminosity.IO
33
31
{
@@ -36,113 +34,69 @@ namespace Luminosity.IO
36
34
{
37
35
public const string VERSION = "2017.2";
38
36
39
- private float m_PrevActionTime;
40
- private Vector2 m_LastMoveVector;
41
- private int m_ConsecutiveMoveCount = 0;
42
-
43
- private Vector2 m_LastMousePosition;
44
- private Vector2 m_MousePosition;
45
-
46
- private GameObject m_CurrentFocusedGameObject;
47
-
48
- protected StandaloneInputModule()
49
- {
50
- }
51
-
52
- [Obsolete("Mode is no longer needed on input module as it handles both mouse and keyboard simultaneously.", false)]
53
- public enum InputMode
54
- {
55
- Mouse,
56
- Buttons
57
- }
58
-
59
- [Obsolete("Mode is no longer needed on input module as it handles both mouse and keyboard simultaneously.", false)]
60
- public InputMode inputMode
61
- {
62
- get { return InputMode.Mouse; }
63
- }
64
-
65
37
[SerializeField]
66
- private string m_HorizontalAxis = "Horizontal ";
38
+ private string m_UpButton = "UI_Up ";
67
39
68
- /// <summary>
69
- /// Name of the vertical axis for movement (if axis events are used).
70
- /// </summary>
71
40
[SerializeField]
72
- private string m_VerticalAxis = "Vertical ";
41
+ private string m_DownButton = "UI_Down ";
73
42
74
- /// <summary>
75
- /// Name of the submit button.
76
- /// </summary>
77
43
[SerializeField]
78
- private string m_SubmitButton = "Submit ";
44
+ private string m_LeftButton = "UI_Left ";
79
45
80
- /// <summary>
81
- /// Name of the submit button.
82
- /// </summary>
83
46
[SerializeField]
84
- private string m_CancelButton = "Cancel ";
47
+ private string m_RightButton = "UI_Right ";
85
48
86
49
[SerializeField]
87
- private float m_InputActionsPerSecond = 10 ;
88
-
50
+ private string m_SubmitButton = "UI_Submit" ;
51
+
89
52
[SerializeField]
90
- private float m_RepeatDelay = 0.5f ;
53
+ private string m_CancelButton = "UI_Cancel" ;
91
54
92
55
[SerializeField]
93
- [FormerlySerializedAs("m_AllowActivationOnMobileDevice")]
94
56
private bool m_ForceModuleActive;
57
+
58
+ private Vector2 m_LastMousePosition;
59
+ private Vector2 m_MousePosition;
95
60
96
- [Obsolete("allowActivationOnMobileDevice has been deprecated. Use forceModuleActive instead (UnityUpgradable) -> forceModuleActive")]
97
- public bool allowActivationOnMobileDevice
98
- {
99
- get { return m_ForceModuleActive; }
100
- set { m_ForceModuleActive = value; }
101
- }
61
+ private GameObject m_CurrentFocusedGameObject;
102
62
103
- public bool forceModuleActive
63
+ public bool ForceModuleActive
104
64
{
105
65
get { return m_ForceModuleActive; }
106
66
set { m_ForceModuleActive = value; }
107
67
}
108
68
109
- public float inputActionsPerSecond
69
+ public string UpButton
110
70
{
111
- get { return m_InputActionsPerSecond ; }
112
- set { m_InputActionsPerSecond = value; }
71
+ get { return m_UpButton ; }
72
+ set { m_UpButton = value; }
113
73
}
114
74
115
- public float repeatDelay
75
+ public string DownButton
116
76
{
117
- get { return m_RepeatDelay ; }
118
- set { m_RepeatDelay = value; }
77
+ get { return m_DownButton ; }
78
+ set { m_DownButton = value; }
119
79
}
120
80
121
- /// <summary>
122
- /// Name of the horizontal axis for movement (if axis events are used).
123
- /// </summary>
124
- public string horizontalAxis
81
+ public string LeftButton
125
82
{
126
- get { return m_HorizontalAxis ; }
127
- set { m_HorizontalAxis = value; }
83
+ get { return m_LeftButton ; }
84
+ set { m_LeftButton = value; }
128
85
}
129
86
130
- /// <summary>
131
- /// Name of the vertical axis for movement (if axis events are used).
132
- /// </summary>
133
- public string verticalAxis
87
+ public string RightButton
134
88
{
135
- get { return m_VerticalAxis ; }
136
- set { m_VerticalAxis = value; }
89
+ get { return m_RightButton ; }
90
+ set { m_RightButton = value; }
137
91
}
138
92
139
- public string submitButton
93
+ public string SubmitButton
140
94
{
141
95
get { return m_SubmitButton; }
142
96
set { m_SubmitButton = value; }
143
97
}
144
98
145
- public string cancelButton
99
+ public string CancelButton
146
100
{
147
101
get { return m_CancelButton; }
148
102
set { m_CancelButton = value; }
@@ -193,8 +147,10 @@ namespace Luminosity.IO
193
147
var shouldActivate = m_ForceModuleActive;
194
148
shouldActivate |= input.GetButtonDown(m_SubmitButton);
195
149
shouldActivate |= input.GetButtonDown(m_CancelButton);
196
- shouldActivate |= !Mathf.Approximately(input.GetAxisRaw(m_HorizontalAxis), 0.0f);
197
- shouldActivate |= !Mathf.Approximately(input.GetAxisRaw(m_VerticalAxis), 0.0f);
150
+ shouldActivate |= input.GetButtonDown(m_UpButton);
151
+ shouldActivate |= input.GetButtonDown(m_DownButton);
152
+ shouldActivate |= input.GetButtonDown(m_LeftButton);
153
+ shouldActivate |= input.GetButtonDown(m_RightButton);
198
154
shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f;
199
155
shouldActivate |= input.GetMouseButtonDown(0);
200
156
@@ -393,23 +349,15 @@ namespace Luminosity.IO
393
349
private Vector2 GetRawMoveVector()
394
350
{
395
351
Vector2 move = Vector2.zero;
396
- move.x = input.GetAxisRaw(m_HorizontalAxis);
397
- move.y = input.GetAxisRaw(m_VerticalAxis);
352
+ if(input.GetButtonDown(m_LeftButton))
353
+ move.x = -1.0f;
354
+ if(input.GetButtonDown(m_RightButton))
355
+ move.x = 1.0f;
356
+ if(input.GetButtonDown(m_UpButton))
357
+ move.y = 1.0f;
358
+ if(input.GetButtonDown(m_DownButton))
359
+ move.y = -1.0f;
398
360
399
- if(input.GetButtonDown(m_HorizontalAxis))
400
- {
401
- if(move.x < 0)
402
- move.x = -1f;
403
- if(move.x > 0)
404
- move.x = 1f;
405
- }
406
- if(input.GetButtonDown(m_VerticalAxis))
407
- {
408
- if(move.y < 0)
409
- move.y = -1f;
410
- if(move.y > 0)
411
- move.y = 1f;
412
- }
413
361
return move;
414
362
}
415
363
@@ -418,46 +366,12 @@ namespace Luminosity.IO
418
366
/// </summary>
419
367
protected bool SendMoveEventToSelectedObject()
420
368
{
421
- float time = Time.unscaledTime;
422
-
423
- Vector2 movement = GetRawMoveVector();
424
- if(Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
425
- {
426
- m_ConsecutiveMoveCount = 0;
427
- return false;
428
- }
429
-
430
- // If user pressed key again, always allow event
431
- bool allow = input.GetButtonDown(m_HorizontalAxis) || input.GetButtonDown(m_VerticalAxis);
432
- bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
433
- if(!allow)
434
- {
435
- // Otherwise, user held down key or axis.
436
- // If direction didn't change at least 90 degrees, wait for delay before allowing consequtive event.
437
- if(similarDir && m_ConsecutiveMoveCount == 1)
438
- allow = (time > m_PrevActionTime + m_RepeatDelay);
439
- // If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
440
- else
441
- allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
442
- }
443
- if(!allow)
444
- return false;
445
-
446
- // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")");
369
+ var movement = GetRawMoveVector();
447
370
var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
448
371
449
372
if(axisEventData.moveDir != MoveDirection.None)
450
373
{
451
374
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
452
- if(!similarDir)
453
- m_ConsecutiveMoveCount = 0;
454
- m_ConsecutiveMoveCount++;
455
- m_PrevActionTime = time;
456
- m_LastMoveVector = movement;
457
- }
458
- else
459
- {
460
- m_ConsecutiveMoveCount = 0;
461
375
}
462
376
463
377
return axisEventData.used;
@@ -468,12 +382,6 @@ namespace Luminosity.IO
468
382
ProcessMouseEvent(0);
469
383
}
470
384
471
- [Obsolete("This method is no longer checked, overriding it with return true does nothing!")]
472
- protected virtual bool ForceAutoSelect()
473
- {
474
- return false;
475
- }
476
-
477
385
/// <summary>
478
386
/// Process all mouse events.
479
387
/// </summary>
0 commit comments