Added a NetworkStart method to all NetworkedBehaviours which is invoked when handlers are ready to be added
This commit is contained in:
parent
0d099c83b2
commit
1f14ded9cf
@ -7,7 +7,7 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
public abstract class NetworkedBehaviour : MonoBehaviour
|
public abstract class NetworkedBehaviour : MonoBehaviour
|
||||||
{
|
{
|
||||||
protected bool isLocalPlayer
|
public bool isLocalPlayer
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace MLAPI
|
|||||||
return NetworkingManager.singleton.isHost;
|
return NetworkingManager.singleton.isHost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected NetworkedObject networkedObject
|
public NetworkedObject networkedObject
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@ -66,6 +66,20 @@ namespace MLAPI
|
|||||||
//Change data type
|
//Change data type
|
||||||
private Dictionary<string, int> registeredMessageHandlers = new Dictionary<string, int>();
|
private Dictionary<string, int> registeredMessageHandlers = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
if (_networkedObject == null)
|
||||||
|
{
|
||||||
|
_networkedObject = GetComponentInParent<NetworkedObject>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal bool networkedStartInvoked = false;
|
||||||
|
public virtual void NetworkStart()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected int RegisterMessageHandler(string name, Action<int, byte[]> action)
|
protected int RegisterMessageHandler(string name, Action<int, byte[]> action)
|
||||||
{
|
{
|
||||||
int counter = MessageManager.AddIncomingMessageHandler(name, action, networkId);
|
int counter = MessageManager.AddIncomingMessageHandler(name, action, networkId);
|
||||||
|
@ -46,5 +46,18 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
SpawnManager.OnSpawnObject(this, clientId);
|
SpawnManager.OnSpawnObject(this, clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void InvokeBehaviourNetworkSpawn()
|
||||||
|
{
|
||||||
|
NetworkedBehaviour[] netBehaviours = GetComponentsInChildren<NetworkedBehaviour>();
|
||||||
|
for (int i = 0; i < netBehaviours.Length; i++)
|
||||||
|
{
|
||||||
|
//We check if we are it's networkedObject owner incase a networkedObject exists as a child of our networkedObject.
|
||||||
|
if(netBehaviours[i].networkedObject == this && !netBehaviours[i].networkedStartInvoked)
|
||||||
|
{
|
||||||
|
netBehaviours[i].NetworkStart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ namespace MLAPI
|
|||||||
ConnectionConfig cConfig = new ConnectionConfig();
|
ConnectionConfig cConfig = new ConnectionConfig();
|
||||||
|
|
||||||
//MLAPI channels and messageTypes
|
//MLAPI channels and messageTypes
|
||||||
NetworkConfig.Channels.Add("MLAPI_RELIABLE_FRAGMENTED", QosType.ReliableFragmented);
|
NetworkConfig.Channels.Add("MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", QosType.ReliableFragmentedSequenced);
|
||||||
NetworkConfig.Channels.Add("MLAPI_POSITION_UPDATE", QosType.StateUpdate);
|
NetworkConfig.Channels.Add("MLAPI_POSITION_UPDATE", QosType.StateUpdate);
|
||||||
MessageManager.messageTypes.Add("MLAPI_CONNECTION_REQUEST", 0);
|
MessageManager.messageTypes.Add("MLAPI_CONNECTION_REQUEST", 0);
|
||||||
MessageManager.messageTypes.Add("MLAPI_CONNECTION_APPROVED", 1);
|
MessageManager.messageTypes.Add("MLAPI_CONNECTION_APPROVED", 1);
|
||||||
@ -284,7 +284,7 @@ namespace MLAPI
|
|||||||
writer.Write(NetworkConfig.ConnectionData);
|
writer.Write(NetworkConfig.ConnectionData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Send(clientId, "MLAPI_CONNECTION_REQUEST", "MLAPI_RELIABLE_FRAGMENTED", writeStream.GetBuffer());
|
Send(clientId, "MLAPI_CONNECTION_REQUEST", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", writeStream.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -742,7 +742,7 @@ namespace MLAPI
|
|||||||
{
|
{
|
||||||
writer.Write(clientId);
|
writer.Write(clientId);
|
||||||
}
|
}
|
||||||
Send("MLAPI_CLIENT_DISCONNECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer(), clientId);
|
Send("MLAPI_CLIENT_DISCONNECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -811,7 +811,7 @@ namespace MLAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Send(clientId, "MLAPI_CONNECTION_APPROVED", "MLAPI_RELIABLE_FRAGMENTED", writeStream.GetBuffer());
|
Send(clientId, "MLAPI_CONNECTION_APPROVED", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", writeStream.GetBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Inform old clients of the new player
|
//Inform old clients of the new player
|
||||||
@ -837,7 +837,7 @@ namespace MLAPI
|
|||||||
writer.Write(clientId);
|
writer.Write(clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer(), clientId);
|
Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -52,6 +52,7 @@ namespace MLAPI.NetworkingManagerComponents
|
|||||||
netObject.OwnerClientId = ownerId;
|
netObject.OwnerClientId = ownerId;
|
||||||
|
|
||||||
spawnedObjects.Add(netObject.NetworkId, netObject);
|
spawnedObjects.Add(netObject.NetworkId, netObject);
|
||||||
|
netObject.InvokeBehaviourNetworkSpawn();
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ namespace MLAPI.NetworkingManagerComponents
|
|||||||
netObject.isPlayerObject = true;
|
netObject.isPlayerObject = true;
|
||||||
netManager.connectedClients[clientId].PlayerObject = go;
|
netManager.connectedClients[clientId].PlayerObject = go;
|
||||||
spawnedObjects.Add(netObject.NetworkId, netObject);
|
spawnedObjects.Add(netObject.NetworkId, netObject);
|
||||||
|
netObject.InvokeBehaviourNetworkSpawn();
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,9 +99,9 @@ namespace MLAPI.NetworkingManagerComponents
|
|||||||
}
|
}
|
||||||
//If we are host, send to everyone except ourselves. Otherwise, send to all
|
//If we are host, send to everyone except ourselves. Otherwise, send to all
|
||||||
if (netManager.isHost)
|
if (netManager.isHost)
|
||||||
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer(), -1);
|
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), -1);
|
||||||
else
|
else
|
||||||
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer());
|
netManager.Send("MLAPI_DESTROY_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,9 +153,9 @@ namespace MLAPI.NetworkingManagerComponents
|
|||||||
}
|
}
|
||||||
//If we are host, send to everyone except ourselves. Otherwise, send to all
|
//If we are host, send to everyone except ourselves. Otherwise, send to all
|
||||||
if (netManager.isHost)
|
if (netManager.isHost)
|
||||||
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer(), -1);
|
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer(), -1);
|
||||||
else
|
else
|
||||||
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED", stream.GetBuffer());
|
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_RELIABLE_FRAGMENTED_SEQUENCED", stream.GetBuffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user