Skip to content

Commit 0b5e875

Browse files
committed
adding basic usage example
1 parent c9c6f98 commit 0b5e875

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 22 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.Multiplayer.Samples.BossRoom.Visual;
47
using Unity.Netcode;
58
using UnityEngine;
@@ -45,6 +48,24 @@ public class ServerBossRoomState : GameStateBehaviour
4548
//the lifetime of the ServerBossRoomState).
4649
private List<ulong> m_HeroIds = new List<ulong>();
4750

51+
[Inject]
52+
void InjectDependencies(IPublisher<ApplicationController.test> pub, ISubscriber<ApplicationController.test> sub)
53+
{
54+
m_Publisher = pub;
55+
m_sub = sub.Subscribe(Test);
56+
}
57+
58+
void Test(ApplicationController.test test)
59+
{
60+
Debug.Log(test.a);
61+
Debug.Log(test.b);
62+
m_sub.Dispose();
63+
}
64+
65+
IPublisher<ApplicationController.test> m_Publisher;
66+
67+
IDisposable m_sub;
68+
4869
public override void OnNetworkSpawn()
4970
{
5071
if (!IsServer)
@@ -205,6 +226,7 @@ private void SpawnPlayer(ulong clientId, bool lateJoin)
205226

206227
// spawn players characters with destroyWithScene = true
207228
newPlayer.SpawnWithOwnership(clientId, true);
229+
m_Publisher.Publish(new ApplicationController.test());
208230
}
209231

210232
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
@@ -59,6 +59,8 @@ private void Awake()
5959
//buffered message channels hold the latest received message in buffer and pass to any new subscribers
6060
scope.BindBufferedMessageChannelInstance<LobbyListFetchedMessage>();
6161

62+
scope.BindNetworkedMessageChannelInstance<test>("test", sizeof(int) + sizeof(float));
63+
6264
//all the lobby service stuff, bound here so that it persists through scene loads
6365
scope.BindAsSingle<AuthenticationServiceFacade>(); //a manager entity that allows us to do anonymous authentication with unity services
6466
scope.BindAsSingle<LobbyServiceFacade>();
@@ -76,6 +78,12 @@ private void Awake()
7678
Application.targetFrameRate = 120;
7779
}
7880

81+
public struct test
82+
{
83+
public int a;
84+
public float b;
85+
}
86+
7987
private void Start()
8088
{
8189
SceneManager.LoadScene("MainMenu");

0 commit comments

Comments
 (0)