added example of how to do audio groups/message groups

handTracking
Kyle Johnsen 2022-01-05 00:20:54 -05:00
parent 6c6c7c4833
commit 20fcf118bd
3 changed files with 38 additions and 4 deletions

View File

@ -20,6 +20,8 @@ public class PlayerController : NetworkObject, Dissonance.IDissonancePlayer
public Vector3 targetPosition; public Vector3 targetPosition;
public Quaternion targetRotation; public Quaternion targetRotation;
public List<int> closePlayers = new List<int>();
public byte[] getSyncMessage() public byte[] getSyncMessage()
{ {
@ -124,7 +126,7 @@ public class PlayerController : NetworkObject, Dissonance.IDissonancePlayer
byte[] lastAudioIdBytes = BitConverter.GetBytes(lastAudioId++); byte[] lastAudioIdBytes = BitConverter.GetBytes(lastAudioId++);
Buffer.BlockCopy(lastAudioIdBytes, 0, toSend, 0, 4); Buffer.BlockCopy(lastAudioIdBytes, 0, toSend, 0, 4);
Buffer.BlockCopy(data.Array, data.Offset, toSend, 4, data.Count); 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 // Update is called once per frame
void Update() void Update()
{ {
if (owner != null && owner.isLocal) {
PlayerController[] players = GameObject.FindObjectsOfType<PlayerController>();
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) if (owner != null && !owner.isLocal)

View File

@ -159,7 +159,17 @@ public class NetworkPlayer : MonoBehaviour
//FindObjectsOfType<NetworkObject>(); //FindObjectsOfType<NetworkObject>();
} }
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) public void sendMessage(NetworkObject obj, string identifier, byte[] data)
{ {
if (obj == myObject) if (obj == myObject)

View File

@ -1,2 +1,2 @@
#!/usr/bin/env bash #!/usr/bin/env bash
./TestVelGameServer/Build/macbuild.app/Contents/MacOS/TestVelGameServer & ./TestVelGameServer/Build/velnetunityexample.app/Contents/MacOS/VelNetUnity &