Skip to content

Commit 5ac5788

Browse files
authored
[MTT-9853] Improve Mobile UI (#266)
* wip: Mobile UI refactor * wip: Touch UI working * wip: Mobile UI improvements * feat: Only allow landscape mode * feat: Manage keyboard on Mobile * feat: make settings ui touchable * chore: rename * chore: extract class * chore: cleanup unnecessary changes * chore: Improve folder structure * chore: remove unnecessary icon * chore: Cleanup Event registration * chore: cleanup * feat: Add stylesheet overwrite * chore: renaming, restructure etc. * feat: increase audio distance * docsL: readd comment * chore: remove warnings about changed path to textures * feat: improve focus states * feat: align touch input button styles to the rest of the UI * feat: improve colapse button
1 parent 190f3c2 commit 5ac5788

File tree

69 files changed

+1063
-645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1063
-645
lines changed

Basic/DistributedAuthoritySocialHub/Assets/Prefabs/UI/IngameUI.prefab

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GameObject:
1111
- component: {fileID: 8260601768609746557}
1212
- component: {fileID: 2624134516453966882}
1313
- component: {fileID: 7977430163742817466}
14+
- component: {fileID: 6103793809426782772}
1415
m_Layer: 0
1516
m_Name: WorldspaceUIContainer
1617
m_TagString: Untagged
@@ -96,6 +97,20 @@ UIRenderer:
9697
m_SortingLayerID: 0
9798
m_SortingLayer: 0
9899
m_SortingOrder: 0
100+
--- !u!114 &6103793809426782772
101+
MonoBehaviour:
102+
m_ObjectHideFlags: 0
103+
m_CorrespondingSourceObject: {fileID: 0}
104+
m_PrefabInstance: {fileID: 0}
105+
m_PrefabAsset: {fileID: 0}
106+
m_GameObject: {fileID: 3209112381140291289}
107+
m_Enabled: 1
108+
m_EditorHideFlags: 0
109+
m_Script: {fileID: 11500000, guid: c3f1e8062945c4f4d846b5dd47a10b49, type: 3}
110+
m_Name:
111+
m_EditorClassIdentifier:
112+
m_Stylesheet:
113+
- {fileID: 7433441132597879392, guid: ea9efe379dfd4506ad59f7fe609e1c85, type: 3}
99114
--- !u!1 &3760817242580890973
100115
GameObject:
101116
m_ObjectHideFlags: 0
@@ -227,8 +242,8 @@ Transform:
227242
- {fileID: 2256034313796960807}
228243
- {fileID: 7559383771208540613}
229244
- {fileID: 8481058004063830698}
230-
- {fileID: 6866794867799222920}
231245
- {fileID: 7817311818480281289}
246+
- {fileID: 6866794867799222920}
232247
m_Father: {fileID: 0}
233248
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
234249
--- !u!1 &5231826839060252271
@@ -241,6 +256,7 @@ GameObject:
241256
m_Component:
242257
- component: {fileID: 3336661237540986728}
243258
- component: {fileID: 436460152536684898}
259+
- component: {fileID: 7317808533901021140}
244260
m_Layer: 0
245261
m_Name: ScreenspaceUIContainer
246262
m_TagString: Untagged
@@ -282,6 +298,20 @@ MonoBehaviour:
282298
m_WorldSpaceSizeMode: 1
283299
m_WorldSpaceWidth: 1920
284300
m_WorldSpaceHeight: 1080
301+
--- !u!114 &7317808533901021140
302+
MonoBehaviour:
303+
m_ObjectHideFlags: 0
304+
m_CorrespondingSourceObject: {fileID: 0}
305+
m_PrefabInstance: {fileID: 0}
306+
m_PrefabAsset: {fileID: 0}
307+
m_GameObject: {fileID: 5231826839060252271}
308+
m_Enabled: 1
309+
m_EditorHideFlags: 0
310+
m_Script: {fileID: 11500000, guid: c3f1e8062945c4f4d846b5dd47a10b49, type: 3}
311+
m_Name:
312+
m_EditorClassIdentifier:
313+
m_Stylesheet:
314+
- {fileID: 7433441132597879392, guid: ea9efe379dfd4506ad59f7fe609e1c85, type: 3}
285315
--- !u!1 &6990578997068127384
286316
GameObject:
287317
m_ObjectHideFlags: 0
@@ -339,7 +369,6 @@ GameObject:
339369
serializedVersion: 6
340370
m_Component:
341371
- component: {fileID: 7817311818480281289}
342-
- component: {fileID: 2936985890301440173}
343372
- component: {fileID: 6707317209091797481}
344373
m_Layer: 0
345374
m_Name: TouchUI
@@ -363,25 +392,6 @@ Transform:
363392
m_Children: []
364393
m_Father: {fileID: 8617889547341104717}
365394
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
366-
--- !u!114 &2936985890301440173
367-
MonoBehaviour:
368-
m_ObjectHideFlags: 0
369-
m_CorrespondingSourceObject: {fileID: 0}
370-
m_PrefabInstance: {fileID: 0}
371-
m_PrefabAsset: {fileID: 0}
372-
m_GameObject: {fileID: 7432143492640579472}
373-
m_Enabled: 1
374-
m_EditorHideFlags: 0
375-
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
376-
m_Name:
377-
m_EditorClassIdentifier:
378-
m_PanelSettings: {fileID: 11400000, guid: f87c14ce92c804cf2a078e05e3ee2019, type: 2}
379-
m_ParentUI: {fileID: 0}
380-
sourceAsset: {fileID: 9197481963319205126, guid: ccd45339dc8ff154fbbe578856089eaf, type: 3}
381-
m_SortingOrder: 0
382-
m_WorldSpaceSizeMode: 1
383-
m_WorldSpaceWidth: 1920
384-
m_WorldSpaceHeight: 1080
385395
--- !u!114 &6707317209091797481
386396
MonoBehaviour:
387397
m_ObjectHideFlags: 0
@@ -394,6 +404,8 @@ MonoBehaviour:
394404
m_Script: {fileID: 11500000, guid: 6d7e4e4868ed5df4b928c22423c690a0, type: 3}
395405
m_Name:
396406
m_EditorClassIdentifier:
407+
m_Document: {fileID: 436460152536684898}
408+
m_TouchscreenUI: {fileID: 9197481963319205126, guid: ccd45339dc8ff154fbbe578856089eaf, type: 3}
397409
--- !u!1 &7898239706649082948
398410
GameObject:
399411
m_ObjectHideFlags: 0

Basic/DistributedAuthoritySocialHub/Assets/Scenes/MainMenu.unity

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ GameObject:
343343
- component: {fileID: 378839173}
344344
- component: {fileID: 378839172}
345345
- component: {fileID: 378839174}
346+
- component: {fileID: 378839175}
346347
m_Layer: 0
347348
m_Name: MainMenuUI
348349
m_TagString: Untagged
@@ -399,6 +400,20 @@ MonoBehaviour:
399400
m_EditorClassIdentifier:
400401
IsModal: 0
401402
m_HomeView: {fileID: 2105351336}
403+
--- !u!114 &378839175
404+
MonoBehaviour:
405+
m_ObjectHideFlags: 0
406+
m_CorrespondingSourceObject: {fileID: 0}
407+
m_PrefabInstance: {fileID: 0}
408+
m_PrefabAsset: {fileID: 0}
409+
m_GameObject: {fileID: 378839171}
410+
m_Enabled: 1
411+
m_EditorHideFlags: 0
412+
m_Script: {fileID: 11500000, guid: c3f1e8062945c4f4d846b5dd47a10b49, type: 3}
413+
m_Name:
414+
m_EditorClassIdentifier:
415+
m_Stylesheet:
416+
- {fileID: 7433441132597879392, guid: ea9efe379dfd4506ad59f7fe609e1c85, type: 3}
402417
--- !u!1 &1088131142
403418
GameObject:
404419
m_ObjectHideFlags: 0

Basic/DistributedAuthoritySocialHub/Assets/Scripts/GameManagement/GameplayEventHandler.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Threading.Tasks;
44
using Unity.Services.Vivox;
5+
using UnityEngine;
56
using UnityEngine.SceneManagement;
67

78
namespace Unity.Multiplayer.Samples.SocialHub.GameManagement
@@ -21,6 +22,8 @@ static class GameplayEventHandler
2122
internal static event Action<VivoxParticipant> OnParticipantJoinedVoiceChat;
2223
internal static event Action<VivoxParticipant> OnParticipantLeftVoiceChat;
2324

25+
internal static event Action<PickupState, Transform> OnPickupStateChanged;
26+
2427
internal static void NetworkObjectDespawned(NetworkObject networkObject)
2528
{
2629
OnNetworkObjectDespawned?.Invoke(networkObject);
@@ -90,5 +93,17 @@ public static void ParticipantLeftVoiceChat(VivoxParticipant vivoxParticipant)
9093
{
9194
OnParticipantLeftVoiceChat?.Invoke(vivoxParticipant);
9295
}
96+
97+
internal static void SetAvatarPickupState(PickupState state, Transform pickup)
98+
{
99+
OnPickupStateChanged?.Invoke(state, pickup);
100+
}
101+
}
102+
103+
internal enum PickupState
104+
{
105+
Inactive,
106+
PickupInRange,
107+
Carry
93108
}
94109
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Player/AvatarInteractions.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class AvatarInteractions : NetworkBehaviour, INetworkUpdateSystem
4949

5050
TransferableObject m_TransferableObject;
5151

52-
PickUpIndicator m_PickUpIndicator;
53-
54-
CarryBoxIndicator m_CarryBoxIndicator;
55-
5652
const float k_MinDurationHeld = 0f;
5753
const float k_MaxDurationHeld = 2f;
5854

@@ -92,9 +88,6 @@ public override void OnNetworkSpawn()
9288

9389
this.RegisterNetworkUpdate(updateStage: NetworkUpdateStage.FixedUpdate);
9490

95-
m_PickUpIndicator = FindFirstObjectByType<PickUpIndicator>();
96-
m_CarryBoxIndicator = FindFirstObjectByType<CarryBoxIndicator>();
97-
9891
GameInput.Actions.Player.Interact.performed += OnInteractPerformed;
9992
GameInput.Actions.Player.Interact.canceled += OnInteractCanceled;
10093

@@ -284,8 +277,7 @@ void StartPickup(TransferableObject other)
284277
// Rotate the player to face the item smoothly
285278
StartCoroutine(SmoothLookAt(other.transform));
286279
m_AvatarNetworkAnimator.SetTrigger(k_PickupId);
287-
m_PickUpIndicator.ClearPickup();
288-
m_CarryBoxIndicator.ShowCarry(m_TransferableObject.transform);
280+
GameplayEventHandler.SetAvatarPickupState(PickupState.Carry, m_TransferableObject.transform);
289281
}
290282

291283
IEnumerator SmoothLookAt(Transform target)
@@ -383,7 +375,7 @@ void DropAction()
383375
SetTransferableObjectAsTransferableDistributable();
384376
OnDropAction();
385377
m_CurrentTransferableObject.Value = new NetworkBehaviourReference();
386-
m_CarryBoxIndicator.HideCarry();
378+
GameplayEventHandler.SetAvatarPickupState(PickupState.Inactive, null);
387379
}
388380

389381
// invoked on all clients
@@ -419,7 +411,7 @@ void ThrowAction(double holdDuration)
419411

420412
OnThrowAction();
421413
m_CurrentTransferableObject.Value = new NetworkBehaviourReference();
422-
m_CarryBoxIndicator.HideCarry();
414+
GameplayEventHandler.SetAvatarPickupState(PickupState.Inactive, null);
423415
}
424416

425417
// invoked on all clients
@@ -493,13 +485,12 @@ void CheckForPickupsInRange()
493485
m_PotentialPickupCollider = resultCollider;
494486
}
495487
}
496-
497-
m_PickUpIndicator.ShowPickup(m_PotentialPickupCollider.transform);
488+
GameplayEventHandler.SetAvatarPickupState(PickupState.PickupInRange, m_PotentialPickupCollider.transform);
498489
}
499490
else
500491
{
501492
m_PotentialPickupCollider = null;
502-
m_PickUpIndicator.ClearPickup();
493+
GameplayEventHandler.SetAvatarPickupState(PickupState.Inactive, null);
503494
}
504495
}
505496

