예제 #1
0
        void Update()
        {
            LogMessage msg;

            while (LogQueue.GetNext(out msg))
            {
                switch (msg.Type)
                {
                case ELogType.Info:
                    Debug.Log(msg.Message);
                    break;

                case ELogType.Warning:
                    Debug.LogWarning(msg.Message);
                    break;

                case ELogType.Error:
                    Debug.LogError(msg.Message);
                    break;
                }
            }

            while (Net.GetNextEvent(out ConnectionEvent e))
            {
                switch (e.EventType)
                {
                case ConnectionEvent.EType.Connected:
                    OnClientConnected?.Invoke(this, new ConnectionEventArgs(e.Connection));
                    break;

                case ConnectionEvent.EType.Disconnected:
                    OnClientDisconnected?.Invoke(this, new ConnectionEventArgs(e.Connection));
                    break;
                }
            }

            if (Net.GetState() == ENetworkState.Running)
            {
                while (Net.GetNextMessage(out byte[] message, out ConnectionHandle connection, out ENetChannel channel))
                {
                    byte type = message[0];
                    if (NetworkDataTypes[type] != null)
                    {
                        NetworkData networkData = (NetworkData)Activator.CreateInstance(NetworkDataTypes[type]);
                        networkData.Deserialize(message);
                        ReceivedNetworkDataEventArgs args = new ReceivedNetworkDataEventArgs(connection, networkData, message[0]);
                        OnNetworkDataReceived?.Invoke(this, args);

                        //Debug.LogFormat("Received Network data of type '{0}'", type.ToString(), networkData);
                    }
                    else
                    {
                        Debug.LogWarningFormat("A received package of type '{0}' got not de-serialized! Did you forget to register a appropriate NetworkData class?", type.ToString());
                    }
                }
            }
        }
 public bool Enqueue(TKey key, TValue value)
 {
     lock (Lock)
     {
         try
         {
             List.Add(key, value);
             return(true);
         }
         catch (ArgumentException)
         {
             LogQueue.LogError("Cannot add element ({}, {}) to list, key already exists!", new object[] { key, value });
             return(false);
         }
     }
 }