Пример #1
0
        // Token: 0x0600042F RID: 1071 RVA: 0x00013614 File Offset: 0x00011A14
        public Finger GetMouseTouch(int fingerIndex, Finger myFinger)
        {
            Finger finger;

            if (myFinger != null)
            {
                finger = myFinger;
            }
            else
            {
                finger         = new Finger();
                finger.gesture = EasyTouch.GestureType.None;
            }
            if (fingerIndex == 1 && (Input.GetKeyUp(KeyCode.LeftAlt) || Input.GetKeyUp(EasyTouch.instance.twistKey) || Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(EasyTouch.instance.swipeKey)))
            {
                finger.fingerIndex   = fingerIndex;
                finger.position      = this.oldFinger2Position;
                finger.deltaPosition = finger.position - this.oldFinger2Position;
                finger.tapCount      = this.tapCount[fingerIndex];
                finger.deltaTime     = Time.realtimeSinceStartup - this.deltaTime[fingerIndex];
                finger.phase         = TouchPhase.Ended;
                return(finger);
            }
            if (Input.GetMouseButton(0))
            {
                finger.fingerIndex = fingerIndex;
                finger.position    = this.GetPointerPosition(fingerIndex);
                if ((double)(Time.realtimeSinceStartup - this.tapeTime[fingerIndex]) > 0.5)
                {
                    this.tapCount[fingerIndex] = 0;
                }
                if (Input.GetMouseButtonDown(0) || (fingerIndex == 1 && (Input.GetKeyDown(KeyCode.LeftAlt) || Input.GetKeyDown(EasyTouch.instance.twistKey) || Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(EasyTouch.instance.swipeKey))))
                {
                    finger.position                   = this.GetPointerPosition(fingerIndex);
                    finger.deltaPosition              = Vector2.zero;
                    this.tapCount[fingerIndex]        = this.tapCount[fingerIndex] + 1;
                    finger.tapCount                   = this.tapCount[fingerIndex];
                    this.startActionTime[fingerIndex] = Time.realtimeSinceStartup;
                    this.deltaTime[fingerIndex]       = this.startActionTime[fingerIndex];
                    finger.deltaTime                  = 0f;
                    finger.phase = TouchPhase.Began;
                    if (fingerIndex == 1)
                    {
                        this.oldFinger2Position            = finger.position;
                        this.oldMousePosition[fingerIndex] = finger.position;
                    }
                    else
                    {
                        this.oldMousePosition[fingerIndex] = finger.position;
                    }
                    if (this.tapCount[fingerIndex] == 1)
                    {
                        this.tapeTime[fingerIndex] = Time.realtimeSinceStartup;
                    }
                    return(finger);
                }
                finger.deltaPosition = finger.position - this.oldMousePosition[fingerIndex];
                finger.tapCount      = this.tapCount[fingerIndex];
                finger.deltaTime     = Time.realtimeSinceStartup - this.deltaTime[fingerIndex];
                if (finger.deltaPosition.sqrMagnitude < 1f)
                {
                    finger.phase = TouchPhase.Stationary;
                }
                else
                {
                    finger.phase = TouchPhase.Moved;
                }
                this.oldMousePosition[fingerIndex] = finger.position;
                this.deltaTime[fingerIndex]        = Time.realtimeSinceStartup;
                return(finger);
            }
            else
            {
                if (Input.GetMouseButtonUp(0))
                {
                    finger.fingerIndex   = fingerIndex;
                    finger.position      = this.GetPointerPosition(fingerIndex);
                    finger.deltaPosition = finger.position - this.oldMousePosition[fingerIndex];
                    finger.tapCount      = this.tapCount[fingerIndex];
                    finger.deltaTime     = Time.realtimeSinceStartup - this.deltaTime[fingerIndex];
                    finger.phase         = TouchPhase.Ended;
                    this.oldMousePosition[fingerIndex] = finger.position;
                    return(finger);
                }
                return(null);
            }
        }
