浏览代码

Merging in Cooldown for Lobby Buttons.

/main/staging
当前提交
b536a7a4
共有 10 个文件被更改,包括 192 次插入138 次删除
  1. 24
      Assets/Prefabs/UI/JoinContent.prefab
  2. 42
      Assets/Prefabs/UI/JoinCreateCanvas.prefab
  3. 148
      Assets/Scenes/mainScene.unity
  4. 40
      Assets/Scripts/Game/GameManager.cs
  5. 1
      Assets/Scripts/UI/JoinCreateLobbyUI.cs
  6. 18
      Assets/Scripts/UI/JoinMenuUI.cs
  7. 11
      Assets/Scripts/UI/SpinnerUI.cs
  8. 2
      Assets/Scripts/UI/UIPanelBase.cs
  9. 33
      Assets/Scripts/Lobby/LobbyListHeartbeat.cs
  10. 11
      Assets/Scripts/Lobby/LobbyListHeartbeat.cs.meta

24
Assets/Prefabs/UI/JoinContent.prefab


- component: {fileID: 3931324176504405867}
- component: {fileID: 1462126939442648229}
- component: {fileID: 7550446569341709048}
- component: {fileID: 7645291363343340383}
m_Layer: 5
m_Name: JoinContent
m_TagString: Untagged

m_onVisibilityChange:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 7645291363343340383}
m_TargetAssemblyTypeName: LobbyRooms.RoomsListHeartbeat, LobbyRooms
m_MethodName: SetActive
- m_Target: {fileID: 1462126939442648229}
m_TargetAssemblyTypeName: LobbyRelaySample.UI.JoinMenuUI, LobbyRelaySample
m_MethodName: JoinMenuChangedVisibility
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}

m_BoolArgument: 0
m_CallState: 2
m_LobbyButtonPrefab: {fileID: 7018369548608736188, guid: f6d35a456ba76a24587dce83bd088b7d, type: 3}
m_LobbyCodeField: {fileID: 8659642538454988273}
m_LobbyButtonParent: {fileID: 7824921818678239159}
--- !u!114 &7550446569341709048
MonoBehaviour:

m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &7645291363343340383
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 785260762106121644}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 48ec34a3875818e4690f1bf0be69ccd9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &891284586109156510
GameObject:
m_ObjectHideFlags: 0

- target: {fileID: 7144088886657378797, guid: c9b04951bd45e154b8096955d9bc8a0b, type: 3}
propertyPath: m_Name
value: Spinner
objectReference: {fileID: 0}
- target: {fileID: 7859013680193933450, guid: c9b04951bd45e154b8096955d9bc8a0b, type: 3}
propertyPath: m_text
value: 'Error: Check the console log.'
objectReference: {fileID: 0}
- target: {fileID: 8141644855275361747, guid: c9b04951bd45e154b8096955d9bc8a0b, type: 3}
propertyPath: m_Pivot.x

42
Assets/Prefabs/UI/JoinCreateCanvas.prefab


m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 22.8
m_fontSize: 30.2
m_fontSizeBase: 24
m_fontWeight: 400
m_enableAutoSizing: 1

m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 22.8
m_fontSize: 30.2
m_fontSizeBase: 24
m_fontWeight: 400
m_enableAutoSizing: 1

m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
m_PresetInfoIsWorld: 1
--- !u!114 &5836614391142406752
MonoBehaviour:
m_ObjectHideFlags: 0

m_TransformParent: {fileID: 1119140321553661053}
m_Modifications:
- target: {fileID: 1079176168591545865, guid: 328b912adedf1bc41a44f60a12723cc0, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1079176168591545865, guid: 328b912adedf1bc41a44f60a12723cc0, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Mode
value: 1
objectReference: {fileID: 0}

m_TransformParent: {fileID: 1119140321553661053}
m_Modifications:
- target: {fileID: 433211913614645534, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 433211913614645534, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Mode
value: 1
objectReference: {fileID: 0}

value: 0
objectReference: {fileID: 0}
- target: {fileID: 8242294458145102565, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9032799187230319547, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_Size
value: 0.99999994
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9095321446247494771, guid: c308ffc2a02e5ab4bbe70a8b2e8108c6, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}

148
Assets/Scenes/mainScene.unity


propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_IntArgument
value: 3
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 302677088753936851, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 326167899787007624, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0

propertyPath: m_fontColor32.rgba
value: 4291809231
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2491863691556184441, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2545639037669962845, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0

objectReference: {fileID: 0}
- target: {fileID: 2637199316291327119, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: -12.500015
value: -12.5
objectReference: {fileID: 0}
- target: {fileID: 2637199316850714327, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_PresetInfoIsWorld

objectReference: {fileID: 0}
- target: {fileID: 4822032080772604407, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.00006490946
value: 0
value: -0.2306938
value: -0.000015258789
objectReference: {fileID: 0}
- target: {fileID: 4824240073023402834, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y

propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Mode
value: 6
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Target
value:
objectReference: {fileID: 2637199315837045700}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_CallState
value: 2
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_MethodName
value: set_isOn
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_TargetAssemblyTypeName
value: UnityEngine.UI.Toggle, UnityEngine.UI
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_BoolArgument
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5016612605613956886, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_ObjectArgumentAssemblyTypeName
value: UnityEngine.Object, UnityEngine
objectReference: {fileID: 0}
- target: {fileID: 5044563295281636569, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0

value: 0
objectReference: {fileID: 0}
- target: {fileID: 5164090239530900493, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5451244976481318432, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}

propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7138194943800857534, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7198558056629795013, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
propertyPath: m_fontSize
value: 35.8

propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 4928485776352161055, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
--- !u!114 &2637199315837045694 stripped
MonoBehaviour:

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a03b37d5b8df06948b36dfbc430a1ea5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &2637199315837045700 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7695022432396603176, guid: f1d618bdc6f1813449d428126e640aa5, type: 3}
m_PrefabInstance: {fileID: 2637199315837045693}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &7716713812904700119

40
Assets/Scripts/Game/GameManager.cs


using System;
using LobbyRelaySample.Relay;
using System.Collections;
using System.Collections.Generic;

private LobbyContentHeartbeat m_lobbyContentHeartbeat = new LobbyContentHeartbeat();
private RelayUtpSetup m_relaySetup;
private RelayUtpClient m_relayClient;
// The Lobby API rate limits query requests to one every 1.5s, and it will return a 429 "Too Many Requests" error otherwise.
private const float k_lobbyAssignmentCoolingSeconds = 1.5f;
private bool m_coolingDown;
/// <summary>Rather than a setter, this is usable in-editor. It won't accept an enum, however.</summary>
public void SetLobbyColorFilter(int color) { m_lobbyColorFilter = (LobbyColor)color; }

}
else if (type == MessageType.CreateLobbyRequest)
{
if (!LobbyRequestCooledDown())
return;
OnCreatedLobby();
},
OnFailedJoin);
OnCreatedLobby();
},
OnFailedJoin);
if (!LobbyRequestCooledDown())
return;
OnJoinedLobby();
},
OnFailedJoin);
OnJoinedLobby();
},
OnFailedJoin);
if (!LobbyRequestCooledDown())
return;
m_lobbyServiceData.State = LobbyQueryState.Fetching;
LobbyAsyncRequests.Instance.RetrieveLobbyListAsync(
qr => {

{ Component.Destroy(m_relayClient);
m_relayClient = null;
}
}
private bool LobbyRequestCooledDown()
{
if (m_coolingDown)
return false;
StartCoroutine(RequestCoolDown());
return true;
}
private IEnumerator RequestCoolDown()
{
m_coolingDown = true;
yield return new WaitForSeconds(k_lobbyAssignmentCoolingSeconds);
m_coolingDown = false;
}
/// <summary>

1
Assets/Scripts/UI/JoinCreateLobbyUI.cs


if (observed.State == GameState.JoinMenu)
{
Show();
Locator.Get.Messenger.OnReceiveMessage(MessageType.QueryLobbies, null);
}
else
{

18
Assets/Scripts/UI/JoinMenuUI.cs


using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

{
[SerializeField]
LobbyButtonUI m_LobbyButtonPrefab;
[SerializeField]
TMP_InputField m_LobbyCodeField;
[SerializeField]
RectTransform m_LobbyButtonParent;

RemoveLobbyButton(m_LocalLobby[key]);
}
bool CanDisplay(LocalLobby lobby)
public void JoinMenuChangedVisibility(bool show)
{
if (show)
OnRefresh();
}
private bool CanDisplay(LocalLobby lobby)
{
return lobby.Data.State == LobbyState.Lobby && !lobby.Private;
}

/// </summary>
void AddNewLobbyButton(string lobbyCode, LocalLobby lobby)
private void AddNewLobbyButton(string lobbyCode, LocalLobby lobby)
{
var lobbyButtonInstance = Instantiate(m_LobbyButtonPrefab, m_LobbyButtonParent);
lobbyButtonInstance.GetComponent<LocalLobbyObserver>().BeginObserving(lobby);

m_LocalLobby.Add(lobbyCode, lobby);
}
void UpdateLobbyButton(string lobbyCode, LocalLobby lobby)
private void UpdateLobbyButton(string lobbyCode, LocalLobby lobby)
void RemoveLobbyButton(LocalLobby lobby)
private void RemoveLobbyButton(LocalLobby lobby)
{
var lobbyID = lobby.LobbyID;
var lobbyButton = m_LobbyButtons[lobbyID];

11
Assets/Scripts/UI/SpinnerUI.cs


errorTextVisibility.Show();
var errorString = new StringBuilder();
errorString.Append("Error");
var codeString = ": " + observed.lastErrorCode;
if (observed.lastErrorCode < 1)
codeString = ".";
errorString.Append(": ");
if (observed.lastErrorCode > 0)
{
errorString.Append(observed.lastErrorCode);
errorString.Append(", ");
}
errorString.Append("Check Unity Console Log for Details.");
errorString.Append(codeString);
errorText.SetText(errorString.ToString());
}
else if (observed.State == LobbyQueryState.Fetched)

2
Assets/Scripts/UI/UIPanelBase.cs


public class UIPanelBase : MonoBehaviour
{
[SerializeField]
private UnityEvent<bool> m_onVisibilityChange;
protected UnityEvent<bool> m_onVisibilityChange;
bool showing;
CanvasGroup m_canvasGroup;

33
Assets/Scripts/Lobby/LobbyListHeartbeat.cs


using UnityEngine;
namespace LobbyRelaySample
{
/// <summary>
/// Keeps the lobby list updated automatically.
/// </summary>
public class LobbyListHeartbeat : MonoBehaviour
{
private const float k_refreshRate = 5;
private float m_refreshTimer = 0;
// This is called in-editor via events.
public void SetActive(bool isActive)
{
if (isActive)
Locator.Get.UpdateSlow.Subscribe(OnUpdate);
else
Locator.Get.UpdateSlow.Unsubscribe(OnUpdate);
m_refreshTimer = 0;
}
private void OnUpdate(float dt)
{
m_refreshTimer += dt;
if (m_refreshTimer > k_refreshRate)
{
Locator.Get.Messenger.OnReceiveMessage(MessageType.QueryLobbies, null);
m_refreshTimer = 0;
}
}
}
}

11
Assets/Scripts/Lobby/LobbyListHeartbeat.cs.meta


fileFormatVersion: 2
guid: 48ec34a3875818e4690f1bf0be69ccd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存