Пример #1
0
    void onTouchDown()
    {
        isItemHasSel = false;
        Vector2 pos = Common.GetInputPosition();

        ptDownScreen = pos;
        isError      = false;
        Vector3 posword = mainCam.ScreenToWorldPoint(pos);

        Debug.Log("onTouchDown: " + posword);
        foreach (ShapeColorItemInfo info in listItem)
        {
            bool isLock = IsItemLock(info);
            if (isLock)
            {
                continue;
            }

            if (iDelegateShapeColor != null)
            {
                iDelegateShapeColor.OnGameShapeColorDidError(this, UIGameShapeColor.ERROR_STATUS_HIDE, null);
            }

            Bounds bd = info.obj.GetComponent <SpriteRenderer>().bounds;

            posword.z = bd.center.z;
            Rect rc = new Rect(info.obj.transform.position.x - bd.size.x / 2, info.obj.transform.position.y - bd.size.y / 2, bd.size.x, bd.size.y);
            //Debug.Log("left:"+bd+"rc="+rc);
            if (rc.Contains(posword))
            {
                posItemWorld = info.obj.transform.position;
                itemInfoSel  = info;
                isItemHasSel = true;

                // ShapeHighlighterController hlc = AddHighLight(info.obj);
                //   hlc.UpdateColor(color);

                if (info.objTrail != null)
                {
                    ShapeTrail trail = info.objTrail.GetComponent <ShapeTrail>();
                    if (trail != null)
                    {
                        trail.setColor(Color.red);
                        trail.ClearDraw();
                    }
                }

                Debug.Log("itemInfoSel:id:" + itemInfoSel.id + " color:" + itemInfoSel.color);
                break;
            }
        }
    }
Пример #2
0
    void onTouchMove()
    {
        if (!isItemHasSel)
        {
            Debug.Log("onTouchMove ng 1");
            return;
        }
        bool isLock = IsItemLock(itemInfoSel);

        if (isLock)
        {
            Debug.Log("onTouchMove ng 2");
            return;
        }
        float   x, y, w, h;
        Vector2 pos = Common.GetInputPosition();

        Vector2 ptStep       = pos - ptDownScreen;
        Vector2 ptStepWorld  = Common.ScreenToWorldSize(mainCam, ptStep);
        Vector3 posStepWorld = new Vector3(ptStepWorld.x, ptStepWorld.y, 0);
        Vector3 posword      = posItemWorld + posStepWorld;

        //将选中item暂时置顶
        posword.z = itemPosZ - 2;
        //itemInfoSel.obj.transform.position = posword;
        Rigidbody2D body = itemInfoSel.obj.GetComponent <Rigidbody2D>();

        if (body != null)
        {
            body.MovePosition(posword);
        }

        //尾巴添加节点
        if (itemInfoSel.objTrail != null)
        {
            Debug.Log("itemInfoSel.objTrail");
            ShapeTrail trail = itemInfoSel.objTrail.GetComponent <ShapeTrail>();
            if (trail != null)
            {
                // trail.AddPoint(posword);
                trail.OnDraw();
            }
        }


        foreach (ShapeColorItemInfo info in listItem)
        {
            isLock = IsItemLock(info);
            if (isLock)
            {
                //  Debug.Log("onTouchMove ng 3");
                // continue;
            }
            Bounds bd = info.obj.GetComponent <SpriteRenderer>().bounds;

            posword.z = bd.center.z;
            w         = bd.size.x / 4;
            h         = bd.size.y / 4;
            Rect rc = new Rect(info.obj.transform.position.x - w / 2, info.obj.transform.position.y - h / 2, w, h);
            if (info == itemInfoSel)
            {
                continue;
            }

            //  Debug.Log("onTouchMove:posword=" + posword + "rc=" + rc);


            if (rc.Contains(posword))
            {
                if (!isTheSamePairItems(this.itemInfoSel, info))
                {
                    if ((iDelegateShapeColor != null) && (!isError))
                    {
                        isError = true;
                        int error = 0;
                        if ((itemInfoSel.id != info.id) && (itemInfoSel.color != info.color))
                        {
                            error = UIGameShapeColor.ERROR_STATUS_SHAPE_COLOR;
                        }
                        else
                        {
                            if (itemInfoSel.id != info.id)
                            {
                                error = UIGameShapeColor.ERROR_STATUS_SHAPE;
                            }
                            if (itemInfoSel.color != info.color)
                            {
                                error = UIGameShapeColor.ERROR_STATUS_COLOR;
                            }
                        }

                        iDelegateShapeColor.OnGameShapeColorDidError(this, error, null);
                        Invoke("OnGameFail", 0.5f);
                    }
                    continue;
                }
                isSelectTheBomb = false;
                if (itemInfoSel.id == ID_BOMB)
                {
                    isSelectTheBomb = true;
                }
                Debug.Log("合并正确 isSelectTheBomb=" + isSelectTheBomb);

                //合并正确
                SetItemLock(info, true);
                SetItemLock(itemInfoSel, true);

                itemInfoSel.obj.transform.position = info.obj.transform.position;
                RunDisapperAnimation(itemInfoSel);
                PlayAudioItemFinish(itemInfoSel);


                //记录游戏开始进行中
                int level   = LevelManager.main.gameLevel;
                int idx     = level / GUANKA_NUM_PER_ITEM;
                int idx_sub = level % GUANKA_NUM_PER_ITEM;
                if (idx_sub == 0)
                {
                    ShapeColorItemInfo infoitem;
                    string             key;
                    if (gameMode == GAME_MODE_SHAPE)
                    {
                        infoitem = GetItemInfoShapeColor(idx, listShape);
                        key      = STR_KEY_GAME_STATUS_SHAPE + infoitem.id;
                        PlayerPrefs.SetInt(key, GAME_STATUS_PLAY);
                    }
                    if (gameMode == GAME_MODE_COLOR)
                    {
                        infoitem = GetItemInfoShapeColor(idx, listColor);
                        key      = STR_KEY_GAME_STATUS_COLOR + infoitem.id;
                        PlayerPrefs.SetInt(key, GAME_STATUS_PLAY);
                    }
                }



                break;
            }
        }
    }