Пример #1
0
    // ========================================================================== //

    /* public - [Do] Function
     * 외부 객체가 호출(For External class call)*/

    /* public - [Event] Function
     * 프랜드 객체가 호출(For Friend class call)*/

    #endregion Public

    // ========================================================================== //

    #region Protected

    /* protected - [abstract & virtual]         */

    /* protected - [Event] Function
     * 자식 객체가 호출(For Child class call)		*/

    /* protected - Override & Unity API         */

    public override void OnUpdate(ref bool bCheckUpdateCount)
    {
        base.OnUpdate(ref bCheckUpdateCount);
        bCheckUpdateCount = true;

        int iTouchCount = 0;

#if (UNITY_EDITOR || UNITY_STANDALONE)
        iTouchCount = Input.GetMouseButton(0) ? 1 : 0;

        _fPinchDistance     = Mathf.Clamp(_fPinchDistance + Input.GetAxis(const_strMouseScrollWheel) / 2f, 0.1f, 100f);
        _fLerpPinchDistance = Mathf.Lerp(_fLerpPinchDistance, _fPinchDistance, Time.deltaTime * 20f);

        if (Mathf.Approximately(_fPinchDistance, _fLerpPinchDistance) == false)
        {
            iTouchCount = 2;
        }
#elif (UNITY_ANDROID || UNITY_IOS)
        iTouchCount = Input.touchCount;
#endif

        if (iTouchCount == 1)
        {
            Vector3 v3CurrentTouchOnePos = Vector3.zero;

#if (UNITY_EDITOR || UNITY_STANDALONE)
            v3CurrentTouchOnePos = Input.mousePosition;
#elif (UNITY_ANDROID || UNITY_IOS)
            Touch pTouch = Input.touches[0];
            v3CurrentTouchOnePos = pTouch.position;
#endif
            if (_eStateTouch != EStateTouch.Dragging)
            {
                float fDistByResolution = PrimitiveHelper.GetDistanceByResolution(v3CurrentTouchOnePos, _v3DragStartPos);
                if (fDistByResolution > p_fDragStartDistanceThreshold)
                {
                    _eStateTouch    = EStateTouch.Dragging;
                    _v3DragStartPos = v3CurrentTouchOnePos;

                    ProcOnStartDrag();
                }
            }
            else
            {
                ProcOnUpdateDrag(v3CurrentTouchOnePos);
                _v3LastTouchOnePos = v3CurrentTouchOnePos;
            }
        }
        else if (iTouchCount == 2)
        {
            float fPinchDistance = 0f;

#if (UNITY_EDITOR || UNITY_STANDALONE)
            fPinchDistance = _fLerpPinchDistance;
#elif (UNITY_ANDROID || UNITY_IOS)
            Touch pTouchOne = Input.touches[0];
            Touch pTouchTwo = Input.touches[1];

            Vector3 v3TouchPosOne = pTouchOne.position;
            Vector3 v3TouchPosTwo = pTouchTwo.position;
            //Vector3 v3CenterPos = PrimitiveHelper.GetCenterPos(v3TouchPosOne, v3TouchPosTwo);

            fPinchDistance = PrimitiveHelper.GetDistanceByResolutionSqrt(v3TouchPosOne, v3TouchPosTwo);
#endif

            if (_eStateTouch != EStateTouch.Pinching)
            {
                ProcOnStartPinch(fPinchDistance);
                _eStateTouch = EStateTouch.Pinching;
            }

            ProcOnUpdatePinch(fPinchDistance);
        }
        else
        {
            if (_eStateTouch == EStateTouch.Dragging)
            {
                ProcOnFinishDrag();
            }
            else if (_eStateTouch == EStateTouch.Pinching)
            {
                ProcOnFinishPinch();
            }

            if (_eStateTouch != EStateTouch.None)
            {
                _eStateTouch = EStateTouch.None;
            }
        }
    }