浏览代码
Adding in rate limit events for query operations. Now, the refresh button will be disabled while within the rate limit cooldown, and the lobby data refresh follows it as well (which it did previously, but it was less clear).
/main/staging/rate_limit_data
Adding in rate limit events for query operations. Now, the refresh button will be disabled while within the rate limit cooldown, and the lobby data refresh follows it as well (which it did previously, but it was less clear).
/main/staging/rate_limit_data
nathaniel.buck@unity3d.com
3 年前
当前提交
b9db2078
共有 8 个文件被更改,包括 169 次插入 和 66 次删除
-
72Assets/Prefabs/UI/JoinContent.prefab
-
2Assets/Scripts/Game/GameManager.cs
-
89Assets/Scripts/Lobby/LobbyAsyncRequests.cs
-
9Assets/Scripts/UI/UIPanelBase.cs
-
2Assets/Scripts/UI/RateLimitVisibility.cs.meta
-
35Assets/Scripts/UI/RateLimitVisibility.cs
-
26Assets/Scripts/Lobby/LobbyListHeartbeat.cs
-
0/Assets/Scripts/UI/RateLimitVisibility.cs.meta
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.UI |
|||
{ |
|||
/// <summary>
|
|||
/// Observes the Lobby request rate limits and changes the visibility of a UIPanelBase to suit.
|
|||
/// E.g. the refresh button on the Join menu should be inactive after a refresh for long enough to avoid the lobby query rate limit.
|
|||
/// </summary>
|
|||
public class RateLimitVisibility : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
UIPanelBase m_target; |
|||
[SerializeField] |
|||
float m_alphaWhenHidden = 0.5f; |
|||
[SerializeField] |
|||
LobbyAsyncRequests.RequestType m_requestType; |
|||
|
|||
private void Start() |
|||
{ |
|||
LobbyAsyncRequests.Instance.GetRateLimit(m_requestType).onChanged += UpdateVisibility; |
|||
} |
|||
private void OnDestroy() |
|||
{ |
|||
LobbyAsyncRequests.Instance.GetRateLimit(m_requestType).onChanged -= UpdateVisibility; |
|||
} |
|||
|
|||
private void UpdateVisibility(LobbyAsyncRequests.RateLimitCooldown rateLimit) |
|||
{ |
|||
if (rateLimit.IsInCooldown) |
|||
m_target.Hide(m_alphaWhenHidden); |
|||
else |
|||
m_target.Show(); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
/// <summary>
|
|||
/// Keeps the lobby list updated automatically.
|
|||
/// </summary>
|
|||
public class LobbyListHeartbeat : MonoBehaviour |
|||
{ |
|||
private const float k_refreshRate = 5; |
|||
|
|||
// This is called in-editor via events.
|
|||
public void SetActive(bool isActive) |
|||
{ |
|||
if (isActive) |
|||
Locator.Get.UpdateSlow.Subscribe(OnUpdate, k_refreshRate); |
|||
else |
|||
Locator.Get.UpdateSlow.Unsubscribe(OnUpdate); |
|||
} |
|||
|
|||
private void OnUpdate(float dt) |
|||
{ |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.QueryLobbies, null); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue