Skip to content

Commit ff3371e

Browse files
committed
custom UI input module with navigation based on buttons instead of axes
1 parent 9777a3d commit ff3371e

23 files changed

+4743
-308
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
22
<InputModules>
3-
<Item name="Unity 2017.2" path="ui_input_modules/unity_2017_2" />
3+
<Item name="Unity 2017.2" path="ui_input_modules/unity_2017_2" />
4+
<Item name="Unity 2017.2 Classic" path="ui_input_modules/unity_2017_2_classic" />
45
</InputModules>

Assets/InputManager/Addons/UIInputModule/Resources/ui_input_modules/unity_2017_2.txt

+40-132
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region [License]
1+
#region [License]
22
// The MIT License (MIT)
33
//
44
// Copyright (c) 2017, Unity Technologies
@@ -26,8 +26,6 @@
2626
#endregion
2727
using UnityEngine;
2828
using UnityEngine.EventSystems;
29-
using UnityEngine.Serialization;
30-
using System;
3129

3230
namespace Luminosity.IO
3331
{
@@ -36,113 +34,69 @@ namespace Luminosity.IO
3634
{
3735
public const string VERSION = "2017.2";
3836

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-
6537
[SerializeField]
66-
private string m_HorizontalAxis = "Horizontal";
38+
private string m_UpButton = "UI_Up";
6739

68-
/// <summary>
69-
/// Name of the vertical axis for movement (if axis events are used).
70-
/// </summary>
7140
[SerializeField]
72-
private string m_VerticalAxis = "Vertical";
41+
private string m_DownButton = "UI_Down";
7342

74-
/// <summary>
75-
/// Name of the submit button.
76-
/// </summary>
7743
[SerializeField]
78-
private string m_SubmitButton = "Submit";
44+
private string m_LeftButton = "UI_Left";
7945

80-
/// <summary>
81-
/// Name of the submit button.
82-
/// </summary>
8346
[SerializeField]
84-
private string m_CancelButton = "Cancel";
47+
private string m_RightButton = "UI_Right";
8548

8649
[SerializeField]
87-
private float m_InputActionsPerSecond = 10;
88-
50+
private string m_SubmitButton = "UI_Submit";
51+
8952
[SerializeField]
90-
private float m_RepeatDelay = 0.5f;
53+
private string m_CancelButton = "UI_Cancel";
9154

9255
[SerializeField]
93-
[FormerlySerializedAs("m_AllowActivationOnMobileDevice")]
9456
private bool m_ForceModuleActive;
57+
58+
private Vector2 m_LastMousePosition;
59+
private Vector2 m_MousePosition;
9560

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;
10262

103-
public bool forceModuleActive
63+
public bool ForceModuleActive
10464
{
10565
get { return m_ForceModuleActive; }
10666
set { m_ForceModuleActive = value; }
10767
}
10868

109-
public float inputActionsPerSecond
69+
public string UpButton
11070
{
111-
get { return m_InputActionsPerSecond; }
112-
set { m_InputActionsPerSecond = value; }
71+
get { return m_UpButton; }
72+
set { m_UpButton = value; }
11373
}
11474

115-
public float repeatDelay
75+
public string DownButton
11676
{
117-
get { return m_RepeatDelay; }
118-
set { m_RepeatDelay = value; }
77+
get { return m_DownButton; }
78+
set { m_DownButton = value; }
11979
}
12080

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
12582
{
126-
get { return m_HorizontalAxis; }
127-
set { m_HorizontalAxis = value; }
83+
get { return m_LeftButton; }
84+
set { m_LeftButton = value; }
12885
}
12986

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
13488
{
135-
get { return m_VerticalAxis; }
136-
set { m_VerticalAxis = value; }
89+
get { return m_RightButton; }
90+
set { m_RightButton = value; }
13791
}
13892

139-
public string submitButton
93+
public string SubmitButton
14094
{
14195
get { return m_SubmitButton; }
14296
set { m_SubmitButton = value; }
14397
}
14498

145-
public string cancelButton
99+
public string CancelButton
146100
{
147101
get { return m_CancelButton; }
148102
set { m_CancelButton = value; }
@@ -193,8 +147,10 @@ namespace Luminosity.IO
193147
var shouldActivate = m_ForceModuleActive;
194148
shouldActivate |= input.GetButtonDown(m_SubmitButton);
195149
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);
198154
shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f;
199155
shouldActivate |= input.GetMouseButtonDown(0);
200156

@@ -393,23 +349,15 @@ namespace Luminosity.IO
393349
private Vector2 GetRawMoveVector()
394350
{
395351
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;
398360

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-
}
413361
return move;
414362
}
415363

@@ -418,46 +366,12 @@ namespace Luminosity.IO
418366
/// </summary>
419367
protected bool SendMoveEventToSelectedObject()
420368
{
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();
447370
var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
448371

449372
if(axisEventData.moveDir != MoveDirection.None)
450373
{
451374
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;
461375
}
462376

463377
return axisEventData.used;
@@ -468,12 +382,6 @@ namespace Luminosity.IO
468382
ProcessMouseEvent(0);
469383
}
470384

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-
477385
/// <summary>
478386
/// Process all mouse events.
479387
/// </summary>

Assets/InputManager/Addons/UIInputModule/Resources/ui_input_modules/unity_2017_2.txt.meta

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)