Skip to content

Commit a579bfa

Browse files
committed
Fixed a problem which would cause mobile rebind sample build to run in portrait mode. Game manager now enforces landscape as part of running. Added menu button and reenabled UI actions during gameplay.
1 parent 0962b73 commit a579bfa

File tree

7 files changed

+468
-27
lines changed

7 files changed

+468
-27
lines changed

Assets/Samples/RebindingUI/Game/GameplayManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ internal bool TryTeleportOrthographicExtents(Vector3 position, out Vector3 resul
191191

192192
private void Awake()
193193
{
194+
// This game is designed for landscape orientation, so make sure we use it.
195+
Screen.orientation = ScreenOrientation.LandscapeLeft;
196+
194197
m_FeedbackController = GetComponent<FeedbackController>();
195198

196199
m_EnemyPool = new ObjectPool<Enemy>(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace UnityEngine.InputSystem.Samples.RebindUI
4+
{
5+
/// <summary>
6+
/// Extension methods to reduce code bloat of this example.
7+
/// </summary>
8+
public static class InputActionExtensions
9+
{
10+
/// <summary>
11+
/// Attempts to find an action binding using its binding ID (GUID).
12+
/// </summary>
13+
/// <param name="action">The action instance, may be null.</param>
14+
/// <param name="bindingId">The binding ID (GUID) represented by a string.</param>
15+
/// <returns>Zero-based index of the binding or -1 if not found.</returns>
16+
public static int FindBindingById(this InputAction action, string bindingId)
17+
{
18+
if (action == null || string.IsNullOrEmpty(bindingId))
19+
return -1;
20+
var id = new Guid(bindingId);
21+
return action.bindings.IndexOf(x => x.id == id);
22+
}
23+
}
24+
}

Assets/Samples/RebindingUI/InputActionExtensions.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/RebindingUI/RebindActionEditor.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,8 @@ public bool Refresh()
129129
return true;
130130
}
131131

132-
public static int FindBindingById(InputAction action, string bindingId)
133-
{
134-
if (action == null || string.IsNullOrEmpty(bindingId)) return -1;
135-
var id = new Guid(bindingId);
136-
return action.bindings.IndexOf(x => x.id == id);
137-
}
138-
139132
public string bindingId => m_BindingIdProperty.stringValue;
140-
public int bindingIndex => FindBindingById(action, m_BindingIdProperty.stringValue);
133+
public int bindingIndex => action.FindBindingById(m_BindingIdProperty.stringValue);
141134

142135
public InputAction action => ((InputActionReference)m_ActionProperty.objectReferenceValue)?.action;
143136

Assets/Samples/RebindingUI/RebindActionParameterUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private void SetParameterValue(float value)
124124
if (m_Action != null && m_Action.action != null)
125125
{
126126
var action = m_Action.action;
127-
int bindingIndex = BindingUI.FindBindingById(action, m_BindingId);
127+
int bindingIndex = action.FindBindingById(m_BindingId);
128128
var bindingMask = bindingIndex >= 0 ? action.bindings[bindingIndex] : default;
129129

130130
// We apply parameter override. This directly affects matching processors and interactions

Assets/Samples/RebindingUI/RebindActionUI.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,15 @@ public InteractiveRebindEvent stopRebindEvent
182182
/// <returns>true if able to resolve, otherwise false.</returns>
183183
public bool ResolveActionAndBinding(out InputAction action, out int bindingIndex)
184184
{
185-
bindingIndex = -1;
186-
187185
action = m_Action?.action;
188-
if (action == null)
189-
return false;
190186

191-
if (string.IsNullOrEmpty(m_BindingId))
192-
return false;
187+
bindingIndex = action.FindBindingById(m_BindingId);
188+
if (bindingIndex >= 0)
189+
return true;
193190

194-
// Look up binding index.
195-
var id = new Guid(m_BindingId);
196-
bindingIndex = action.bindings.IndexOf(x => x.id == id);
197-
if (bindingIndex == -1)
198-
{
191+
if (action != null && !string.IsNullOrEmpty(m_BindingId))
199192
Debug.LogError($"Cannot find binding with ID '{m_BindingId}' on '{action}'", this);
200-
return false;
201-
}
202-
203-
return true;
193+
return false;
204194
}
205195

206196
/// <summary>

0 commit comments

Comments
 (0)