Skip to content

feat: NetcodeHooks added to restore previous IsServer/IsClient logic-gating [MTT-4054] [MTT-4056] #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions Assets/Prefabs/State/BossRoomState.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 5655447013084909147}
- component: {fileID: -1764033382396218637}
- component: {fileID: 3608714310874968837}
- component: {fileID: -1764033382396218637}
- component: {fileID: 5762482089640033414}
- component: {fileID: 1290852967062359934}
m_Layer: 0
m_Name: BossRoomState
m_TagString: Untagged
Expand Down Expand Up @@ -42,7 +43,7 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-1764033382396218637
--- !u!114 &3608714310874968837
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -51,14 +52,14 @@ MonoBehaviour:
m_GameObject: {fileID: 297185343939699586}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e631ac38df479741af592cf6a1fb553, type: 3}
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
parentReference:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
--- !u!114 &3608714310874968837
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &-1764033382396218637
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -67,13 +68,13 @@ MonoBehaviour:
m_GameObject: {fileID: 297185343939699586}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Script: {fileID: 11500000, guid: 5e631ac38df479741af592cf6a1fb553, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
parentReference:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
--- !u!114 &5762482089640033414
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -90,6 +91,7 @@ MonoBehaviour:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
m_NetcodeHooks: {fileID: 1290852967062359934}
m_NetworkGameStateTransform: {fileID: 11400000, guid: 07bddcdf06738e74cb79d30065ff96af, type: 2}
m_PlayerPrefab: {fileID: 6009713983291384767, guid: 8237adf32a9b6de4892e6febe6b4bdef, type: 3}
m_PlayerSpawnPoints:
Expand All @@ -101,6 +103,18 @@ MonoBehaviour:
- {fileID: 6314369147267609336}
- {fileID: 8725901042666772653}
- {fileID: 7239491272522478247}
--- !u!114 &1290852967062359934
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 297185343939699586}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6aedfcf74b3f4f248897af16490caa9d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1088799320945899822
GameObject:
m_ObjectHideFlags: 0
Expand Down
15 changes: 15 additions & 0 deletions Assets/Prefabs/State/CharSelectState.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 3565665953789623675}
- component: {fileID: 3565665953789623674}
- component: {fileID: 3565665953789623673}
- component: {fileID: 8494646029522094751}
m_Layer: 0
m_Name: CharSelectState
m_TagString: Untagged
Expand Down Expand Up @@ -67,6 +68,7 @@ MonoBehaviour:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
m_NetcodeHooks: {fileID: 8494646029522094751}
--- !u!114 &3565665953789623674
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -83,6 +85,7 @@ MonoBehaviour:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
m_NetcodeHooks: {fileID: 8494646029522094751}
m_AnimationTriggerOnCharSelect: BeginRevive
m_AnimationTriggerOnCharChosen: BeginRevive
m_PlayerSeats:
Expand Down Expand Up @@ -146,3 +149,15 @@ MonoBehaviour:
- {fileID: 11400000, guid: f49fc0646d4e9554f88a31ac496afd19, type: 2}
- {fileID: 11400000, guid: 70d299733c76b0649852336624091fca, type: 2}
- {fileID: 11400000, guid: 9cc69a593b6ff1b4b95bf7330ec5ab46, type: 2}
--- !u!114 &8494646029522094751
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3565665953789623672}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6aedfcf74b3f4f248897af16490caa9d, type: 3}
m_Name:
m_EditorClassIdentifier:
40 changes: 27 additions & 13 deletions Assets/Prefabs/State/PostGameState.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 7475764267130300179}
- component: {fileID: 7475764267130300178}
- component: {fileID: -1007214952234040975}
- component: {fileID: 7475764267130300178}
- component: {fileID: 4223400095609434710}
- component: {fileID: 6576822806953781696}
m_Layer: 0
m_Name: PostGameState
m_TagString: Untagged
Expand All @@ -34,7 +35,7 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7475764267130300178
--- !u!114 &-1007214952234040975
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -43,14 +44,14 @@ MonoBehaviour:
m_GameObject: {fileID: 7475764267130300177}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a2a5cf2c4e970b64a9073f4f760322b5, type: 3}
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
parentReference:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
--- !u!114 &-1007214952234040975
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &7475764267130300178
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -59,13 +60,14 @@ MonoBehaviour:
m_GameObject: {fileID: 7475764267130300177}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Script: {fileID: 11500000, guid: a2a5cf2c4e970b64a9073f4f760322b5, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 951099334
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
parentReference:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
m_NetcodeHooks: {fileID: 6576822806953781696}
--- !u!114 &4223400095609434710
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -82,3 +84,15 @@ MonoBehaviour:
TypeName: Unity.Multiplayer.Samples.BossRoom.Shared.ApplicationController
autoRun: 1
autoInjectGameObjects: []
--- !u!114 &6576822806953781696
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475764267130300177}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6aedfcf74b3f4f248897af16490caa9d, type: 3}
m_Name:
m_EditorClassIdentifier:
4 changes: 2 additions & 2 deletions Assets/Scenes/MainMenu.unity
Git LFS file not shown
12 changes: 0 additions & 12 deletions Assets/Scripts/Gameplay/GameState/CharSelectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ private void Awake()
m_LobbyPlayers = new NetworkList<LobbyPlayerState>();
}

