made sending messages lower level
parent
34732b43f6
commit
001e89509f
|
|
@ -1819,7 +1819,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 03a4d4e1a7fd74c7ab2eccca4ce168db, type: 3}
|
m_Script: {fileID: 11500000, guid: 03a4d4e1a7fd74c7ab2eccca4ce168db, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
host: localhost
|
host: neko.ugavel.com
|
||||||
port: 3290
|
port: 3290
|
||||||
userid: -1
|
userid: -1
|
||||||
room:
|
room:
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,7 @@ public class NetworkManager : MonoBehaviour
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socketConnection = new TcpClient(host, port);
|
socketConnection = new TcpClient(host, port);
|
||||||
|
socketConnection.NoDelay = true;
|
||||||
Byte[] bytes = new Byte[1024];
|
Byte[] bytes = new Byte[1024];
|
||||||
string partialMessage = "";
|
string partialMessage = "";
|
||||||
while (true)
|
while (true)
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ using UnityEngine;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a base class for all objects that a player can instantiated/owned
|
/// This is a base class for all objects that a player can instantiated/owned
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class NetworkObject: MonoBehaviour, NetworkSyncable
|
public abstract class NetworkObject: MonoBehaviour
|
||||||
{
|
{
|
||||||
public NetworkPlayer owner;
|
public NetworkPlayer owner;
|
||||||
public string networkId; //this is forged from the combination of the creator's id (-1 in the case of a scene object) and an object id, so it's always unique for a room
|
public string networkId; //this is forged from the combination of the creator's id (-1 in the case of a scene object) and an object id, so it's always unique for a room
|
||||||
public string prefabName; //this may be empty if it's not a prefab (scene object)
|
public string prefabName; //this may be empty if it's not a prefab (scene object)
|
||||||
public abstract byte[] getSyncMessage();
|
public abstract void handleMessage(string identifier, byte[] message);
|
||||||
public abstract void handleSyncMessage(byte[] message);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,9 @@ public class NetworkPlayer : MonoBehaviour, Dissonance.IDissonancePlayer
|
||||||
{
|
{
|
||||||
case "1": //update my object's data
|
case "1": //update my object's data
|
||||||
{
|
{
|
||||||
byte[] message = Convert.FromBase64String(sections[1]);
|
string identifier = sections[1];
|
||||||
myObject.handleSyncMessage(message);
|
byte[] message = Convert.FromBase64String(sections[2]);
|
||||||
|
myObject.handleMessage(identifier, message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "2": //audio data
|
case "2": //audio data
|
||||||
|
|
@ -144,13 +145,14 @@ public class NetworkPlayer : MonoBehaviour, Dissonance.IDissonancePlayer
|
||||||
{
|
{
|
||||||
|
|
||||||
string objectKey = sections[1];
|
string objectKey = sections[1];
|
||||||
string syncMessage = sections[2];
|
string identifier = sections[2];
|
||||||
|
string syncMessage = sections[3];
|
||||||
byte[] messageBytes = Convert.FromBase64String(syncMessage);
|
byte[] messageBytes = Convert.FromBase64String(syncMessage);
|
||||||
if (manager.objects.ContainsKey(objectKey))
|
if (manager.objects.ContainsKey(objectKey))
|
||||||
{
|
{
|
||||||
if(manager.objects[objectKey].owner == this)
|
if(manager.objects[objectKey].owner == this)
|
||||||
{
|
{
|
||||||
manager.objects[objectKey].handleSyncMessage(messageBytes);
|
manager.objects[objectKey].handleMessage(identifier, messageBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,7 +225,6 @@ public class NetworkPlayer : MonoBehaviour, Dissonance.IDissonancePlayer
|
||||||
public void setDissonanceID(string id) //this sort of all initializes dissonance
|
public void setDissonanceID(string id) //this sort of all initializes dissonance
|
||||||
{
|
{
|
||||||
dissonanceID = id;
|
dissonanceID = id;
|
||||||
Debug.Log("here");
|
|
||||||
manager.sendTo(NetworkManager.MessageType.OTHERS, "3," + id+";");
|
manager.sendTo(NetworkManager.MessageType.OTHERS, "3," + id+";");
|
||||||
commsNetwork.comms.TrackPlayerPosition(this);
|
commsNetwork.comms.TrackPlayerPosition(this);
|
||||||
}
|
}
|
||||||
|
|
@ -234,17 +235,18 @@ public class NetworkPlayer : MonoBehaviour, Dissonance.IDissonancePlayer
|
||||||
//if I'm master, I'm now responsible for updating all scene objects
|
//if I'm master, I'm now responsible for updating all scene objects
|
||||||
//FindObjectsOfType<NetworkObject>();
|
//FindObjectsOfType<NetworkObject>();
|
||||||
}
|
}
|
||||||
public void syncObject(NetworkObject obj)
|
|
||||||
|
|
||||||
|
public void sendMessage(NetworkObject obj, string identifier, byte[] data)
|
||||||
{
|
{
|
||||||
byte[] data = obj.getSyncMessage();
|
|
||||||
if (obj == myObject)
|
if (obj == myObject)
|
||||||
{
|
{
|
||||||
manager.sendTo(NetworkManager.MessageType.OTHERS, "1," + Convert.ToBase64String(data));
|
manager.sendTo(NetworkManager.MessageType.OTHERS, "1," + identifier +"," + Convert.ToBase64String(data));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
manager.sendTo(NetworkManager.MessageType.OTHERS, "5," + obj.networkId + "," + Convert.ToBase64String(data));
|
manager.sendTo(NetworkManager.MessageType.OTHERS, "5," + obj.networkId + "," + identifier + "," + Convert.ToBase64String(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This makes serialization somewhat uniform
|
|
||||||
/// </summary>
|
|
||||||
public interface NetworkSyncable
|
|
||||||
{
|
|
||||||
public byte[] getSyncMessage(); //local owner asks for this and sends it periodically
|
|
||||||
public void handleSyncMessage(byte[] message); //remote owner will call this
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 8e4266960bfa444998dda57f911448f0
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class PlayerController : NetworkObject
|
||||||
public Quaternion targetRotation;
|
public Quaternion targetRotation;
|
||||||
|
|
||||||
|
|
||||||
public override byte[] getSyncMessage()
|
public byte[] getSyncMessage()
|
||||||
{
|
{
|
||||||
float[] data = new float[7];
|
float[] data = new float[7];
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
|
|
@ -25,16 +25,21 @@ public class PlayerController : NetworkObject
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void handleSyncMessage(byte[] message)
|
public override void handleMessage(string identifier, byte[] message)
|
||||||
{
|
{
|
||||||
float[] data = new float[7];
|
switch (identifier)
|
||||||
Buffer.BlockCopy(message, 0, data, 0, message.Length);
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
{
|
{
|
||||||
targetPosition[i] = data[i];
|
case "s":
|
||||||
targetRotation[i] = data[i + 3];
|
float[] data = new float[7];
|
||||||
|
Buffer.BlockCopy(message, 0, data, 0, message.Length);
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
targetPosition[i] = data[i];
|
||||||
|
targetRotation[i] = data[i + 3];
|
||||||
|
}
|
||||||
|
targetRotation[3] = data[6];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
targetRotation[3] = data[6];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
|
|
@ -50,7 +55,7 @@ public class PlayerController : NetworkObject
|
||||||
if (owner != null && owner.isLocal)
|
if (owner != null && owner.isLocal)
|
||||||
{
|
{
|
||||||
|
|
||||||
owner.syncObject(this);
|
owner.sendMessage(this, "s", getSyncMessage());
|
||||||
}
|
}
|
||||||
yield return new WaitForSeconds(.1f);
|
yield return new WaitForSeconds(.1f);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ public class SyncTransform : NetworkObject
|
||||||
public Quaternion targetRotation;
|
public Quaternion targetRotation;
|
||||||
|
|
||||||
|
|
||||||
public override byte[] getSyncMessage()
|
public byte[] getSyncMessage()
|
||||||
{
|
{
|
||||||
float[] data = new float[7];
|
float[] data = new float[7];
|
||||||
for(int i = 0; i < 3; i++)
|
for(int i = 0; i < 3; i++)
|
||||||
|
|
@ -31,16 +31,22 @@ public class SyncTransform : NetworkObject
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void handleSyncMessage(byte[] message)
|
public override void handleMessage(string identifier, byte[] message)
|
||||||
{
|
{
|
||||||
float[] data = new float[7];
|
switch (identifier)
|
||||||
Buffer.BlockCopy(message, 0, data, 0, message.Length);
|
|
||||||
for(int i = 0; i < 3; i++)
|
|
||||||
{
|
{
|
||||||
targetPosition[i] = data[i];
|
case "s":
|
||||||
targetRotation[i] = data[i + 3];
|
float[] data = new float[7];
|
||||||
|
Buffer.BlockCopy(message, 0, data, 0, message.Length);
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
targetPosition[i] = data[i];
|
||||||
|
targetRotation[i] = data[i + 3];
|
||||||
|
}
|
||||||
|
targetRotation[3] = data[6];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
targetRotation[3] = data[6];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
|
|
@ -56,7 +62,7 @@ public class SyncTransform : NetworkObject
|
||||||
if (owner != null && owner.isLocal)
|
if (owner != null && owner.isLocal)
|
||||||
{
|
{
|
||||||
|
|
||||||
owner.syncObject(this);
|
owner.sendMessage(this, "s", getSyncMessage());
|
||||||
}
|
}
|
||||||
yield return new WaitForSeconds(.1f);
|
yield return new WaitForSeconds(.1f);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue