From 20fcf118bd1824395eb2bbc96d0602926d87d919 Mon Sep 17 00:00:00 2001 From: Kyle Johnsen Date: Wed, 5 Jan 2022 00:20:54 -0500 Subject: [PATCH] added example of how to do audio groups/message groups --- .../VelGameServer/Example/PlayerController.cs | 28 +++++++++++++++++-- .../Assets/VelGameServer/NetworkPlayer.cs | 12 +++++++- start_mac.sh | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/TestVelGameServer/Assets/VelGameServer/Example/PlayerController.cs b/TestVelGameServer/Assets/VelGameServer/Example/PlayerController.cs index 9cc71c5..4228b46 100644 --- a/TestVelGameServer/Assets/VelGameServer/Example/PlayerController.cs +++ b/TestVelGameServer/Assets/VelGameServer/Example/PlayerController.cs @@ -20,6 +20,8 @@ public class PlayerController : NetworkObject, Dissonance.IDissonancePlayer public Vector3 targetPosition; public Quaternion targetRotation; + public List closePlayers = new List(); + public byte[] getSyncMessage() { @@ -124,7 +126,7 @@ public class PlayerController : NetworkObject, Dissonance.IDissonancePlayer byte[] lastAudioIdBytes = BitConverter.GetBytes(lastAudioId++); Buffer.BlockCopy(lastAudioIdBytes, 0, toSend, 0, 4); Buffer.BlockCopy(data.Array, data.Offset, toSend, 4, data.Count); - owner.sendMessage(this, "a", toSend); + owner.sendGroupMessage(this,"close", "a", toSend); } } @@ -158,8 +160,30 @@ public class PlayerController : NetworkObject, Dissonance.IDissonancePlayer // Update is called once per frame void Update() { + if (owner != null && owner.isLocal) { - + PlayerController[] players = GameObject.FindObjectsOfType(); + bool shouldUpdate = false; + for (int i = 0; i < players.Length; i++) + { + if (players[i] == this) { continue; } + float dist = Vector3.Distance(players[i].transform.position, this.transform.position); + if (dist < 2 && !closePlayers.Contains(players[i].owner.userid)) + { + closePlayers.Add(players[i].owner.userid); + shouldUpdate = true; + } + else if(dist >=2 && closePlayers.Contains(players[i].owner.userid)) + { + closePlayers.Remove(players[i].owner.userid); + shouldUpdate = true; + } + } + if (shouldUpdate) + { + owner.manager.setupMessageGroup("close", closePlayers.ToArray()); + } + } if (owner != null && !owner.isLocal) diff --git a/TestVelGameServer/Assets/VelGameServer/NetworkPlayer.cs b/TestVelGameServer/Assets/VelGameServer/NetworkPlayer.cs index 336d79b..ff2751f 100644 --- a/TestVelGameServer/Assets/VelGameServer/NetworkPlayer.cs +++ b/TestVelGameServer/Assets/VelGameServer/NetworkPlayer.cs @@ -159,7 +159,17 @@ public class NetworkPlayer : MonoBehaviour //FindObjectsOfType(); } - + public void sendGroupMessage(NetworkObject obj, string group, string identifier, byte[] data) + { + if (obj == myObject) + { + manager.sendToGroup(group, "1," + identifier + "," + Convert.ToBase64String(data)); + } + else + { + manager.sendToGroup(group, "5," + obj.networkId + "," + identifier + "," + Convert.ToBase64String(data)); + } + } public void sendMessage(NetworkObject obj, string identifier, byte[] data) { if (obj == myObject) diff --git a/start_mac.sh b/start_mac.sh index 295f539..972be19 100755 --- a/start_mac.sh +++ b/start_mac.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -./TestVelGameServer/Build/macbuild.app/Contents/MacOS/TestVelGameServer & +./TestVelGameServer/Build/velnetunityexample.app/Contents/MacOS/VelNetUnity &