Basic/DistributedAuthoritySocialHub/Assets/Scripts/Services/VivoxManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ namespace Unity.Multiplayer.Samples.SocialHub.Services
1212
{
1313
class VivoxManager : MonoBehaviour
1414
{
15+
const int k_AudibleDistance = 20;
16+
const int k_ConventionalDistance = 1;
17+
const float k_AudioFadeByDistance = 1f;
18+
1519
string m_TextChannelName;
1620
string m_VoiceChannelName;
1721

1822
#if UNITY_STANDALONE_OSX || UNITY_IOS
1923
bool m_MicPermissionChecked;
24+
2025
#endif
2126

2227
internal static VivoxManager Instance { get; private set; }
@@ -76,7 +81,7 @@ async void OnLoggedInVivox()
7681

7782
async Task JoinChannels()
7883
{
79-
var positionalChannelProperties = new Channel3DProperties(10, 1, 1f, AudioFadeModel.InverseByDistance);
84+
var positionalChannelProperties = new Channel3DProperties(k_AudibleDistance, k_ConventionalDistance, k_AudioFadeByDistance, AudioFadeModel.InverseByDistance);
8085
BindChannelEvents(true);
8186
await VivoxService.Instance.JoinPositionalChannelAsync(m_VoiceChannelName, ChatCapability.AudioOnly, positionalChannelProperties);
8287
await VivoxService.Instance.JoinGroupChannelAsync(m_TextChannelName, ChatCapability.TextOnly);

Basic/DistributedAuthoritySocialHub/Assets/Scripts/UI/IngameUI/CarryBoxIndicator.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using Unity.Multiplayer.Samples.SocialHub.GameManagement;
34
using UnityEngine;
45
using UnityEngine.UIElements;
56

@@ -42,9 +43,21 @@ void OnEnable()
4243
m_CarryUI.Q<Label>("call-to-action").text = "tap - drop \nhold - throw";
4344
m_CarryUI.AddToClassList("carrybox");
4445
m_CarryUI.AddToClassList(UIUtils.s_InactiveUSSClass);
46+
47+
GameplayEventHandler.OnPickupStateChanged += OnPickupStateChanged;
4548
}
4649

47-
internal void ShowCarry(Transform t)
50+
void OnPickupStateChanged(PickupState state, Transform pickupTransform)
51+
{
52+
if (state == PickupState.Carry)
53+
{
54+
ShowCarry(pickupTransform);
55+
return;
56+
}
57+
HideCarry();
58+
}
59+
60+
void ShowCarry(Transform t)
4861
{
4962
if (m_IsShown)
5063
return;
@@ -57,7 +70,7 @@ internal void ShowCarry(Transform t)
5770
m_IsShown = true;
5871
}
5972

60-
internal void HideCarry()
73+
void HideCarry()
6174
{
6275
if(m_IsShown == false)
6376
return;
@@ -84,5 +97,10 @@ void Update()
8497
var mappedScale = Mathf.Lerp(m_PanelMaxSize, m_PanelMinSize, Mathf.InverseLerp(5, 20, distance));
8598
m_CarryUI.style.scale = new StyleScale(new Vector2(mappedScale, mappedScale));
8699
}
100+
101+
void OnDisable()
102+
{
103+
GameplayEventHandler.OnPickupStateChanged -= OnPickupStateChanged;
104+
}
87105
}
88106
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/UI/IngameUI/IngameMenu.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class IngameMenu : MonoBehaviour
2121

2222
VisualElement m_Root;
2323
VisualElement m_Menu;
24-
VisualElement m_SceenOverlay;
24+
VisualElement m_ScreenOverlay;
2525

2626
Button m_BurgerButton;
2727
Button m_ExitButton;
@@ -41,7 +41,7 @@ void OnEnable()
4141
m_Root = m_UIDocument.rootVisualElement.Q<VisualElement>("ingame-menu-container");
4242
m_Root.Add(m_IngameMenuAsset.CloneTree().GetFirstChild());
4343

44-
m_SceenOverlay = m_Root.Q<VisualElement>("sceen-overlay");
44+
m_ScreenOverlay = m_Root.Q<VisualElement>("screen-overlay");
4545

4646
m_BurgerButton = m_Root.Q<Button>("burger-button");
4747
m_BurgerButton.clicked += ShowMenu;
@@ -117,14 +117,14 @@ void ShowMenu()
117117
InputSystemManager.Instance.EnableUIInputs();
118118
m_Menu.RemoveFromClassList(UIUtils.s_InactiveUSSClass);
119119
m_Menu.AddToClassList(UIUtils.s_ActiveUSSClass);
120-
m_SceenOverlay.style.display = DisplayStyle.Flex;
120+
m_ScreenOverlay.style.display = DisplayStyle.Flex;
121121
m_Menu.SetEnabled(true);
122122
}
123123

124124
void HideMenu()
125125
{
126126
InputSystemManager.Instance.EnableGameplayInputs();
127-
m_SceenOverlay.style.display = DisplayStyle.None;
127+
m_ScreenOverlay.style.display = DisplayStyle.None;
128128
m_Menu.RemoveFromClassList(UIUtils.s_ActiveUSSClass);
129129
m_Menu.AddToClassList(UIUtils.s_InactiveUSSClass);
130130
m_Menu.SetEnabled(false);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Unity.Multiplayer.Samples.SocialHub.Input;
2+
using UnityEngine;
3+
using UnityEngine.UIElements;
4+
5+
namespace Unity.Multiplayer.Samples.SocialHub.UI
6+
{
7+
[RequireComponent(typeof(UIDocument))]
8+
class MobileStylesheetAdder : MonoBehaviour
9+
{
10+
[SerializeField]
11+
StyleSheet[] m_Stylesheet;
12+
13+
async void Awake()
14+
{
15+
var isMobile = await InputSystemManager.IsMobile;
16+
if (!isMobile)
17+
{
18+
return;
19+
}
20+
21+
var uiDocument = GetComponent<UIDocument>();
22+
foreach (var styleSheet in m_Stylesheet)
23+
{
24+
uiDocument.rootVisualElement.styleSheets.Add(styleSheet);
25+
}
26+
}
27+
}
28+
}

Basic/DistributedAuthoritySocialHub/Assets/Scripts/UI/IngameUI/MobileStylesheetAdder.cs.meta

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

0 commit comments

Comments
 (0)