public Action OnNetworkSpawnCallback;
public override void OnNetworkSpawn()
{
OnNetworkSpawnCallback();
}

public Action OnNetworkDespawnCallback;
public override void OnNetworkDespawn()
{
OnNetworkDespawnCallback();
}

/// <summary>
/// Current state of all players in the lobby.
/// </summary>
Expand Down
13 changes: 9 additions & 4 deletions Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Unity.Multiplayer.Samples.Utilities;
using Unity.Netcode;
using VContainer;

Expand All @@ -10,13 +11,17 @@ namespace Unity.Multiplayer.Samples.BossRoom.Client
/// <summary>
/// Client specialization of the Character Select game state. Mainly controls the UI during character-select.
/// </summary>
[RequireComponent(typeof(NetcodeHooks))]
public class ClientCharSelectState : GameStateBehaviour
{
/// <summary>
/// Reference to the scene's state object so that UI can access state
/// </summary>
public static ClientCharSelectState Instance { get; private set; }

[SerializeField]
NetcodeHooks m_NetcodeHooks;

public override GameState ActiveState { get { return GameState.CharSelect; } }
public CharSelectData CharSelectData { get; private set; }

Expand Down Expand Up @@ -111,8 +116,8 @@ protected override void Awake()
// TODO inject or find another way to find CharSelectData
// TODO CharSelectData should directly be in ServerCharSelectState
CharSelectData = FindObjectOfType<CharSelectData>();
CharSelectData.OnNetworkSpawnCallback += OnSpawn; if (CharSelectData.IsSpawned) OnSpawn();
CharSelectData.OnNetworkDespawnCallback += OnDespawn;
m_NetcodeHooks.OnNetworkSpawnHook += OnNetworkSpawn;
m_NetcodeHooks.OnNetworkDespawnHook += OnNetworkDespawn;

m_LobbyUIElementsByMode = new Dictionary<LobbyMode, List<GameObject>>()
{
Expand Down Expand Up @@ -145,7 +150,7 @@ protected override void Start()
UpdateCharacterSelection(CharSelectData.SeatState.Inactive);
}

public void OnDespawn()
void OnNetworkDespawn()
{
if (CharSelectData)
{
Expand All @@ -154,7 +159,7 @@ public void OnDespawn()
}
}

public void OnSpawn()
void OnNetworkSpawn()
{
if (!NetworkManager.Singleton.IsClient)
{
Expand Down
Loading