Skip to content

Commit 6780d58

Browse files
committed
Renamed assets to have more meaningful names, created a dedicated UI map for rebinding sample, code clean-up, tweaks.
1 parent c6e4018 commit 6780d58

13 files changed

+678
-79
lines changed

Assets/Samples/RebindingUI/Game/RebindingMaterial2.mat renamed to Assets/Samples/RebindingUI/Game/BulletMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: RebindingMaterial2
10+
m_Name: BulletMaterial
1111
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
1212
m_Parent: {fileID: 0}
1313
m_ModifiedSerializedProperties: 0

Assets/Samples/RebindingUI/Game/RebindingMaterial3.mat renamed to Assets/Samples/RebindingUI/Game/EnemyMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: RebindingMaterial3
10+
m_Name: EnemyMaterial
1111
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
1212
m_Parent: {fileID: 0}
1313
m_ModifiedSerializedProperties: 0

Assets/Samples/RebindingUI/Game/RebindingMaterial.mat renamed to Assets/Samples/RebindingUI/Game/PlayerMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: RebindingMaterial
10+
m_Name: PlayerMaterial
1111
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
1212
m_Parent: {fileID: 0}
1313
m_ModifiedSerializedProperties: 0

Assets/Samples/RebindingUI/Game/RebindingMaterial4.mat renamed to Assets/Samples/RebindingUI/Game/PlayerMaterial2.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: RebindingMaterial4
10+
m_Name: PlayerMaterial2
1111
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
1212
m_Parent: {fileID: 0}
1313
m_ModifiedSerializedProperties: 0

Assets/Samples/RebindingUI/InputActionIndicator.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,22 @@ public class InputActionIndicator : MonoBehaviour
2525
[Tooltip("The duration for which the indicator should be lit before becoming completely inactive.")]
2626
public float duration = 1.0f;
2727

28-
private double m_RealTimeLastPerformed;
29-
private Image m_Image;
30-
private Text m_Text;
28+
public Image performedIndicator;
29+
public Image pressedIndicator;
30+
public Text label;
3131

32-
void Awake()
33-
{
34-
m_Image = GetComponent<Image>();
35-
m_Text = GetComponent<Text>();
36-
Update();
37-
}
32+
private double m_RealTimeLastPerformed;
3833

3934
private void OnEnable()
4035
{
41-
action.action.performed += OnPerformed;
42-
action.action.Enable();
36+
if (action != null && action.action != null)
37+
action.action.performed += OnPerformed;
4338
}
4439

4540
private void OnDisable()
4641
{
47-
action.action.Disable();
48-
action.action.performed -= OnPerformed;
42+
if (action != null && action.action != null)
43+
action.action.performed -= OnPerformed;
4944
}
5045

5146
private void OnPerformed(InputAction.CallbackContext obj)
@@ -57,23 +52,30 @@ private void Update()
5752
{
5853
if (action.action.enabled)
5954
{
60-
// Pulse active color if enabled
55+
// Pulse active color if enabled and performed
6156
var elapsedSincePerformed = Time.realtimeSinceStartupAsDouble - m_RealTimeLastPerformed;
62-
m_Image.color = duration <= 0.0f
63-
? inactiveColor
64-
: Color.Lerp(inactiveColor, activeColor,
65-
(float)Math.Max(0.0, 1.0 - elapsedSincePerformed / duration));
57+
if (performedIndicator)
58+
{
59+
performedIndicator.color = duration <= 0.0f
60+
? inactiveColor
61+
: Color.Lerp(inactiveColor, activeColor,
62+
(float)Math.Max(0.0, 1.0 - elapsedSincePerformed / duration));
63+
}
64+
65+
if (pressedIndicator)
66+
pressedIndicator.color = action.action.IsPressed() ? activeColor : inactiveColor;
6667
}
6768
else
6869
{
6970
// Show disabled indicator if disabled
70-
if (m_Image.color != disabledColor)
71-
m_Image.color = disabledColor;
71+
if (performedIndicator && performedIndicator.color != disabledColor)
72+
performedIndicator.color = disabledColor;
73+
if (pressedIndicator && pressedIndicator.color != disabledColor)
74+
pressedIndicator.color = disabledColor;
7275
}
7376
}
7477

75-
// We want the label for the action name to update in edit mode, too, so
76-
// we kick that off from here.
78+
// Also update action label in edit-mode
7779
#if UNITY_EDITOR
7880
protected void OnValidate()
7981
{
@@ -84,12 +86,12 @@ protected void OnValidate()
8486

8587
private void UpdateActionLabel()
8688
{
87-
if (m_Text == null)
89+
if (label == null)
8890
return;
8991
if (action != null && action.action != null)
90-
m_Text.text = action.name;
92+
label.text = action.action.name;
9193
else
92-
m_Text.text = string.Empty;
94+
label.text = string.Empty;
9395
}
9496
}
9597
}

Assets/Samples/RebindingUI/InputActionIndicator.prefab

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ RectTransform:
3232
m_ConstrainProportionsScale: 0
3333
m_Children:
3434
- {fileID: 943689430639722906}
35+
- {fileID: 4857538067602185801}
3536
m_Father: {fileID: 0}
3637
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3738
m_AnchorMin: {x: 0.5, y: 0}
@@ -60,7 +61,7 @@ MonoBehaviour:
6061
m_Name:
6162
m_EditorClassIdentifier:
6263
m_Material: {fileID: 0}
63-
m_Color: {r: 0, g: 1, b: 0.19607843, a: 1}
64+
m_Color: {r: 0.30588236, g: 0.7372549, b: 0.30588236, a: 1}
6465
m_RaycastTarget: 1
6566
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
6667
m_Maskable: 1
@@ -90,10 +91,13 @@ MonoBehaviour:
9091
m_Name:
9192
m_EditorClassIdentifier:
9293
action: {fileID: 0}
93-
activeColor: {r: 0, g: 1, b: 0, a: 1}
94-
inactiveColor: {r: 0, g: 0, b: 0, a: 1}
95-
disabledColor: {r: 1, g: 0, b: 0, a: 1}
94+
activeColor: {r: 0.3019758, g: 0.735849, b: 0.3019758, a: 1}
95+
inactiveColor: {r: 0.23529412, g: 0.23529412, b: 0.23529412, a: 1}
96+
disabledColor: {r: 0.764151, g: 0.32079923, b: 0.32079923, a: 1}
9697
duration: 1
98+
performedIndicator: {fileID: 4442569273011091735}
99+
pressedIndicator: {fileID: 1254813625780045290}
100+
label: {fileID: 4072204658071074964}
97101
--- !u!1 &5827664391383982697
98102
GameObject:
99103
m_ObjectHideFlags: 0
@@ -172,4 +176,79 @@ MonoBehaviour:
172176
m_HorizontalOverflow: 0
173177
m_VerticalOverflow: 0
174178
m_LineSpacing: 1
175-
m_Text: Indicator
179+
m_Text:
180+
--- !u!1 &8554363940581882067
181+
GameObject:
182+
m_ObjectHideFlags: 0
183+
m_CorrespondingSourceObject: {fileID: 0}
184+
m_PrefabInstance: {fileID: 0}
185+
m_PrefabAsset: {fileID: 0}
186+
serializedVersion: 6
187+
m_Component:
188+
- component: {fileID: 4857538067602185801}
189+
- component: {fileID: 1513442470749367355}
190+
- component: {fileID: 1254813625780045290}
191+
m_Layer: 5
192+
m_Name: Pressed
193+
m_TagString: Untagged
194+
m_Icon: {fileID: 0}
195+
m_NavMeshLayer: 0
196+
m_StaticEditorFlags: 0
197+
m_IsActive: 1
198+
--- !u!224 &4857538067602185801
199+
RectTransform:
200+
m_ObjectHideFlags: 0
201+
m_CorrespondingSourceObject: {fileID: 0}
202+
m_PrefabInstance: {fileID: 0}
203+
m_PrefabAsset: {fileID: 0}
204+
m_GameObject: {fileID: 8554363940581882067}
205+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
206+
m_LocalPosition: {x: 0, y: 0, z: 0}
207+
m_LocalScale: {x: 1, y: 1, z: 1}
208+
m_ConstrainProportionsScale: 0
209+
m_Children: []
210+
m_Father: {fileID: 1777307397533242038}
211+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
212+
m_AnchorMin: {x: 0.5, y: 0.5}
213+
m_AnchorMax: {x: 0.5, y: 0.5}
214+
m_AnchoredPosition: {x: 0, y: -0.5}
215+
m_SizeDelta: {x: 15, y: 15}
216+
m_Pivot: {x: 0.5, y: 0.5}
217+
--- !u!222 &1513442470749367355
218+
CanvasRenderer:
219+
m_ObjectHideFlags: 0
220+
m_CorrespondingSourceObject: {fileID: 0}
221+
m_PrefabInstance: {fileID: 0}
222+
m_PrefabAsset: {fileID: 0}
223+
m_GameObject: {fileID: 8554363940581882067}
224+
m_CullTransparentMesh: 1
225+
--- !u!114 &1254813625780045290
226+
MonoBehaviour:
227+
m_ObjectHideFlags: 0
228+
m_CorrespondingSourceObject: {fileID: 0}
229+
m_PrefabInstance: {fileID: 0}
230+
m_PrefabAsset: {fileID: 0}
231+
m_GameObject: {fileID: 8554363940581882067}
232+
m_Enabled: 1
233+
m_EditorHideFlags: 0
234+
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
235+
m_Name:
236+
m_EditorClassIdentifier:
237+
m_Material: {fileID: 0}
238+
m_Color: {r: 0.0023497343, g: 1, b: 0, a: 1}
239+
m_RaycastTarget: 1
240+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
241+
m_Maskable: 1
242+
m_OnCullStateChanged:
243+
m_PersistentCalls:
244+
m_Calls: []
245+
m_Sprite: {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
246+
m_Type: 0
247+
m_PreserveAspect: 0
248+
m_FillCenter: 1
249+
m_FillMethod: 4
250+
m_FillAmount: 1
251+
m_FillClockwise: 1
252+
m_FillOrigin: 0
253+
m_UseSpriteMesh: 0
254+
m_PixelsPerUnitMultiplier: 1

0 commit comments

Comments
 (0)