Skip to content

Commit 088e063

Browse files
committed
adding basic usage example
(cherry picked from commit 0b5e875)
1 parent 18cf7c9 commit 088e063

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
4+
using Unity.Multiplayer.Samples.BossRoom.Shared;
5+
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
36
using Unity.Netcode;
47
using UnityEngine;
58
using UnityEngine.Assertions;
@@ -44,6 +47,28 @@ public class ServerBossRoomState : GameStateBehaviour
4447
//the lifetime of the ServerBossRoomState).
4548
private List<ulong> m_HeroIds = new List<ulong>();
4649

50+
[Inject]
51+
void InjectDependencies(IPublisher<ApplicationController.test> pub, ISubscriber<ApplicationController.test> sub)
52+
{
53+
m_Publisher = pub;
54+
m_sub = sub.Subscribe(Test);
55+
}
56+
57+
void Test(ApplicationController.test test)
58+
{
59+
Debug.Log(test.a);
60+
Debug.Log(test.b);
61+
}
62+
63+
IPublisher<ApplicationController.test> m_Publisher;
64+
65+
IDisposable m_sub;
66+
67+
public override void OnDestroy()
68+
{
69+
m_sub.Dispose();
70+
}
71+
4772
public override void OnNetworkSpawn()
4873
{
4974
if (!IsServer)
@@ -204,6 +229,7 @@ private void SpawnPlayer(ulong clientId, bool lateJoin)
204229

205230
// spawn players characters with destroyWithScene = true
206231
newPlayer.SpawnWithOwnership(clientId, true);
232+
m_Publisher.Publish(new ApplicationController.test());
207233
}
208234

209235
static IEnumerator WaitToReposition(Transform moveTransform, Vector3 newPosition, Quaternion newRotation)

Assets/BossRoom/Scripts/Shared/ApplicationController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ private void Awake()
5555
//buffered message channels hold the latest received message in buffer and pass to any new subscribers
5656
scope.BindBufferedMessageChannelInstance<LobbyListFetchedMessage>();
5757

58+
scope.BindNetworkedMessageChannelInstance<test>("test", sizeof(int) + sizeof(float));
59+
5860
//all the lobby service stuff, bound here so that it persists through scene loads
5961
scope.BindAsSingle<AuthenticationServiceFacade>(); //a manager entity that allows us to do anonymous authentication with unity services
6062
scope.BindAsSingle<LobbyServiceFacade>();
@@ -72,6 +74,12 @@ private void Awake()
7274
Application.targetFrameRate = 120;
7375
}
7476

77+
public struct test
78+
{
79+
public int a;
80+
public float b;
81+
}
82+
7583
private void Start()
7684
{
7785
SceneManager.LoadScene("MainMenu");

0 commit comments

Comments
 (0)