示例#1
0
        private void PlayNext(int pre_exit_)
        {
            if (0 == pre_exit_)
            {
                this.GameFinished(false);
                return;
            }
            else if (9 == pre_exit_)
            {
                this.GameFinished(true);
                return;
            }


            while (this.m_cur_index_playing < this.m_anchor_positions.Count)
            {
                AnchorPos ap = this.m_anchor_positions[this.m_cur_index_playing];

                int cartoon_id = ap.cur_ocuppied_cartoon_item_id;

                if (m_played_views.Contains(cartoon_id))
                {
                    ++this.m_cur_index_playing;
                    continue;
                }

                this.PlayVideo(pre_exit_);

                break;
            }
        }
示例#2
0
    private void Dragging(CartoonLongRotateView view_, CartoonRotate model_)
    {
        int exchanged_index = -1;

        switch (view_.m_dir)
        {
        case ENUM_ITEM_DIRECTION.E_LEFT:
            exchanged_index = CartoonUtil.GetLeftIndex(view_.Item_index, model_.m_width_unit, this.anchor_w_size, this.anchor_h_size);
            break;

        case ENUM_ITEM_DIRECTION.E_UP:
            exchanged_index = CartoonUtil.GetUpIndex(view_.Item_index, model_.m_width_unit, this.anchor_w_size, this.anchor_h_size);
            break;

        case ENUM_ITEM_DIRECTION.E_RIGHT:
            exchanged_index = CartoonUtil.GetRightIndex(view_.Item_index, model_.m_width_unit, this.anchor_w_size, this.anchor_h_size);
            break;

        case ENUM_ITEM_DIRECTION.E_DOWN:
            exchanged_index = CartoonUtil.GetDownIndex(view_.Item_index, model_.m_width_unit, this.anchor_w_size, this.anchor_h_size);
            break;
        }

        if (-1 == exchanged_index)
        {
            return;
        }

        if (false == this.CanBeExchanged(exchanged_index))
        {
            return;
        }

        AnchorPos exchanged    = this.m_anchor_positions[exchanged_index];
        int       exchanged_id = exchanged.cur_ocuppied_cartoon_item_id;

        CartoonFixedView exchange_view = m_cartoon_views[exchanged_id];
        CartoonFixed     exchange_item = m_cartoon.m_cartoon_items[exchanged_id];

        //我的钉子点不动,尾巴被替换
        int my_tail_index = view_.Tail_index;
        int my_id         = model_.m_item_id;

        //来我的位置
        this.ChangeAnchorPos(exchange_view, exchange_item, my_tail_index, m_anchor_positions[my_tail_index].m_pos);

        //目的地记录换成我
        m_anchor_positions[exchanged_index].cur_ocuppied_cartoon_item_id = my_id;
        //我的anchor记录换成目的地的
        view_.Tail_index = exchanged_index;
    }
示例#3
0
        private void PlayVideo(int pre_exit_, bool is_first = false)
        {
            AnchorPos ap = this.m_anchor_positions[this.m_cur_index_playing];

            int cartoon_id = ap.cur_ocuppied_cartoon_item_id;

            CartoonFixedView cartoon_view = this.m_cartoon_views[cartoon_id];

            cartoon_view.Play(pre_exit_, is_first);

            m_played_views.Add(cartoon_id);

            ++this.m_cur_index_playing;
        }
示例#4
0
        private AnchorPos GetNearestNeighbour(int my_id_, int my_index_, Vector2 anchor_pos_)
        {
            Vector2 my_ori_anchor_pos = m_anchor_positions[my_index_].m_pos;

            if (Mathf.Abs(anchor_pos_.x - my_ori_anchor_pos.x) > m_min_cartoon_width_half ||
                Mathf.Abs(anchor_pos_.y - my_ori_anchor_pos.y) > m_min_cartoon_height_half)
            {
                //出轨

                for (int i = 0; i < m_anchor_positions.Count; ++i)
                {
                    if (i == my_index_)
                    {
                        continue;
                    }

                    AnchorPos neighbour = m_anchor_positions[i];
                    if (neighbour.cur_ocuppied_cartoon_item_id == my_id_)
                    {
                        Debug.LogError(string.Format("index {0},id {1}", my_index_, my_id_));
                        continue;
                    }

                    Vector2 neighbour_pos = neighbour.m_pos;

                    if (Mathf.Abs(anchor_pos_.x - neighbour_pos.x) < m_min_cartoon_width_half &&
                        Mathf.Abs(anchor_pos_.y - neighbour_pos.y) < m_min_cartoon_height_half)
                    {
                        ENUM_CARTOON_ITEM_TYPE c_type = m_cartoon.m_cartoon_items[neighbour.cur_ocuppied_cartoon_item_id].m_item_type;

                        if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_DRAG != c_type)
                        {
                            continue;
                        }


                        return(neighbour);
                    }
                }

                return(null);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        void UpdateAnchor(AnchorPos anchorPos)
        {
            RectTransform trans = GetComponent <RectTransform> ();

            if (trans == null)
            {
                return;
            }

            Vector2 pos = new Vector2(0.5f, 0.5f);

            switch (anchorPos)
            {
            case AnchorPos.TopLeft:
            case AnchorPos.MiddleLeft:
            case AnchorPos.BottomLeft:
                pos.x = 0f;
                break;

            case AnchorPos.TopRight:
            case AnchorPos.MiddleRight:
            case AnchorPos.BottomRight:
                pos.x = 1f;
                break;
            }
            switch (anchorPos)
            {
            case AnchorPos.TopLeft:
            case AnchorPos.Top:
            case AnchorPos.TopRight:
                pos.y = 1f;
                break;

            case AnchorPos.BottomLeft:
            case AnchorPos.Bottom:
            case AnchorPos.BottomRight:
                pos.y = 0f;
                break;
            }

            trans.anchorMin = pos;
            trans.anchorMax = pos;
            trans.sizeDelta = Vector2.zero;
            trans.name      = "Anchor_" + anchorPos;
        }
示例#6
0
        private void InitCartoonItemAnchorPosition()
        {
            float panel_width  = m_cartoon.m_play_rect.sizeDelta.x;
            float panel_height = m_cartoon.m_play_rect.sizeDelta.y;

            if ((0 != ((int)panel_width) % ((int)(m_cartoon.m_min_width))) || (0 != ((int)panel_height) % ((int)(m_cartoon.m_min_height))))
            {
                Debug.LogError("可操作区域,不是最小卡通图尺寸的整数倍");
                return;
            }

            anchor_w_size = (int)(panel_width / m_cartoon.m_min_width);
            anchor_h_size = (int)(panel_height / m_cartoon.m_min_height);

            float half_w = panel_width * 0.5f;
            float half_h = panel_height * 0.5f;

            m_min_cartoon_width_half  = m_cartoon.m_min_width * 0.5f;
            m_min_cartoon_height_half = m_cartoon.m_min_height * 0.5f;

            m_anchor_positions = new List <AnchorPos>();

            int index = 0;

            for (int j = anchor_h_size - 1; j >= 0; --j)
            {
                for (int i = 0; i < anchor_w_size; ++i)
                {
                    float     pos_x  = m_cartoon.m_min_width * i + m_cartoon.m_min_width * 0.5f - half_w;
                    float     pos_y  = m_cartoon.m_min_height * j + m_cartoon.m_min_height * 0.5f - half_h;
                    AnchorPos anchor = new AnchorPos();
                    anchor.m_pos                        = new Vector2(pos_x, pos_y);
                    anchor.m_index_on_panel             = index;
                    anchor.cur_ocuppied_cartoon_item_id = -1;
                    m_anchor_positions.Add(anchor);
                    ++index;
                }
            }
        }
示例#7
0
        public void Moving(CartoonDragView view_, CartoonFixed model_)
        {
            int       my_index  = view_.Item_index;
            int       my_id     = model_.m_item_id;
            AnchorPos exchanged = GetNearestNeighbour(my_id, my_index, view_.m_rect.anchoredPosition);

            if (null != exchanged)
            {
                int exchanged_id    = exchanged.cur_ocuppied_cartoon_item_id;
                int exchanged_index = exchanged.m_index_on_panel;

                CartoonFixedView exchange_view = m_cartoon_views[exchanged_id];
                CartoonFixed     exchange_item = m_cartoon.m_cartoon_items[exchanged_id];

                //来我的位置
                this.ChangeAnchorPos(exchange_view, exchange_item, my_index, m_anchor_positions[my_index].m_pos);

                //他的anchor记录换成我
                m_anchor_positions[exchanged_index].cur_ocuppied_cartoon_item_id = my_id;
                //我的anchor记录换成他
                view_.Item_index = exchanged_index;
            }
        }
示例#8
0
        public static MinMaxRect CalcOffsets(AnchorPos anchorPos, float2 posOnParent, float parentHeight, float parentWidth, float2 guiElementDim)
        {
            switch (anchorPos)
            {
            default:
            case AnchorPos.MIDDLE:
                var middle = new float2(parentWidth / 2f, parentHeight / 2f);
                return(new MinMaxRect
                {
                    Min = posOnParent - middle,
                    Max = posOnParent - middle + guiElementDim
                });

            case AnchorPos.STRETCH_ALL:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(-(parentWidth - posOnParent.x - guiElementDim.x), -(parentHeight - posOnParent.y - guiElementDim.y))
                });

            case AnchorPos.STRETCH_HORIZONTAL:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(-(parentWidth - (posOnParent.x + guiElementDim.x)), posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.STRETCH_VERTICAL:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(posOnParent.x + guiElementDim.x, -(parentHeight - (posOnParent.y + guiElementDim.y)))
                });

            case AnchorPos.DOWN_DOWN_LEFT:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(posOnParent.x + guiElementDim.x, posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.DOWN_DOWN_RIGHT:
                return(new MinMaxRect
                {
                    Min = new float2(-(parentWidth - posOnParent.x), posOnParent.y),
                    Max = new float2(-(parentWidth - posOnParent.x - guiElementDim.x), posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.TOP_TOP_LEFT:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, -(parentHeight - posOnParent.y)),
                    Max = new float2(posOnParent.x + guiElementDim.x, -(parentHeight - guiElementDim.y - posOnParent.y))
                });

            case AnchorPos.TOP_TOP_RIGHT:
                return(new MinMaxRect
                {
                    Min = new float2(-(parentWidth - posOnParent.x), -(parentHeight - posOnParent.y)),
                    Max = new float2(-(parentWidth - guiElementDim.x - posOnParent.x), -(parentHeight - guiElementDim.y - posOnParent.y))
                });
            }
        }
示例#9
0
        public static MinMaxRect GetAnchors(AnchorPos anchorPos)
        {
            switch (anchorPos)
            {
            case AnchorPos.DOWN_DOWN_LEFT:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(0, 0)
                });

            case AnchorPos.DOWN_DOWN_RIGHT:
                return(new MinMaxRect()
                {
                    Min = new float2(1, 0),
                    Max = new float2(1, 0)
                });

            case AnchorPos.TOP_TOP_LEFT:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 1),
                    Max = new float2(0, 1)
                });

            case AnchorPos.TOP_TOP_RIGHT:
                return(new MinMaxRect()
                {
                    Min = new float2(1, 1),
                    Max = new float2(1, 1)
                });

            case AnchorPos.STRETCH_ALL:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(1, 1)
                });

            case AnchorPos.STRETCH_HORIZONTAL:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(1, 0)
                });

            case AnchorPos.STRETCH_VERTICAL:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(0, 1)
                });

            default:
            case AnchorPos.MIDDLE:
                return(new MinMaxRect()
                {
                    Min = new float2(0.5f, 0.5f),
                    Max = new float2(0.5f, 0.5f)
                });
            }
        }
示例#10
0
        private void ResetCartoonItemPosition()
        {
            m_cartoon_views     = new Dictionary <int, CartoonFixedView>();
            m_played_views      = new List <int>();
            m_cur_index_playing = 0;

            int index = 0;

            for (int i = 0; i < m_cartoon.m_cartoon_items.Count; ++i)
            {
                CartoonFixed item = m_cartoon.m_cartoon_items[i];
                item.Init();
                item.m_item_id = i;

                CartoonFixedView item_view = null;

                if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_FIXED == item.m_item_type)
                {
                    item_view = item.gameObject.GetComponent <CartoonFixedView>();
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_DRAG == item.m_item_type)
                {
                    item_view = item.gameObject.GetComponent <CartoonDragView>();
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_ROTATE == item.m_item_type)
                {
                    item_view = item.gameObject.GetComponent <CartoonSquareRotateView>();
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_LONGRECT_ROTATE == item.m_item_type)
                {
                    item_view = item.gameObject.GetComponent <CartoonLongRotateView>();
                }


                if (null == item_view)
                {
                    Debug.LogError("找不到漫画的view" + item.name);
                    return;
                }

                m_cartoon_views[item.m_item_id] = item_view;

                AnchorPos pos_on_panel = m_anchor_positions[index];

                while (-1 != pos_on_panel.cur_ocuppied_cartoon_item_id)
                {
                    ++index;
                    pos_on_panel = m_anchor_positions[index];
                }

                if (!this.ChangeAnchorPos(item_view, item, index, pos_on_panel.m_pos))
                {
                    return;
                }
            }

            for (int i = 0; i < m_anchor_positions.Count; ++i)
            {
                Debug.Log(string.Format("序列{0},cartoon id {1}", i, m_anchor_positions[i].cur_ocuppied_cartoon_item_id));
            }
        }
示例#11
0
        private void InitCartoonItemPosition()
        {
            m_cartoon_views     = new Dictionary <int, CartoonFixedView>();
            m_played_views      = new List <int>();
            m_cur_index_playing = 0;

            int index = 0;

            for (int i = 0; i < m_cartoon.m_cartoon_items.Count; ++i)
            {
                CartoonFixed item = m_cartoon.m_cartoon_items[i];
                item.Init();
                item.m_item_id = i;

                CartoonFixedView item_view = null;

                if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_FIXED == item.m_item_type)
                {
                    item_view = item.gameObject.AddComponent <CartoonFixedView>();
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_DRAG == item.m_item_type)
                {
                    item_view = item.gameObject.AddComponent <CartoonDragView>();
                    ((CartoonDragView)item_view).ReisterMoving(Moving);
                    ((CartoonDragView)item_view).ReisterMoveEnd(MoveEnd);
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_SQUARE_ROTATE == item.m_item_type)
                {
                    item_view = item.gameObject.AddComponent <CartoonSquareRotateView>();
                    ((CartoonSquareRotateView)item_view).RegisterCanTurn(CanTurnAround);
                }
                else if (ENUM_CARTOON_ITEM_TYPE.E_LONGRECT_ROTATE == item.m_item_type)
                {
                    item_view = item.gameObject.AddComponent <CartoonLongRotateView>();
                    ((CartoonLongRotateView)item_view).RegisterCanDrag(CanDrag);
                    ((CartoonLongRotateView)item_view).RegisterDragging(Dragging);
                }


                if (null == item_view)
                {
                    Debug.LogError("找不到漫画种类" + item.name);
                    return;
                }

                item_view.SetModel(item);

                m_cartoon_views[item.m_item_id] = item_view;

                item_view.OnVideoFinished = PlayNext;

                AnchorPos pos_on_panel = m_anchor_positions[index];

                while (-1 != pos_on_panel.cur_ocuppied_cartoon_item_id)
                {
                    ++index;
                    pos_on_panel = m_anchor_positions[index];
                }

                if (!this.ChangeAnchorPos(item_view, item, index, pos_on_panel.m_pos))
                {
                    return;
                }
            }

            for (int i = 0; i < m_anchor_positions.Count; ++i)
            {
                Debug.Log(string.Format("序列{0},cartoon id {1}", i, m_anchor_positions[i].cur_ocuppied_cartoon_item_id));
            }
        }
