Example #1
0
    /// <summary>
    /// parameter를 base로 슬라이드 대상 타일들과 x, y coordinate 변화값 설정
    /// </summary>
    /// <param name="hitTile">마우스 Up 타일</param>
    /// <param name="state">슬라이드 방향</param>
    /// <returns></returns>
    public bool Slide(GameObject hitTile, Constants.SlideState state)
    {
        if (Main.blockGenerator.isGenerating)
        {
            return(true);
        }

        Block hitTemp = hitTile.GetComponent <Block>();
        List <Constants.BlockType> blockTypes = new List <Constants.BlockType>();
        int rX = 0, rY = 0;

        tileSliderParent.transform.position = new Vector2(0, 0);

        if (sliding)
        {
            return(true);
        }

        if (state == Constants.SlideState.Left || state == Constants.SlideState.Right)
        {
            for (int i = 0; i < Mathf.Pow(Constants.size, 2); i++)
            {
                Block temp = Main.blockList[i].GetComponent <Block>();

                if (temp.Coord.Y == hitTemp.Coord.Y)
                {
                    Main.blockList[i].transform.parent = tileSliderParent.GetComponent <Transform>();
                    silderList.Add(Main.blockList[i]);
                    blockTypes.Add(Main.blockList[i].GetComponent <Block>().Color);
                }
            }//for

            if (state == Constants.SlideState.Left)
            {
                rX = -1;
            }
            else
            {
                rX = 1;
            }
        }//if

        if (state == Constants.SlideState.Up || state == Constants.SlideState.Down)
        {
            for (int i = 0; i < Mathf.Pow(Constants.size, 2); i++)
            {
                Block temp = Main.blockList[i].GetComponent <Block>();

                if (temp.Coord.X == hitTemp.Coord.X)
                {
                    Main.blockList[i].transform.parent = tileSliderParent.GetComponent <Transform>();
                    silderList.Add(Main.blockList[i]);
                    blockTypes.Add(Main.blockList[i].GetComponent <Block>().Color);
                }
            }//for

            if (state == Constants.SlideState.Up)
            {
                rY = -1;
            }
            else
            {
                rY = 1;
            }
        }//if

        //장애물이 있는 경우


        if (blockTypes.Contains(Constants.BlockType.LOCK))
        {
            foreach (var item in tileSliderParent.transform.GetComponentsInChildren <Block>())
            {
                if (item.Color != Constants.BlockType.LOCK)
                {
                    item.Animator.SetTrigger("Locked");
                }
            }

            tileSliderParent.transform.DetachChildren();
            blockTypes.Clear();

            return(true);
        }

        UpdateSliderTiles(rX, rY);
        SoundManager.Instance.PlayEffect(SoundManager.Instance.effect_slide);

        return(true);
    }
Example #2
0
    public void GetTouch()
    {
        List <Touch> touches = InputHelper.GetTouches();

        if (touches.Count > 0)
        {
            Touch      t = touches[0];
            Ray        ray;
            RaycastHit hit;

            if (Main.resetCheck == false)
            {
                return;
            }

            if (Main.blockGenerator.isGenerating)
            {
                return;
            }

            switch (t.phase)
            {
            case TouchPhase.Began:
                //터치 시작
                touchIn = Camera.main.ScreenToWorldPoint(t.position);
                ray     = Camera.main.ScreenPointToRay(t.position);
                Physics.Raycast(ray, out hit);

                if (hit.collider)
                {
                    hitObject = hit.collider.gameObject;
                }
                break;

            case TouchPhase.Moved:
                //터치 이동
                if (hitObject)
                {
                    //Main.blockTarget.HintTarget(hitObject, true);
                }

                touchOut   = Camera.main.ScreenToWorldPoint(t.position);
                touchState = GetSlideState();

                break;

            case TouchPhase.Ended:
                //터치 종료

                //Main.blockTarget.HintTarget(hitObject, false);
                touchOut   = Camera.main.ScreenToWorldPoint(t.position);
                touchState = GetSlideState();
                ray        = Camera.main.ScreenPointToRay(t.position);
                Physics.Raycast(ray, out hit);

                if (hitObject)
                {
                    foreach (Animator item in Main.blockAnimatorList)
                    {
                        if (item.GetCurrentAnimatorStateInfo(0).IsName("Locked"))
                        {
                            return;
                        }
                        else
                        {
                            //item.SetTrigger("Reset");
                        }
                    }

                    if (touchState == Constants.SlideState.Click && hit.collider)
                    {
                        OnClick(hit.collider.gameObject.tag, hit, t.position);
                    }

                    else if (touchState != Constants.SlideState.NONE)    // moveState = Slide
                    {
                        OnSlide(hitObject.tag);
                    }
                }

                hitObject = null;
                break;
            } //switch
        }
    }