Beispiel #1
0
    void DragUpdate()
    {
        //BuildingManager에서 가상으로 그려둔 타일맵기반으로 움직인다.
        lastPos = myTransform.localPosition;

        InputManager.FingerInput current_input = InputManager.Instance.GetCurrentInput();
        if (current_input.currentRayHitTransform != null)
        {
            if (current_input.currentRayHitTransform.gameObject.layer == LayerMask.NameToLayer("Grid"))
            {
                Vector2 currentHitTransformPosition = current_input.currentRayHitTransform.position;
                if (lastPos != currentHitTransformPosition)
                {
                    if (movePosList.Contains(currentHitTransformPosition) == false)
                    {
                        movePosList.Add(currentHitTransformPosition);
                    }
                }
            }
            else
            {
                //Debug.LogWarning(LayerMask.LayerToName(current_input.currentRayHitTransform.gameObject.layer));
            }
        }

        if (movePosList.Count > 0)
        {
            myTransform.localPosition = new Vector3(movePosList[0].x, movePosList[0].y, -1.0f);
            movePosList.RemoveAt(0);
        }
    }
    void DragUpdate()
    {
        lastPos = myTransform.localPosition;

        InputManager.FingerInput currentInput = InputManager.Instance.GetCurrentInput();
        if (currentInput.currentRayHitTransform != null)
        {
            if (currentInput.currentRayHitTransform.gameObject.layer == LayerMask.NameToLayer("Grid"))
            {
                Vector2 currentRayHitTransformPosition = currentInput.currentRayHitTransform.position;
                if (lastPos != currentRayHitTransformPosition)
                {
                    if (movePosList.Contains(currentRayHitTransformPosition) == false)
                    {
                        movePosList.Add(currentRayHitTransformPosition);
                    }
                }
            }
        }
        if (movePosList.Count > 0)
        {
            myTransform.localPosition = new Vector3(movePosList[0].x, movePosList[0].y, -1.0f);
            movePosList.RemoveAt(0);
        }
    }
Beispiel #3
0
    public void CameraUpdate()
    {
        if (this.isInit == false)
        {
            this.InitCamera();
        }

        InputManager.FingerInput currentInput = InputManager.Instance.GetCurrentInput();

        if (this.isEnableTween == true)
        {
        }
        else
        {
            if (this.isEnablePan == true)
            {
                Pan();
            }
            if (this.isEnableZoom == true)
            {
            }
        }
    }
Beispiel #4
0
    void Pan()
    {
        if (InputManager.fingerInputDic.Count == 1)
        {
            InputManager.FingerInput input = InputManager.Instance.GetCurrentInput();

            if (input.currentTouchPhase == TouchPhase.Began)
            {
                this.momentumVector       = Vector2.zero;
                this.springDampStrengthen = this.springDampStrengthenMax;
                this.dragStartPosition    = input.currentPoint;
                if (springPosition != null)
                {
                    springPosition.enabled = false;
                }
            }
            else if (input.currentTouchPhase == TouchPhase.Moved)
            {
                float x = (input.prevPoint.x - input.currentPoint.x);
                float y = (input.currentPoint.y - input.prevPoint.y);

                Vector2 deltaDrag = new Vector2(x, y);
                this.momentumVector = momentumVector + deltaDrag * ((0.02f / CameraManager.tk2DCamera.ZoomFactor) * momentumAmount);
                this.panAcumVector += this.momentumVector;
            }
            else if (input.currentTouchPhase == TouchPhase.Canceled || input.currentTouchPhase == TouchPhase.Ended)
            {
                Vector3       direction = (Vector3)input.currentPoint - this.dragStartPosition;
                Direction8Way way       = Helper.GetDirectionType(direction);
                float         panTH     = this.panThresHolds;
                if (way == Direction8Way.n || way == Direction8Way.s)
                {
                    panTH = panTH * (Screen.height / Screen.width);
                }


                float distance = Vector3.Distance(input.currentPoint, this.dragStartPosition);

                if (distance > panTH)
                {
                    this.springDampStrengthen = this.springDampStrengthenMin;
                }
                else
                {
                    this.springDampStrengthen = this.springDampStrengthenMax;
                }

                this.ContrainBounds(false);
            }
        }
        else
        {
            this.panAcumVector   = Vector2.zero;
            this.isCameraPanning = false;
        }

        float delTaTime = Time.deltaTime;

        if (momentumVector.magnitude > 0.01f)
        {
            Vector2 dampingVec = NGUIMath.SpringDampen(ref momentumVector, this.springDampStrengthen, delTaTime);
            if (float.IsNaN(dampingVec.x) == false && float.IsNaN(dampingVec.y) == false)
            {
                this.isCameraPanning = true;
                CameraManager.tk2DCamera.transform.Translate(dampingVec, Space.Self);
            }
            if (!ContrainBounds(false))
            {
                springPosition.enabled = false;
            }
        }
    }