enable_collider() public method

public enable_collider ( bool flag ) : void
flag bool
return void
    /// <summary>
    /// 패킷을 순차적으로 처리하기 위한 루프.
    /// 카드 움직이는 연출 장면을 순서대로 처리하기 위해 구현한 매소드 이다.
    /// 코루틴에 의한 카드 이동 연출이 진행중일때도 서버로부터의 패킷은 수신될 수 있으므로
    /// 연출 도중에 다른 연출이 수행되는 경우가 생겨 버린다.
    /// 이런 경우를 방지하려면 두가지 방법이 있다.
    /// 첫번째. 각 연출 단계마다 다른 클라이언트들과 동기화를 수행한다.
    /// 두번째. 들어오는 패킷을 큐잉처리 하여 하나의 연출 장면이 끝난 뒤에 다음 패킷을 꺼내어 처리한다.
    /// 여기서는 두번째 방법으로 구현하였다.
    /// 첫번째 방법의 경우 동기화 패킷을 수시로 교환해야 하기 때문에 구현하기가 번거롭고
    /// 상대방의 네트워크 상태가 좋지 않을 경우 게임 진행이 매끄럽지 못하게 된다.
    /// </summary>
    /// <returns></returns>
    IEnumerator sequential_packet_handler()
    {
        while (true)
        {
            if (this.waiting_packets.Count <= 0)
            {
                yield return(0);

                continue;
            }

            CPacket  msg      = this.waiting_packets.Dequeue();
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol)
            {
            case PROTOCOL.LOCAL_SERVER_STARTED:
            {
                CPacket send = CPacket.create((short)PROTOCOL.READY_TO_START);
                CNetworkManager.Instance.send(send);
            }
            break;

            case PROTOCOL.BEGIN_CARD_INFO:
            {
                reset();

                // if (is_test_mode)
                // {
                //  this.test_auto_slot_index = 0;
                // }

                Queue <CCard> floor_cards = new Queue <CCard>();
                // floor cards.
                this.player_me_index = msg.pop_byte();
                byte floor_count = msg.pop_byte();
                for (byte i = 0; i < floor_count; ++i)
                {
                    byte     number   = msg.pop_byte();
                    PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                    byte     position = msg.pop_byte();

                    CCard card = this.card_manager.find_card(number, pae_type, position);
                    if (card == null)
                    {
                        Debug.LogError(string.Format("Cannot find the card. {0}, {1}, {2}",
                                                     number, pae_type, position));
                    }
                    floor_cards.Enqueue(card);
                }


                Dictionary <byte, Queue <CCard> > player_cards = new Dictionary <byte, Queue <CCard> >();
                byte player_count = msg.pop_byte();
                for (byte player = 0; player < player_count; ++player)
                {
                    Queue <CCard> cards        = new Queue <CCard>();
                    byte          player_index = msg.pop_byte();
                    byte          card_count   = msg.pop_byte();
                    for (byte i = 0; i < card_count; ++i)
                    {
                        byte number = msg.pop_byte();
                        if (number != byte.MaxValue)
                        {
                            PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                            byte     position = msg.pop_byte();
                            CCard    card     = this.card_manager.find_card(number, pae_type, position);
                            cards.Enqueue(card);
                        }
                    }

                    player_cards.Add(player_index, cards);
                }


                yield return(StartCoroutine(distribute_cards(floor_cards, player_cards)));
            }
            break;

            case PROTOCOL.START_TURN:
            {
                byte remain_bomb_card_count = msg.pop_byte();


                // if (this.is_test_mode)
                // {
                //  if (this.player_hand_card_manager[0].get_card_count() <= 0)
                //  {
                //      break;
                //  }
                //
                //  CPacket card_msg = CPacket.create((short)PROTOCOL.SELECT_CARD_REQ);
                //  CCardPicture card_pic = this.player_hand_card_manager[0].get_card(0);
                //
                //  card_msg.push(card_pic.card.number);
                //  card_msg.push((byte)card_pic.card.pae_type);
                //  card_msg.push(card_pic.card.position);
                //  // card_msg.push(this.test_auto_slot_index);
                //      // ++this.test_auto_slot_index;
                //
                //  CNetworkManager.Instance.send(card_msg);
                // }

                // 내 차례가 되었을 때 카드 선택 기능을 활성화 시켜준다.
                this.card_collision_manager.enabled = true;
                this.player_hand_card_manager[0].enable_all_colliders(true);

                // 이전에 폭탄낸게 남아있다면 가운데 카드를 뒤집을 수 있도록 충돌박스를 켜준다.
                if (remain_bomb_card_count > 0)
                {
                    CCardPicture top_card = deck_cards.Peek();
                    top_card.enable_collider(true);
                }
            }
            break;

            case PROTOCOL.SELECT_CARD_ACK:
                yield return(StartCoroutine(on_select_card_ack(msg)));

                break;

            case PROTOCOL.FLIP_DECK_CARD_ACK:
                yield return(StartCoroutine(on_flip_deck_card_ack(msg)));

                break;

            case PROTOCOL.CHOICE_ONE_CARD:
            {
                List <Sprite>             target_cards = new List <Sprite>();
                PLAYER_SELECT_CARD_RESULT result       = (PLAYER_SELECT_CARD_RESULT)msg.pop_byte();
                CCardPicture deck_card = null;
                if (result == PLAYER_SELECT_CARD_RESULT.CHOICE_ONE_CARD_FROM_DECK)
                {
                    deck_card = this.deck_cards.Pop();
                    byte     number   = msg.pop_byte();
                    PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                    byte     position = msg.pop_byte();
                    CCard    card     = this.card_manager.find_card(number, pae_type, position);
                    deck_card.update_card(card, get_hwatoo_sprite(card));
                }
                byte count = msg.pop_byte();
                for (byte i = 0; i < count; ++i)
                {
                    byte     number   = msg.pop_byte();
                    PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                    byte     position = msg.pop_byte();

                    CCard card = this.card_manager.find_card(number, pae_type, position);
                    target_cards.Add(get_hwatoo_sprite(card));
                    //Debug.Log(string.Format("choice one card. {0}, {1}, {2}", number, pae_type, position));
                }

                CUIManager.Instance.show(UI_PAGE.POPUP_CHOICE_CARD);
                CPopupChoiceCard popup =
                    CUIManager.Instance.get_uipage(UI_PAGE.POPUP_CHOICE_CARD).GetComponent <CPopupChoiceCard>();
                popup.refresh(result, target_cards[0], target_cards[1]);

                yield return(StartCoroutine(show_choice_card_popup(deck_card)));
            }
            break;

            case PROTOCOL.TURN_RESULT:
            {
                // 데이터 파싱 시작 ----------------------------------------
                byte player_index = msg.pop_byte();
                yield return(StartCoroutine(on_turn_result(player_index, msg)));
            }
            break;

            case PROTOCOL.ASK_GO_OR_STOP:
                CUIManager.Instance.show(UI_PAGE.POPUP_GO_STOP);
                break;

            case PROTOCOL.UPDATE_PLAYER_STATISTICS:
                update_player_statistics(msg);
                break;

            case PROTOCOL.ASK_KOOKJIN_TO_PEE:
                CUIManager.Instance.show(UI_PAGE.POPUP_ASK_KOOKJIN);
                break;

            case PROTOCOL.MOVE_KOOKJIN_TO_PEE:
            {
                byte player_index = msg.pop_byte();
                yield return(StartCoroutine(move_kookjin_to_pee(player_index)));
            }
            break;

            case PROTOCOL.GAME_RESULT:
                on_game_result(msg);
                break;
            }

            yield return(0);
        }
    }
Esempio n. 2
0
    /// <summary>
    /// 패킷을 순차적으로 처리하기 위한 루프.
    /// 카드 움직이는 연출 장면을 순서대로 처리하기 위해 구현한 매소드 이다.
    /// 코루틴에 의한 카드 이동 연출이 진행중일때도 서버로부터의 패킷은 수신될 수 있으므로
    /// 연출 도중에 다른 연출이 수행되는 경우가 생겨 버린다.
    /// 이런 경우를 방지하려면 두가지 방법이 있다.
    /// 첫번째. 각 연출 단계마다 다른 클라이언트들과 동기화를 수행한다.
    /// 두번째. 들어오는 패킷을 큐잉처리 하여 하나의 연출 장면이 끝난 뒤에 다음 패킷을 꺼내어 처리한다.
    /// 여기서는 두번째 방법으로 구현하였다.
    /// 첫번째 방법의 경우 동기화 패킷을 수시로 교환해야 하기 때문에 구현하기가 번거롭고
    /// 상대방의 네트워크 상태가 좋지 않을 경우 게임 진행이 매끄럽지 못하게 된다.
    /// </summary>
    /// <returns></returns>
    IEnumerator sequential_packet_handler()
    {
        while (true)
        {
            if (this.waiting_packets.Count <= 0)
            {
                yield return(0);

                continue;
            }

            CPacket  msg      = this.waiting_packets.Dequeue();
            PROTOCOL protocol = (PROTOCOL)msg.pop_protocol_id();

            switch (protocol)
            {
            case PROTOCOL.LOCAL_SERVER_STARTED:
            {
                CPacket send = CPacket.create((short)PROTOCOL.READY_TO_START);
                CNetworkManager.Instance.send(send);
            }
            break;

            case PROTOCOL.PLAYER_ORDER_RESULT:
            {
                reset();

                CUIManager.Instance.show(UI_PAGE.POPUP_PLAYER_ORDER);
                CPopupPlayerOrder popup =
                    CUIManager.Instance.get_uipage(UI_PAGE.POPUP_PLAYER_ORDER).GetComponent <CPopupPlayerOrder>();
                popup.reset(this.back_image);
                popup.play();

                yield return(new WaitForSeconds(2.6f));

                byte slot_count  = msg.pop_byte();
                byte best_number = 0;
                byte head        = 0;
                for (byte i = 0; i < slot_count; ++i)
                {
                    byte     slot_index = msg.pop_byte();
                    byte     number     = msg.pop_byte();
                    PAE_TYPE pae_type   = (PAE_TYPE)msg.pop_byte();
                    byte     position   = msg.pop_byte();

                    CCard card = this.card_manager.find_card(number, pae_type, position);
                    Debug.Log(string.Format("{0}, {1}, {2}", number, pae_type, position));
                    popup.update_slot_info(slot_index, get_hwatoo_sprite(card));

                    if (best_number < number)
                    {
                        head        = slot_index;
                        best_number = number;
                    }

                    yield return(new WaitForSeconds(0.7f));
                }

                yield return(new WaitForSeconds(0.5f));

                GameObject ef = CUIManager.Instance.get_uipage(UI_PAGE.POPUP_FIRST_PLAYER);
                if (head == 0)
                {
                    ef.transform.localPosition = new Vector3(100, 100, 0);
                }
                else
                {
                    ef.transform.localPosition = new Vector3(100, -100, 0);
                }
                CUIManager.Instance.show(UI_PAGE.POPUP_FIRST_PLAYER);

                yield return(new WaitForSeconds(1.5f));

                CUIManager.Instance.hide(UI_PAGE.POPUP_PLAYER_ORDER);
                CUIManager.Instance.hide(UI_PAGE.POPUP_FIRST_PLAYER);
            }
            break;

            case PROTOCOL.BEGIN_CARD_INFO:
            {
                if (is_test_mode)
                {
                    this.test_auto_slot_index = 0;
                }

                Queue <CCard> floor_cards = new Queue <CCard>();
                // floor cards.
                this.player_me_index = msg.pop_byte();
                byte floor_count = msg.pop_byte();
                for (byte i = 0; i < floor_count; ++i)
                {
                    byte     number   = msg.pop_byte();
                    PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                    byte     position = msg.pop_byte();

                    CCard card = this.card_manager.find_card(number, pae_type, position);
                    if (card == null)
                    {
                        Debug.LogError(string.Format("Cannot find the card. {0}, {1}, {2}",
                                                     number, pae_type, position));
                    }
                    floor_cards.Enqueue(card);
                }


                Dictionary <byte, Queue <CCard> > player_cards = new Dictionary <byte, Queue <CCard> >();
                byte player_count = msg.pop_byte();
                for (byte player = 0; player < player_count; ++player)
                {
                    Queue <CCard> cards        = new Queue <CCard>();
                    byte          player_index = msg.pop_byte();
                    byte          card_count   = msg.pop_byte();
                    for (byte i = 0; i < card_count; ++i)
                    {
                        byte number = msg.pop_byte();
                        if (number != byte.MaxValue)
                        {
                            PAE_TYPE pae_type = (PAE_TYPE)msg.pop_byte();
                            byte     position = msg.pop_byte();
                            CCard    card     = this.card_manager.find_card(number, pae_type, position);
                            cards.Enqueue(card);
                        }
                    }

                    player_cards.Add(player_index, cards);
                }


                yield return(StartCoroutine(distribute_cards(floor_cards, player_cards)));
            }
            break;

            case PROTOCOL.START_TURN:
            {
                byte remain_bomb_card_count = msg.pop_byte();
                refresh_hint_mark();

                if (this.is_test_mode)
                {
                    if (this.player_hand_card_manager[0].get_card_count() <= 0)
                    {
                        break;
                    }

                    CPacket      card_msg = CPacket.create((short)PROTOCOL.SELECT_CARD_REQ);
                    CCardPicture card_pic = this.player_hand_card_manager[0].get_card(0);

                    card_msg.push(card_pic.card.number);
                    card_msg.push((byte)card_pic.card.pae_type);
                    card_msg.push(card_pic.card.position);
                    card_msg.push(this.test_auto_slot_index);
                    ++this.test_auto_slot_index;

                    CNetworkManager.Instance.send(card_msg);
                }
                else
                {
                    // 내 차례가 되었을 때 카드 선택 기능을 활성화 시켜준다.
                    this.ef_focus.SetActive(true);
                    this.card_collision_manager.enabled = true;
                    this.player_hand_card_manager[0].enable_all_colliders(true);

                    // 이전에 폭탄낸게 남아있다면 가운데 카드를 뒤집을 수 있도록 충돌박스를 켜준다.
                    if (remain_bomb_card_count > 0)
                    {
                        CCardPicture top_card = deck_cards.Peek();
                        top_card.enable_collider(true);

                        show_hint_mark(top_card.transform.position);
                    }
                }
            }
            break;

            case PROTOCOL.SELECT_CARD_ACK:
                yield return(StartCoroutine(on_select_card_ack(msg)));

                break;

            case PROTOCOL.FLIP_DECK_CARD_ACK:
                yield return(StartCoroutine(on_flip_deck_card_ack(msg)));

                break;

            case PROTOCOL.TURN_RESULT:
            {
                // 데이터 파싱 시작 ----------------------------------------
                byte player_index = msg.pop_byte();
                yield return(StartCoroutine(on_turn_result(player_index, msg)));
            }
            break;

            case PROTOCOL.ASK_GO_OR_STOP:
                CUIManager.Instance.show(UI_PAGE.POPUP_GO_STOP);
                break;

            case PROTOCOL.UPDATE_PLAYER_STATISTICS:
                update_player_statistics(msg);
                break;

            case PROTOCOL.ASK_KOOKJIN_TO_PEE:
                CUIManager.Instance.show(UI_PAGE.POPUP_ASK_KOOKJIN);
                break;

            case PROTOCOL.MOVE_KOOKJIN_TO_PEE:
            {
                byte player_index = msg.pop_byte();
                yield return(StartCoroutine(move_kookjin_to_pee(player_index)));
            }
            break;

            case PROTOCOL.NOTIFY_GO_COUNT:
            {
                byte delay    = msg.pop_byte();
                byte go_count = msg.pop_byte();

                yield return(StartCoroutine(delay_if_exist(delay)));

                yield return(StartCoroutine(show_go_count(go_count)));
            }
            break;

            case PROTOCOL.GAME_RESULT:
                yield return(StartCoroutine(on_game_result(msg)));

                break;
            }

            yield return(0);
        }
    }