示例#12
0
        /// <summary>
        /// Sets the anchor position in percent as a <see cref="MinMaxRect"/> depending on its <see cref="AnchorPos"/>
        /// </summary>
        /// <param name="anchorPos">The anchor point of the UI element.</param>
        /// <returns>The <see cref="MinMaxRect"/> containing the anchor position in percent.</returns>
        public static MinMaxRect GetAnchors(AnchorPos anchorPos)
        {
            switch (anchorPos)
            {
            case AnchorPos.DownDownLeft:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(0, 0)
                });

            case AnchorPos.DownDownRight:
                return(new MinMaxRect()
                {
                    Min = new float2(1, 0),
                    Max = new float2(1, 0)
                });

            case AnchorPos.TopTopLeft:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 1),
                    Max = new float2(0, 1)
                });

            case AnchorPos.TopTopRight:
                return(new MinMaxRect()
                {
                    Min = new float2(1, 1),
                    Max = new float2(1, 1)
                });

            case AnchorPos.StretchAll:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(1, 1)
                });

            case AnchorPos.StretchHorizontal:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(1, 0)
                });

            case AnchorPos.StretchVertical:
                return(new MinMaxRect()
                {
                    Min = new float2(0, 0),
                    Max = new float2(0, 1)
                });

            default:
            case AnchorPos.Middle:
                return(new MinMaxRect()
                {
                    Min = new float2(0.5f, 0.5f),
                    Max = new float2(0.5f, 0.5f)
                });
            }
        }
示例#13
0
        /// <summary>
        /// Calculates the offset between an element and their parent element and therefore its size.
        /// </summary>
        /// <param name="anchorPos">The anchor point of the element.</param>
        /// <param name="posOnParent">The position on the parent element.</param>
        /// <param name="parentHeight">The height of the parent element.</param>
        /// <param name="parentWidth">The width of the parent element.</param>
        /// <param name="guiElementDim">The dimensions of the element along the x and y axis.</param>
        /// <returns></returns>
        public static MinMaxRect CalcOffsets(AnchorPos anchorPos, float2 posOnParent, float parentHeight, float parentWidth, float2 guiElementDim)
        {
            switch (anchorPos)
            {
            default:
            case AnchorPos.Middle:
                var middle = new float2(parentWidth / 2f, parentHeight / 2f);
                return(new MinMaxRect
                {
                    Min = posOnParent - middle,
                    Max = posOnParent - middle + guiElementDim
                });

            case AnchorPos.StretchAll:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(-(parentWidth - posOnParent.x - guiElementDim.x), -(parentHeight - posOnParent.y - guiElementDim.y))
                });

            case AnchorPos.StretchHorizontal:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(-(parentWidth - (posOnParent.x + guiElementDim.x)), posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.StretchVertical:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(posOnParent.x + guiElementDim.x, -(parentHeight - (posOnParent.y + guiElementDim.y)))
                });

            case AnchorPos.DownDownLeft:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, posOnParent.y),
                    Max = new float2(posOnParent.x + guiElementDim.x, posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.DownDownRight:
                return(new MinMaxRect
                {
                    Min = new float2(-(parentWidth - posOnParent.x), posOnParent.y),
                    Max = new float2(-(parentWidth - posOnParent.x - guiElementDim.x), posOnParent.y + guiElementDim.y)
                });

            case AnchorPos.TopTopLeft:
                return(new MinMaxRect
                {
                    Min = new float2(posOnParent.x, -(parentHeight - posOnParent.y)),
                    Max = new float2(posOnParent.x + guiElementDim.x, -(parentHeight - guiElementDim.y - posOnParent.y))
                });

            case AnchorPos.TopTopRight:
                return(new MinMaxRect
                {
                    Min = new float2(-(parentWidth - posOnParent.x), -(parentHeight - posOnParent.y)),
                    Max = new float2(-(parentWidth - guiElementDim.x - posOnParent.x), -(parentHeight - guiElementDim.y - posOnParent.y))
                });
            }
        }