nathaniel.buck@unity3d.com
3 年前
当前提交
c90240f8
共有 16 个文件被更改,包括 339 次插入 和 248 次删除
-
118Assets/Prefabs/UI/GameCanvas.prefab
-
71Assets/Prefabs/UI/PopUpUI.prefab
-
79Assets/Scenes/mainScene.unity
-
20Assets/Scripts/Infrastructure/AsyncRequest.cs
-
42Assets/Scripts/Infrastructure/LogHandler.cs
-
32Assets/Scripts/Infrastructure/LogHandlerSettings.cs
-
1Assets/Scripts/Infrastructure/Messenger.cs
-
20Assets/Scripts/Lobby/LobbyAPIInterface.cs
-
59Assets/Scripts/Relay/RelayAPIInterface.cs
-
4Assets/Scripts/Relay/RelayUtpClient.cs
-
1Assets/Scripts/Tests/PlayMode/RelayRoundTripTests.cs
-
55Assets/Scripts/UI/PopUpUI.cs
-
31Assets/Scripts/Lobby/AsyncRequestLobby.cs
-
11Assets/Scripts/Lobby/AsyncRequestLobby.cs.meta
-
32Assets/Scripts/Relay/AsyncRequestRelay.cs
-
11Assets/Scripts/Relay/AsyncRequestRelay.cs.meta
|
|||
using LobbyRelaySample.UI; |
|||
using System.Text; |
|||
using UnityEngine.Serialization; |
|||
using UnityEngine.UI; |
|||
/// <summary>
|
|||
/// Controls a pop-up message that lays over the rest of the UI, with a button to dismiss. Used for displaying player-facing error messages.
|
|||
/// </summary>
|
|||
TMP_InputField m_popupText; |
|||
private TMP_InputField m_popupText; |
|||
[SerializeField] |
|||
private CanvasGroup m_buttonVisibility; |
|||
private float m_buttonVisibilityTimeout = -1; |
|||
private StringBuilder m_currentText = new StringBuilder(); |
|||
|
|||
private void Awake() |
|||
{ |
|||
gameObject.SetActive(false); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// If the pop-up is not currently visible, display it. If it is, append the incoming text to the existing pop-up.
|
|||
/// </summary>
|
|||
public void ShowPopup(string newText) |
|||
{ |
|||
if (!gameObject.activeSelf) |
|||
{ m_currentText.Clear(); |
|||
gameObject.SetActive(true); |
|||
} |
|||
m_currentText.AppendLine(newText); |
|||
m_popupText.SetTextWithoutNotify(m_currentText.ToString()); |
|||
DisableButton(); |
|||
} |
|||
|
|||
private void DisableButton() |
|||
{ |
|||
m_buttonVisibilityTimeout = 0.5f; // Briefly prevent the popup from being dismissed, to ensure the player doesn't accidentally click past it without seeing it.
|
|||
m_buttonVisibility.alpha = 0.5f; |
|||
m_buttonVisibility.interactable = false; |
|||
} |
|||
private void ReenableButton() |
|||
{ |
|||
m_buttonVisibility.alpha = 1; |
|||
m_buttonVisibility.interactable = true; |
|||
} |
|||
public void ShowPopup(string newText, Color textColor = default) |
|||
private void Update() |
|||
m_popupText.SetTextWithoutNotify(newText); |
|||
m_popupText.textComponent.color = textColor; |
|||
if (m_buttonVisibilityTimeout >= 0 && m_buttonVisibilityTimeout - Time.deltaTime < 0) |
|||
ReenableButton(); |
|||
m_buttonVisibilityTimeout -= Time.deltaTime; |
|||
public void Delete() |
|||
public void ClearPopup() |
|||
Destroy(gameObject); |
|||
gameObject.SetActive(false); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using Unity.Services.Lobbies; |
|||
|
|||
namespace LobbyRelaySample.lobby |
|||
{ |
|||
public class AsyncRequestLobby : AsyncRequest |
|||
{ |
|||
private static AsyncRequestLobby s_instance; |
|||
public static AsyncRequestLobby Instance |
|||
{ |
|||
get |
|||
{ if (s_instance == null) |
|||
s_instance = new AsyncRequestLobby(); |
|||
return s_instance; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The Lobby service will wrap HTTP errors in LobbyServiceExceptions. We can filter on LobbyServiceException.Reason for custom behavior.
|
|||
/// </summary>
|
|||
protected override void ParseServiceException(Exception e) |
|||
{ |
|||
if (!(e is LobbyServiceException)) |
|||
return; |
|||
var lobbyEx = e as LobbyServiceException; |
|||
if (lobbyEx.Reason == LobbyExceptionReason.RateLimited) // We have other ways of preventing players from hitting the rate limit, so the developer-facing 429 error is sufficient here.
|
|||
return; |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, $"Lobby Error: {lobbyEx.Message} ({lobbyEx.InnerException.Message})"); // Lobby error type, then HTTP error type.
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 06b074cf2a829884caf9f52a29d33e5b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.Services.Relay; |
|||
|
|||
namespace LobbyRelaySample.relay |
|||
{ |
|||
public class AsyncRequestRelay : AsyncRequest |
|||
{ |
|||
private static AsyncRequestRelay s_instance; |
|||
public static AsyncRequestRelay Instance |
|||
{ |
|||
get |
|||
{ if (s_instance == null) |
|||
s_instance = new AsyncRequestRelay(); |
|||
return s_instance; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The Relay service will wrap HTTP errors in RelayServiceExceptions. We can filter on RelayServiceException.Reason for custom behavior.
|
|||
/// </summary>
|
|||
protected override void ParseServiceException(Exception e) |
|||
{ |
|||
if (!(e is RelayServiceException)) |
|||
return; |
|||
var relayEx = e as RelayServiceException; |
|||
if (relayEx.Reason == RelayExceptionReason.Unknown) |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, "Relay Error: Relay service had an unknown error."); |
|||
else |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.DisplayErrorPopup, $"Relay Error: {relayEx.Message}"); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3fb80ef44d4dad740b6e2950f0768043 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue