浏览代码
Pulling the countdown logic out of the GameManager and the LocalLobby; the latter fixes a bug where the countdown would prevent any lobby changes from being pushed from the host, since every from the LocalLobby's OnChanged event would fire.
/main/staging/host_handshake
Pulling the countdown logic out of the GameManager and the LocalLobby; the latter fixes a bug where the countdown would prevent any lobby changes from being pushed from the host, since every from the LocalLobby's OnChanged event would fire.
/main/staging/host_handshake
nathaniel.buck@unity3d.com
3 年前
当前提交
a1a07b92
共有 9 个文件被更改,包括 111 次插入 和 68 次删除
-
13Assets/Prefabs/UI/PlayerInteractionPanel.prefab
-
27Assets/Scenes/mainScene.unity
-
37Assets/Scripts/Game/GameManager.cs
-
12Assets/Scripts/Game/LocalLobby.cs
-
1Assets/Scripts/Infrastructure/Messenger.cs
-
2Assets/Scripts/Infrastructure/Observed.cs
-
10Assets/Scripts/UI/CountdownUI.cs
-
66Assets/Scripts/Game/Countdown.cs
-
11Assets/Scripts/Game/Countdown.cs.meta
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
/// <summary>
|
|||
/// Runs the countdown to the in-game state. While the start of the countdown is synced via Relay, the countdown itself is handled locally,
|
|||
/// since precise timing isn't necessary.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(UI.CountdownUI))] |
|||
public class Countdown : MonoBehaviour, IReceiveMessages |
|||
{ |
|||
public class Data : Observed<Countdown.Data> |
|||
{ |
|||
private float m_timeLeft; |
|||
public float TimeLeft |
|||
{ |
|||
get => m_timeLeft; |
|||
set |
|||
{ m_timeLeft = value; |
|||
OnChanged(this); |
|||
} |
|||
} |
|||
public override void CopyObserved(Data oldObserved) { /*No-op, since this is unnecessary.*/ } |
|||
} |
|||
|
|||
private Data m_data = new Data(); |
|||
private UI.CountdownUI m_ui; |
|||
private const int k_countdownTime = 4; |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
if (m_ui == null) |
|||
m_ui = GetComponent<UI.CountdownUI>(); |
|||
m_data.TimeLeft = -1; |
|||
Locator.Get.Messenger.Subscribe(this); |
|||
m_ui.BeginObserving(m_data); |
|||
} |
|||
public void OnDisable() |
|||
{ |
|||
Locator.Get.Messenger.Unsubscribe(this); |
|||
m_ui.EndObserving(); |
|||
} |
|||
|
|||
public void OnReceiveMessage(MessageType type, object msg) |
|||
{ |
|||
if (type == MessageType.StartCountdown) |
|||
{ |
|||
m_data.TimeLeft = k_countdownTime; |
|||
} |
|||
else if (type == MessageType.CancelCountdown) |
|||
{ |
|||
m_data.TimeLeft = -1; |
|||
} |
|||
} |
|||
|
|||
public void Update() |
|||
{ |
|||
if (m_data.TimeLeft < 0) |
|||
return; |
|||
m_data.TimeLeft -= Time.deltaTime; |
|||
if (m_data.TimeLeft < 0) |
|||
Locator.Get.Messenger.OnReceiveMessage(MessageType.CompleteCountdown, null); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d125c6cac111c6442ac5b07a1f313fa4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue