From 71de4357ab7621d86c087f9f8fd9b0482afb871d Mon Sep 17 00:00:00 2001 From: tudor <7089284+tudddorrr@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:49:25 +0100 Subject: [PATCH 1/2] add leaderboard entry caching + update sample --- .../Scenes/LeaderboardsDemo.unity | 26 ++++++-- .../Scripts/LeaderboardUIController.cs | 15 +---- .../Runtime/LeaderboardsAPI.cs | 23 +++++++ .../Utils/LeaderboardEntriesManager.cs | 37 +++++++++++ .../Utils/LeaderboardEntriesManager.cs.meta | 11 ++++ UserSettings/EditorUserSettings.asset | 6 +- UserSettings/Layouts/default-2022.dwlt | 61 +++++++++++-------- 7 files changed, 134 insertions(+), 45 deletions(-) create mode 100644 Packages/com.trytalo.talo/Runtime/Utils/LeaderboardEntriesManager.cs create mode 100644 Packages/com.trytalo.talo/Runtime/Utils/LeaderboardEntriesManager.cs.meta diff --git a/Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity b/Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity index 9c57707..d3e9996 100644 --- a/Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity +++ b/Assets/Samples/LeaderboardsDemo/Scenes/LeaderboardsDemo.unity @@ -104,7 +104,7 @@ NavMeshSettings: serializedVersion: 2 m_ObjectHideFlags: 0 m_BuildSettings: - serializedVersion: 2 + serializedVersion: 3 agentTypeID: 0 agentRadius: 0.5 agentHeight: 2 @@ -117,7 +117,7 @@ NavMeshSettings: cellSize: 0.16666667 manualTileSize: 0 tileSize: 256 - accuratePlacement: 0 + buildHeightMesh: 0 maxJobWorkers: 0 preserveTilesOutsideBounds: 0 debug: @@ -164,13 +164,13 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 373737617} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &373737620 MonoBehaviour: @@ -184,7 +184,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5d32f5ae2f5f7495cb77f079a21c54b0, type: 3} m_Name: m_EditorClassIdentifier: - leaderboardName: uniq + leaderboardName: test-leaderboard --- !u!1 &497470367 GameObject: m_ObjectHideFlags: 0 @@ -225,9 +225,17 @@ Camera: m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 + m_Iso: 200 + m_ShutterSpeed: 0.005 + m_Aperture: 16 + m_FocusDistance: 10 + m_FocalLength: 50 + m_BladeCount: 5 + m_Curvature: {x: 2, y: 11} + m_BarrelClipping: 0.25 + m_Anamorphism: 0 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 m_NormalizedViewPortRect: serializedVersion: 2 x: 0 @@ -261,11 +269,17 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 497470367} + serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: -10} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1660057539 &9223372036854775807 +SceneRoots: + m_ObjectHideFlags: 0 + m_Roots: + - {fileID: 497470370} + - {fileID: 373737619} diff --git a/Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs b/Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs index 631111b..b6a01ff 100644 --- a/Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs +++ b/Assets/Samples/LeaderboardsDemo/Scripts/LeaderboardUIController.cs @@ -12,7 +12,6 @@ public class LeaderboardUIController : MonoBehaviour private VisualElement root; private ListView entriesList; private Label infoLabel; - private List entries = new (); private async void Start() { @@ -38,14 +37,6 @@ private async void OnPostClick() var score = Random.Range(0, 100); (LeaderboardEntry entry, bool updated) = await Talo.Leaderboards.AddEntry(leaderboardName, score); - var idx = entries.FindIndex((existingEntry) => existingEntry.playerAlias.id == entry.playerAlias.id); - if (idx != -1) - { - entries.RemoveAt(idx); - } - - entries.Insert(entry.position, entry); - infoLabel.text = $"You scored {score}."; if (updated) infoLabel.text += " Your highscore was updated!"; @@ -54,7 +45,7 @@ private async void OnPostClick() private void HandleListVisibility() { - if (entries.Count == 0) + if (Talo.Leaderboards.GetCachedEntries(leaderboardName).Count == 0) { infoLabel.text = "There are currently no entries"; } @@ -72,8 +63,6 @@ private async Task LoadEntries() do { var res = await Talo.Leaderboards.GetEntries(leaderboardName, page); - entries.AddRange(res.entries); - page++; done = res.isLastPage; } while (!done); @@ -89,6 +78,8 @@ private async Task LoadEntries() return label; }; + var entries = Talo.Leaderboards.GetCachedEntries(leaderboardName); + entriesList.bindItem = (e, i) => { e.Q