Пример #2
0
        private void CreateGesture(int touchIndex,EvtType message,Finger finger, SwipeDirection swipe, float swipeLength, Vector2 swipeVector)
        {
            bool firingEvent = true;

            if (autoUpdatePickedUI && allowUIDetection){
            finger.isOverGui = IsScreenPositionOverUI( finger.position );
            finger.pickedUIElement = GetFirstUIElementFromCache();
            }

            // NGui
            if (enabledNGuiMode  && message == EvtType.On_TouchStart){
            finger.isOverGui = finger.isOverGui || IsTouchOverNGui(finger.position);
            }

            // firing event ?
            if ((enableUIMode || enabledNGuiMode)){
            firingEvent = !finger.isOverGui;
            }

            // The new gesture
            Gesture gesture = finger.GetGesture();

            // Auto update picked object
            if (autoUpdatePickedObject && autoSelect){
            if (message != EvtType.On_Drag && message != EvtType.On_DragEnd && message != EvtType.On_DragStart){
                if (GetPickedGameObject(finger)){
                    gesture.pickedObject = pickedObject.pickedObj;
                    gesture.pickedCamera = pickedObject.pickedCamera;
                    gesture.isGuiCamera = pickedObject.isGUI;
                }
                else{
                    gesture.pickedObject = null;
                    gesture.pickedCamera = null;
                    gesture.isGuiCamera = false;
                }
            }
            }

            gesture.swipe = swipe;
            gesture.swipeLength = swipeLength;
            gesture.swipeVector = swipeVector;

            gesture.deltaPinch = 0;
            gesture.twistAngle = 0;

            // Firing event
            if ( firingEvent){
            RaiseEvent(message, gesture);
            }
            else if (finger.isOverGui){
            if (message == EvtType.On_TouchUp){
                RaiseEvent(EvtType.On_UIElementTouchUp, gesture);
            }
            else{
                RaiseEvent(EvtType.On_OverUIElement, gesture);
            }
            }
        }
Пример #3
0
        void UpdateTouches(bool realTouch, int touchCount)
        {
            fingers.CopyTo( tmpArray,0);

            if (realTouch || enableRemote){
            ResetTouches();
            for (var i = 0; i < touchCount; ++i) {
                Touch touch = Input.GetTouch(i);

                int t=0;
                while (t < 100 && fingers[i]==null){
                    if (tmpArray[t] != null){
                        if ( tmpArray[t].fingerIndex == touch.fingerId){
                            fingers[i] = tmpArray[t];
                        }
                    }
                    t++;
                }

                if (fingers[i]==null){
                    fingers[i]= new Finger();
                    fingers[i].fingerIndex = touch.fingerId;
                    fingers[i].gesture = GestureType.None;
                    fingers[i].phase = TouchPhase.Began;
                }
                else{
                    fingers[i].phase = touch.phase;
                }

                if ( fingers[i].phase!= TouchPhase.Began){
                    fingers[i].deltaPosition = touch.position - fingers[i].position;
                }
                else{
                    fingers[i].deltaPosition = Vector2.zero;
                }

                fingers[i].position = touch.position;
                //fingers[i].deltaPosition = touch.deltaPosition;
                fingers[i].tapCount = touch.tapCount;
                fingers[i].deltaTime = touch.deltaTime;

                fingers[i].touchCount = touchCount;

            #if UNITY_5_3
                fingers[i].altitudeAngle = touch.altitudeAngle;
                fingers[i].azimuthAngle = touch.azimuthAngle;
                fingers[i].maximumPossiblePressure = touch.maximumPossiblePressure;
                fingers[i].pressure = touch.pressure;
                fingers[i].radius = touch.radius;
                fingers[i].radiusVariance = touch.radiusVariance;
                fingers[i].touchType = touch.type;
            #endif
            }
            }
            else{
            int i=0;
            while (i<touchCount){
                fingers[i] = input.GetMouseTouch(i,fingers[i]) as Finger;
                fingers[i].touchCount = touchCount;
                i++;
            }
            }
        }
Пример #4
0
        private bool GetPickedGameObject(Finger finger, bool isTowFinger=false)
        {
            if (finger == null && !isTowFinger){
            return false;
            }

            pickedObject.isGUI = false;
            pickedObject.pickedObj = null;
            pickedObject.pickedCamera = null;

            if (touchCameras.Count>0){
            for (int i=0;i<touchCameras.Count;i++){
                if (touchCameras[i].camera!=null && touchCameras[i].camera.enabled){

                    Vector2 pos=Vector2.zero;
                    if (!isTowFinger){
                        pos = finger.position;
                    }
                    else{
                        pos = twoFinger.position;
                    }

                    return GetGameObjectAt( pos,touchCameras[i].camera,touchCameras[i].guiCamera);
                    /*
                    Ray ray = touchCameras[i].camera.ScreenPointToRay( pos );
                    RaycastHit hit;

                    if (enable2D){

                        LayerMask mask2d = pickableLayers2D;
                        RaycastHit2D[] hit2D = new RaycastHit2D[1];
                        if (Physics2D.GetRayIntersectionNonAlloc( ray,hit2D,float.PositiveInfinity,mask2d)>0){
                            pickedObject.pickedCamera = touchCameras[i].camera;
                            pickedObject.isGUI = touchCameras[i].guiCamera;
                            pickedObject.pickedObj = hit2D[0].collider.gameObject;
                            return true;
                        }
                    }

                    LayerMask mask = pickableLayers3D;

                    if( Physics.Raycast( ray, out hit,float.MaxValue,mask ) ){
                        pickedObject.pickedCamera = touchCameras[i].camera;
                        pickedObject.isGUI = touchCameras[i].guiCamera;
                        pickedObject.pickedObj = hit.collider.gameObject;
                        return true;
                    }*/
                }
            }
            }
            else{
            Debug.LogWarning("No camera is assigned to EasyTouch");
            }
            return false;
        }
Пример #5
0
 private bool FingerInTolerance(Finger finger )
 {
     if ((finger.position-finger.startPosition).sqrMagnitude <= (StationaryTolerance*StationaryTolerance)){
     return true;
     }
     else{
     return false;
     }
 }
Пример #6
0
        // return in Finger structure all informations on an touch
        public Finger GetMouseTouch(int fingerIndex,Finger myFinger)
        {
            Finger finger;

            if (myFinger!=null){
            finger = myFinger;
            }
            else{
            finger = new Finger();
            finger.gesture = EasyTouch.GestureType.None;
            }

            if (fingerIndex==1 && (Input.GetKeyUp(KeyCode.LeftAlt)|| Input.GetKeyUp(EasyTouch.instance.twistKey)|| Input.GetKeyUp(KeyCode.LeftControl)|| Input.GetKeyUp(EasyTouch.instance.swipeKey))){
            finger.fingerIndex = fingerIndex;
            finger.position = oldFinger2Position;
            finger.deltaPosition = finger.position - oldFinger2Position;
            finger.tapCount = tapCount[fingerIndex];
            finger.deltaTime = Time.realtimeSinceStartup-deltaTime[fingerIndex];
            finger.phase = TouchPhase.Ended;

            return finger;
            }

            if (Input.GetMouseButton(0)){

            finger.fingerIndex = fingerIndex;
            finger.position = GetPointerPosition(fingerIndex);

            if (Time.realtimeSinceStartup-tapeTime[fingerIndex]>0.5){
                tapCount[fingerIndex]=0;
            }

            if (Input.GetMouseButtonDown(0) || (fingerIndex==1 && (Input.GetKeyDown(KeyCode.LeftAlt)|| Input.GetKeyDown(EasyTouch.instance.twistKey)|| Input.GetKeyDown(KeyCode.LeftControl)|| Input.GetKeyDown(EasyTouch.instance.swipeKey)))){

                // Began
                finger.position = GetPointerPosition(fingerIndex);
                finger.deltaPosition = Vector2.zero;
                tapCount[fingerIndex]=tapCount[fingerIndex]+1;
                finger.tapCount = tapCount[fingerIndex];
                startActionTime[fingerIndex] = Time.realtimeSinceStartup;
                deltaTime[fingerIndex] = startActionTime[fingerIndex];
                finger.deltaTime = 0;
                finger.phase = TouchPhase.Began;

                if (fingerIndex==1){
                    oldFinger2Position = finger.position;
                    oldMousePosition[fingerIndex] = finger.position;
                }
                else{
                    oldMousePosition[fingerIndex] = finger.position;
                }

                if (tapCount[fingerIndex]==1){
                    tapeTime[fingerIndex] = Time.realtimeSinceStartup;
                }

                return finger;
            }

            finger.deltaPosition = finger.position - oldMousePosition[fingerIndex];

            finger.tapCount = tapCount[fingerIndex];
            finger.deltaTime = Time.realtimeSinceStartup-deltaTime[fingerIndex];
            if (finger.deltaPosition.sqrMagnitude <1){
                finger.phase = TouchPhase.Stationary;
            }
            else{
                finger.phase = TouchPhase.Moved;
            }

            oldMousePosition[fingerIndex] = finger.position;
            deltaTime[fingerIndex] = Time.realtimeSinceStartup;

            return finger;
            }

            else if (Input.GetMouseButtonUp(0)){
            finger.fingerIndex = fingerIndex;
            finger.position = GetPointerPosition(fingerIndex);
            finger.deltaPosition = finger.position - oldMousePosition[fingerIndex];
            finger.tapCount = tapCount[fingerIndex];
            finger.deltaTime = Time.realtimeSinceStartup-deltaTime[fingerIndex];
            finger.phase = TouchPhase.Ended;
            oldMousePosition[fingerIndex] = finger.position;

            return finger;
            }

            return null;
        }