Exemplo n.º 1
0
    public void ChangeState(eTouchState state)
    {
        switch (state)
        {
        case eTouchState.PRESS:
        {
            Press();
        }
        break;

        case eTouchState.PRESS_NOTHING:
        {
            PressNothing();
        }
        break;

        case eTouchState.DRAG:
        {
            Drag();
        }
        break;

        case eTouchState.RELEASE:
        {
            Release();
        }
        break;

        default:
        {
            Debug.Log($"UI_UserInteraction.ChangeState: default");
        }
        break;
        }
    }
Exemplo n.º 2
0
    public void CurBlockCheckMovementBegin()
    {
        bool beginMovement = false;

        // we're done raising but since we want to ignore input while it's raising make sure we're still selecting the block
        if (Input.GetMouseButtonDown(0) || Input.GetMouseButton(0))
        {
            LayerMask  mask = LayerMask.GetMask("Block");
            Ray        ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask))
            {
                Block newBlock = hit.collider.gameObject.GetComponent <Block>();
                if (newBlock == CurBlock)
                {
                    beginMovement = true;
                }
            }
        }
        if (beginMovement == true)
        {
            //Debug.Log("going to begin movement, TouchState: " + TouchState.ToString());
            SetIgnoreBlockInput(false);
            StartTouchPos = Input.mousePosition;
            CurTouchPos   = StartTouchPos;
            LastTouchPos  = StartTouchPos;
        }
        else
        {
            // Debug.Log("don't begin movment, move down");
            TouchState = eTouchState.NONE;
            CurBlock.StopMoving(SnapSpeed);
        }
    }
Exemplo n.º 3
0
    IEnumerator DragImpl()
    {
        currentState = eTouchState.DRAG;
        while (true) //화면을 누르고있는상태
        {
            yield return(null);

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);//Plane에 쏘는레이
            RaycastHit hit;
            var        layerMask2 = 1 << LayerMask.NameToLayer("Plane");
            Debug.DrawRay(ray.origin, ray.direction * 1000, Color.cyan, 1f);
            if (Physics.Raycast(ray, out hit, 100, layerMask2))//Plane과 충돌 확인
            {
                if (SelectedHero != null)
                {
                    var point = hit.point;
                    point.y += 1.5f;
                    SelectedHero.transform.position = point; //내 멤버변수의 히어로의 위치를 터치가 바닥과 닿은곳에서 y는 1.5만큼 떨어진 곳으로 이동한다.
                }
            }
            else
            {
                //Plane과 터치하지 않았으므로 되돌아간다
                SelectedHero.transform.position = SelectedHero.defaultPos;
                SelectedHero = null;
                break;
            }
        }
    }
Exemplo n.º 4
0
    IEnumerator PressImpl()
    {
        currentState = eTouchState.PRESS;
        while (true)
        {
            yield return(null);

            //터치하면 레이를 쏜다
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Debug.DrawRay(ray.origin, ray.direction * 1000, Color.green, 1f);
            var layerMask = 1 << LayerMask.NameToLayer("Hero");
            if (Physics.Raycast(ray, out hit, 100, layerMask))  //영웅 레이어에 쐈을때 감지되는가?
            {
                Debug.Log($"PressImpl: Hit:{hit.transform.gameObject.GetComponent<TestHero>()}");
                SelectedHero = hit.transform.gameObject.GetComponent <TestHero>();
                OnDragHero();
                break;
            }
            else
            {
                OnPressNothing();
            }
        }
    }
Exemplo n.º 5
0
 private void Release()
 {
     this.currentState = eTouchState.RELEASE;
     DisplayState();
     if (coBehavior != null)
     {
         StopCoroutine(coBehavior);
     }
     coBehavior = StartCoroutine(ReleaseImpl());
 }
Exemplo n.º 6
0
 private void Drag()
 {
     this.currentState = eTouchState.DRAG;
     DisplayState();
     if (coBehavior != null)
     {
         StopCoroutine(coBehavior);
     }
     coBehavior = StartCoroutine(DragImpl());
 }
Exemplo n.º 7
0
 private void PressNothing()
 {
     this.currentState = eTouchState.PRESS_NOTHING;
     DisplayState();
     if (coBehavior != null)
     {
         StopCoroutine(coBehavior);
     }
     coBehavior = StartCoroutine(PressNothingImpl());
 }
Exemplo n.º 8
0
        public void Update(float rawX, float rawY)
        {
            RawX = rawX;
            RawY = rawY;
#if UNITY_SWITCH && !UNITY_EDITOR
            x = RawX / GameDefine.SWITCH_MOBILE_SIZE_X * GameDefine.CANVAS_BASE_SIZE_X;
            y = RawY / GameDefine.SWITCH_MOBILE_SIZE_Y * GameDefine.CANVAS_BASE_SIZE_Y;
#else
            x = RawX / (float)(Screen.width) * GameDefine.CANVAS_BASE_SIZE_X;
            y = RawY / (float)(Screen.height) * GameDefine.CANVAS_BASE_SIZE_Y;

            //x = GameDefine.CANVAS_BASE_SIZE_X - x;
            y = GameDefine.CANVAS_BASE_SIZE_Y - y;
#endif
            State = eTouchState.Press;
        }
Exemplo n.º 9
0
    IEnumerator PressNothingImpl()
    {
        currentState = eTouchState.PRESS_NOTHING;
        while (true)
        {
            //선택된 히어로가 있으면 돌아간다
            if (SelectedHero != null)
            {
                SelectedHero.transform.position = SelectedHero.defaultPos;
                this.SelectedHero = null;
            }
            yield return(null);

            break;
        }
    }
Exemplo n.º 10
0
    IEnumerator ReleaseImpl()
    {
        currentState = eTouchState.RELEASE;
        var layerMask = 1 << LayerMask.NameToLayer("Hero");

        if (SelectedHero != null)
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray.origin, ray.direction, out hit, 100, layerMask))//마우스포지션에서 레이를 쏜다.
            {
                var otherHero = hit.transform.gameObject.GetComponent <TestHero>();

                if (otherHero == SelectedHero)
                {
                    SelectedHero.transform.position = SelectedHero.defaultPos;
                    DisPlayHeroRandButton();
                }
                //두개의 타입을 체크한다
                else
                {
                    if (SelectedHero.data.type == otherHero.data.type && SelectedHero.data.type < 11)
                    {
                        //같은 타입이므로 합칠 수 있다
                        OnMergeHeroWithGameObject(SelectedHero, otherHero);
                        HideHeroRandButton();
                    }
                }
            }
            else
            {
                SelectedHero.transform.position = SelectedHero.defaultPos;
                DisPlayHeroRandButton();
            }
        }
        yield return(null);

        OnPressNothing();
    }
Exemplo n.º 11
0
 /// <summary>
 /// Helper function to set/reset all of the current input state values
 /// </summary>
 void SetInputState(eTouchState state, float timer, int taps)
 {
     TouchState = state;
     InputTimer = timer;
     TapCount   = taps;
 }
Exemplo n.º 12
0
 public void BeginUpdate()
 {
     State = eTouchState.Up;
 }
Exemplo n.º 13
0
 public TouchData(int iD, float rawX, float rawY)
 {
     ID = iD;
     Update(rawX, rawY);
     State = eTouchState.Down;
 }