浏览代码
Shifting the target sequence tracking to the host. Adding in scores and UI for them. These both warranted shifting some of the input handling to stay on the host, so that anything that involves validating input and awarding points is serverside.
/main/staging/ngo_minigame_structure
Shifting the target sequence tracking to the host. Adding in scores and UI for them. These both warranted shifting some of the input handling to stay on the host, so that anything that involves validating input and awarding points is serverside.
/main/staging/ngo_minigame_structure
nathaniel.buck@unity3d.com
3 年前
当前提交
e429e5b7
共有 8 个文件被更改,包括 403 次插入 和 40 次删除
-
287Assets/Prefabs/InGame/InGameLogic.prefab
-
12Assets/Scripts/Game/InGame/IInGameInputHandler.cs
-
15Assets/Scripts/Game/InGame/InGameRunner.cs
-
2Assets/Scripts/Game/InGame/PlayerCursor.cs
-
46Assets/Scripts/Game/InGame/SequenceSelector.cs
-
18Assets/Scripts/Game/InGame/SymbolObject.cs
-
52Assets/Scripts/Game/InGame/Scorer.cs
-
11Assets/Scripts/Game/InGame/Scorer.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LobbyRelaySample.inGame |
|||
namespace LobbyRelaySample.inGame |
|||
void OnPlayerInput(SymbolObject selectedSymbol); |
|||
void OnPlayerInput(ulong id, SymbolObject selectedSymbol); |
|||
public void OnPlayerInput(SymbolObject selectedSymbol) { } |
|||
public void OnPlayerInput(ulong id, SymbolObject selectedSymbol) { } |
|||
public void OnReProvided(IInGameInputHandler previousProvider) { } |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using TMPro; |
|||
using Unity.Netcode; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample.inGame |
|||
{ |
|||
// TODO: I'm using host and server interchangeably...
|
|||
|
|||
/// <summary>
|
|||
/// Used by the host to actually track scores for all players, and by each client to monitor for updates to their own score.
|
|||
/// </summary>
|
|||
public class Scorer : NetworkBehaviour |
|||
{ |
|||
// TODO: Most of the ints could be bytes?
|
|||
private Dictionary<ulong, int> m_scoresByClientId = new Dictionary<ulong, int>(); |
|||
private ulong m_localId; |
|||
[SerializeField] private TMP_Text m_scoreOutputText = default; |
|||
|
|||
public override void OnNetworkSpawn() |
|||
{ |
|||
m_localId = NetworkManager.Singleton.LocalClientId; |
|||
AddClient_ServerRpc(m_localId); |
|||
} |
|||
|
|||
[ServerRpc(RequireOwnership = false)] |
|||
private void AddClient_ServerRpc(ulong id) |
|||
{ |
|||
if (!m_scoresByClientId.ContainsKey(id)) |
|||
m_scoresByClientId.Add(id, 0); |
|||
} |
|||
|
|||
public void ScoreSuccess(ulong id) |
|||
{ |
|||
m_scoresByClientId[id] += 5; |
|||
UpdateScoreOutput_ClientRpc(id, m_scoresByClientId[id]); |
|||
} |
|||
|
|||
public void ScoreFailure(ulong id) |
|||
{ |
|||
m_scoresByClientId[id] -= 1; |
|||
UpdateScoreOutput_ClientRpc(id, m_scoresByClientId[id]); |
|||
} |
|||
|
|||
[ClientRpc] |
|||
private void UpdateScoreOutput_ClientRpc(ulong id, int score) |
|||
{ |
|||
if (m_localId == id) |
|||
m_scoreOutputText.text = score.ToString("00"); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d90dac0e0ae417b4ea7f60baf966db37 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue