Exemplo n.º 1
0
 public void Run()
 {
     lock (MessageQueue)
     {
         if (MessageQueue.Count > 0)
         {
             Receive.ReceiveMessage msg = MessageQueue.Dequeue();
             ProcessMessage(msg);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the message.
        /// Server to Client Message.
        /// 서버로부터 온 메세지를 큐에서 꺼내 읽고 해당 이벤트 발생.
        /// </summary>
        /// <param name="msg">Message.</param>
        protected void ProcessMessage(Receive.ReceiveMessage msg)
        {
            if (msg is Receive.BindSuccessMessage)
            {
                if (OnBindSuccess != null)
                {
                    OnBindSuccess();
                }
            }
            else if (msg is Receive.BindFailedMessage)
            {
                if (OnBindFailed != null)
                {
                    OnBindFailed(((Receive.BindFailedMessage)msg).Code);
                }
            }
            else if (msg is Receive.MoveAndRotateMessage)
            {
                Receive.MoveAndRotateMessage m = (Receive.MoveAndRotateMessage)msg;

                Vector2 move   = new Vector2(m.moveX, m.moveY);
                Vector2 rotate = new Vector2(m.rotateX, m.rotateY);

                if (OnControl != null)
                {
                    OnControl(move, rotate);
                }

                if (OnControlType != null)
                {
                    OnControlType(getMoveType(move), getRotateType(rotate));
                }
            }
            else if (msg is Receive.ShootMessage)
            {
                Receive.ShootMessage m = (Receive.ShootMessage)msg;
                Vector3 position       = new Vector3(m.positionX, m.positionY, m.positionZ);
                Vector3 velocity       = new Vector3(m.velocityX, m.velocityY, m.velocityZ);
                if (OnShoot != null)
                {
                    OnShoot(position, velocity);
                }
            }
            else if (msg is Receive.GameStartMessage)
            {
                if (OnGameStart != null)
                {
                    OnGameStart();
                }
            }
            else if (msg is Receive.GameCountMessage)
            {
                if (OnGameCount != null)
                {
                    OnGameCount(((Receive.GameCountMessage)msg).value);
                }
            }
            else if (msg is Receive.GameEndMessage)
            {
                if (OnGameEnd != null)
                {
                    OnGameEnd(((Receive.GameEndMessage)msg).value);
                }
            }
            else if (msg is Receive.AttackedMessage)
            {
                if (OnAttacked != null)
                {
                    OnAttacked();
                }
            }
            else if (msg is Receive.MapMessage)
            {
                if (OnMap != null)
                {
                    OnMap();
                }
            }
            else if (msg is Receive.DeathMessage)
            {
                if (OnDeath != null)
                {
                    OnDeath(((Receive.DeathMessage)msg).uid);
                }
            }
            else if (msg is Receive.SoldOutMessage)
            {
                if (OnSoldOut != null)
                {
                    OnSoldOut(((Receive.SoldOutMessage)msg).uid, ((Receive.SoldOutMessage)msg).unitnum);
                }
            }
            else if (msg is Receive.DeathStopMessage)
            {
                if (OnDeathStop != null)
                {
                    OnDeathStop(((Receive.DeathMessage)msg).uid);
                }
            }
            else if (msg is Receive.EmergencyStopMessage)
            {
                if (OnEmergencyStop != null)
                {
                    OnEmergencyStop(((Receive.DeathMessage)msg).uid);
                }
            }
        }