public static void Interpret(IPEndPoint source, Message message, NetworkMessage network)
    {
        NetworkCommon networkCommon = GameObject.FindObjectOfType <Network> ().NetworkCommon;

        switch (network.Message)
        {
        case NetworkMessage.MessageValue.CONNECT:
            if (networkCommon is NetworkServer && networkCommon.ID == message.DestID)
            {
                (networkCommon as NetworkServer).Send(source, MessageTranslator.ToByteArray(
                                                          createMessage(networkCommon.ID,
                                                                        message.SourceID,
                                                                        NetworkMessage.MessageValue.CONNECTED)));
                networkCommon.Connected = true;
                Application.LoadLevel(1);
            }
            break;

        case NetworkMessage.MessageValue.CONNECTED:
            if (networkCommon is NetworkClient && networkCommon.ID == message.DestID)
            {
                networkCommon.Connected = true;
                Application.LoadLevel(1);
            }
            break;
        }
    }
    public static void Send(GameplayMessage.MessageValue messageValue, int id, Vector2 delta, Vector3 originalPosition)
    {
        Network network = GameObject.FindObjectOfType <Network>();

        if (network == null)
        {
            return;
        }

        NetworkCommon networkCommon = network.NetworkCommon;

        if (networkCommon == null)
        {
            return;
        }

        Message m = createMessage(networkCommon.ID,
                                  1 - networkCommon.ID,
                                  messageValue,
                                  id,
                                  delta,
                                  originalPosition);

        if (networkCommon is NetworkClient)
        {
            (networkCommon as NetworkClient).Send(null, MessageTranslator.ToByteArray(m));
        }
        else
        {
            (networkCommon as NetworkServer).Broadcast(MessageTranslator.ToByteArray(m));
        }
    }
Exemple #3
0
    private void ClientConnection()
    {
        if (!NetworkCommon.Connected)
        {
            Invoke("ClientConnection", .1f);
        }

        NetworkCommon.Send(null, MessageTranslator.ToByteArray(
                               NetworkTranslator.createMessage(NetworkCommon.ID, 1 - NetworkCommon.ID, NetworkMessage.MessageValue.CONNECT)
                               ));
    }
 public static byte[] ToByteArray(NetworkMessage message)
 {
     return(MessageTranslator.ToByteArray <NetworkMessage>(message));
 }
 private static byte[] ToByteArray(GameplayMessage message)
 {
     return(MessageTranslator.ToByteArray <GameplayMessage>(message));
 }