示例#1
0
 private void PanGestureUpdated(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (gesture.State == GestureRecognizerState.Began || gesture.State == GestureRecognizerState.Executing)
     {
         if (gesture.State == GestureRecognizerState.Began && MoveDPadToGestureStartLocation)
         {
             transform.position = new Vector3(gesture.FocusX, gesture.FocusY, transform.position.z);
         }
         DisableButtons();
         CheckForOverlap(new Vector2(gesture.FocusX, gesture.FocusY), PanGesture, DPadItemPanned);
     }
     else if (gesture.State == GestureRecognizerState.Ended || gesture.State == GestureRecognizerState.Failed)
     {
         DisableButtons();
     }
 }
示例#2
0
 private void LongPressGestureUpdated(DigitalRubyShared.GestureRecognizer r)
 {
     FingersPanRotateScaleComponentScript.StartOrResetGesture(r, BringToFront, Camera, gameObject, spriteRenderer, GestureRecognizerComponentScriptBase.GestureObjectMode.RequireIntersectWithGameObject);
     if (r.State == GestureRecognizerState.Began)
     {
         transform.localScale *= DragScale;
         panZ      = Camera.WorldToScreenPoint(transform.position).z;
         panOffset = transform.position - Camera.ScreenToWorldPoint(new Vector3(r.FocusX, r.FocusY, panZ));
         if (DragStarted != null)
         {
             DragStarted.Invoke(this, System.EventArgs.Empty);
         }
     }
     else if (r.State == GestureRecognizerState.Executing)
     {
         Vector3 gestureScreenPoint = new Vector3(r.FocusX, r.FocusY, panZ);
         Vector3 gestureWorldPoint  = Camera.ScreenToWorldPoint(gestureScreenPoint) + panOffset;
         if (rigidBody != null)
         {
             rigidBody.MovePosition(gestureWorldPoint);
         }
         else if (rigidBody2D != null)
         {
             rigidBody2D.MovePosition(gestureWorldPoint);
         }
         else
         {
             transform.position = gestureWorldPoint;
         }
         if (DragUpdated != null)
         {
             DragUpdated.Invoke(this, System.EventArgs.Empty);
         }
     }
     else if (r.State == GestureRecognizerState.Ended)
     {
         transform.localScale /= DragScale;
         if (spriteRenderer != null && BringToFront)
         {
             spriteRenderer.sortingOrder = startSortOrder;
         }
         if (DragEnded != null)
         {
             DragEnded.Invoke(this, System.EventArgs.Empty);
         }
     }
 }
示例#3
0
        private void RotateGestureUpdated(DigitalRubyShared.GestureRecognizer r)
        {
            if (!AllowRotate)
            {
                r.Reset();
                return;
            }

            Camera     camera;
            GameObject obj = FingersScript.StartOrResetGesture(r, BringToFront, Cameras, gameObject, spriteRenderer, Mode, out camera);

            if (camera == null)
            {
                r.Reset();
                return;
            }
            else if (r.State == GestureRecognizerState.Began)
            {
                SetStartState(r, obj, false);
            }
            else if (r.State == GestureRecognizerState.Executing && _transform != null)
            {
                if (rigidBody != null)
                {
                    float      angle    = RotateGesture.RotationDegreesDelta;
                    Quaternion rotation = Quaternion.AngleAxis(angle, camera.transform.forward);
                    rigidBody.MoveRotation(rigidBody.rotation * rotation);
                }
                else if (rigidBody2D != null)
                {
                    rigidBody2D.MoveRotation(rigidBody2D.rotation + RotateGesture.RotationDegreesDelta);
                }
                else if (canvasRenderer != null)
                {
                    _transform.Rotate(Vector3.forward, RotateGesture.RotationDegreesDelta, Space.Self);
                }
                else
                {
                    _transform.Rotate(camera.transform.forward, RotateGesture.RotationDegreesDelta, Space.Self);
                }
            }
            else if (r.State == GestureRecognizerState.Ended)
            {
                ClearStartState();
            }
        }
示例#4
0
        /// <summary>
        /// Callback for image gesture
        /// </summary>
        /// <param name="gesture">Image gesture</param>
        public void ImageGestureExecuted(DigitalRubyShared.GestureRecognizer gesture)
        {
            ImageGestureRecognizer imgGesture = gesture as ImageGestureRecognizer;

            if (gesture.State == GestureRecognizerState.Ended)
            {
                if (imgGesture.MatchedGestureImage == null)
                {
                    Debug.Log("Image gesture failed to match.");
                }
                else
                {
                    Debug.Log("Image gesture matched!");
                }
                gesture.Reset();
            }
        }
示例#5
0
        private void TapGesture_Updated(DigitalRubyShared.GestureRecognizer gesture)
        {
            if (TapGesture.State != GestureRecognizerState.Ended)
            {
                return;
            }
            Ray        ray = _camera.ScreenPointToRay(new Vector3(TapGesture.FocusX, TapGesture.FocusY, 0.0f));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, float.MaxValue, TapToCenterLayerMask))
            {
                // adjust camera x, y to look at the tapped / clicked sphere
                cameraAnimationTargetPosition = new Vector3(hit.transform.position.x, hit.transform.position.y, _camera.transform.position.z);
                StopAllCoroutines();
                StartCoroutine(AnimationCoRoutine());
            }
        }
示例#6
0
        private void Swipe_Updated(DigitalRubyShared.GestureRecognizer gesture)
        {
            Debug.LogFormat("Swipe state: {0}", gesture.State);

            SwipeGestureRecognizer swipe = gesture as SwipeGestureRecognizer;

            if (swipe.State == GestureRecognizerState.Ended)
            {
                float angle = Mathf.Atan2(-swipe.DistanceY, swipe.DistanceX) * Mathf.Rad2Deg;
                SwipeParticleSystem.transform.rotation = Quaternion.Euler(angle, 90.0f, 0.0f);
                Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(gesture.StartFocusX, gesture.StartFocusY, 0.0f));
                pos.z = 0.0f;
                SwipeParticleSystem.transform.position = pos;
                SwipeParticleSystem.Play();
                Debug.LogFormat("Swipe dir: {0}", swipe.EndDirection);
            }
        }
        private void ScaleGesture_Updated(DigitalRubyShared.GestureRecognizer gesture)
        {
            // if gesture is not executing, exit function
            if (gesture.State != GestureRecognizerState.Executing)
            {
                return;
            }

            if (ScaleGesture.ScaleMultiplier > 1.0f)
            {
                zoomSpeed += (ScaleGesture.ScaleMultiplier * ZoomSpeed);
            }
            else if (ScaleGesture.ScaleMultiplier < 1.0f)
            {
                zoomSpeed -= ((1.0f / ScaleGesture.ScaleMultiplier) * ZoomSpeed);
            }
        }
示例#8
0
 private void LongPressGestureCallback(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (gesture.State == GestureRecognizerState.Began)
     {
         DebugText("Long press began: {0}, {1}", gesture.FocusX, gesture.FocusY);
         BeginDrag(gesture.FocusX, gesture.FocusY);
     }
     else if (gesture.State == GestureRecognizerState.Executing)
     {
         DebugText("Long press moved: {0}, {1}", gesture.FocusX, gesture.FocusY);
         DragTo(gesture.FocusX, gesture.FocusY);
     }
     else if (gesture.State == GestureRecognizerState.Ended)
     {
         DebugText("Long press end: {0}, {1}, delta: {2}, {3}", gesture.FocusX, gesture.FocusY, gesture.DeltaX, gesture.DeltaY);
         EndDrag(longPressGesture.VelocityX, longPressGesture.VelocityY);
     }
 }
        private void PanGestureUpdated(DigitalRubyShared.GestureRecognizer r)
        {
            GameObject obj = StartOrResetGesture(r, BringToFront, Camera, gameObject, spriteRenderer, Mode);

            if (r.State == GestureRecognizerState.Began)
            {
                SetStartState(r, obj, false);
            }
            else if (r.State == GestureRecognizerState.Executing && _transform != null)
            {
                if (PanGesture.ReceivedAdditionalTouches)
                {
                    panZ      = Camera.WorldToScreenPoint(_transform.position).z;
                    panOffset = _transform.position - Camera.ScreenToWorldPoint(new Vector3(r.FocusX, r.FocusY, panZ));
                }
                Vector3 gestureScreenPoint = new Vector3(r.FocusX, r.FocusY, panZ);
                Vector3 gestureWorldPoint  = Camera.ScreenToWorldPoint(gestureScreenPoint) + panOffset;
                if (rigidBody != null)
                {
                    rigidBody.MovePosition(gestureWorldPoint);
                }
                else if (rigidBody2D != null)
                {
                    rigidBody2D.MovePosition(gestureWorldPoint);
                }
                else if (canvasRenderer != null)
                {
                    _transform.position = gestureScreenPoint;
                }
                else
                {
                    _transform.position = gestureWorldPoint;
                }
            }
            else if (r.State == GestureRecognizerState.Ended)
            {
                if (spriteRenderer != null && BringToFront)
                {
                    spriteRenderer.sortingOrder = startSortOrder;
                }
                ClearStartState();
            }
        }
 private bool SetStartState(DigitalRubyShared.GestureRecognizer gesture, GameObject obj, bool force)
 {
     if (!force && Mode != GestureRecognizerComponentScriptBase.GestureObjectMode.AllowOnAnyGameObjectViaRaycast)
     {
         return(false);
     }
     else if (obj == null)
     {
         ClearStartState();
         return(false);
     }
     else if (_transform == null)
     {
         rigidBody2D    = obj.GetComponent <Rigidbody2D>();
         rigidBody      = obj.GetComponent <Rigidbody>();
         spriteRenderer = obj.GetComponent <SpriteRenderer>();
         canvasRenderer = obj.GetComponent <CanvasRenderer>();
         if (spriteRenderer != null)
         {
             startSortOrder = spriteRenderer.sortingOrder;
         }
         _transform = (rigidBody == null ? (rigidBody2D == null ? obj.transform : rigidBody2D.transform) : rigidBody.transform);
         if (DoubleTapResetMode != _DoubleTapResetMode.Off && !savedStates.ContainsKey(_transform))
         {
             savedStates[_transform] = new SavedState {
                 Rotation = _transform.rotation, Scale = _transform.localScale, Position = _transform.position
             };
         }
         if (startScale == null)
         {
             startScale = _transform.localScale;
         }
     }
     else if (_transform != obj.transform)
     {
         if (gesture != null)
         {
             gesture.Reset();
         }
         return(false);
     }
     return(true);
 }
        private void SwipeDown_StateUpdated(DigitalRubyShared.GestureRecognizer gesture)
        {
            if (gesture.State == GestureRecognizerState.Ended)
            {
                // if on a platform, drop down
                Collider2D platform = FindIntersectingPlatform();
                if (platform != null)
                {
                    PlatformEffector2D effector = platform.GetComponent <PlatformEffector2D>();
                    if (effector != null)
                    {
                        // allow fall through
                        effector.rotationalOffset = -180.0f;

                        StartCoroutine(StopFallThrough(effector));
                    }
                }
            }
        }
示例#12
0
 //===============================================================
 //GESTURE IMPLIMENTATION
 private void TapHandle(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (gesture.State == GestureRecognizerState.Ended)
     {
         if (GameManager.Instance.gameState == GameManager.GameState.Gameplay)
         {
             RaycastHit hit;
             Ray        ray = cam.ScreenPointToRay(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f));
             if (Physics.Raycast(ray, out hit))
             {
                 if (hit.collider.tag == "Interactable")
                 {
                     hit.collider.gameObject.GetComponent <InteractableObstacle>().Anim();
                     return;
                 }
             }
         }
     }
 }
示例#13
0
        private void ScaleGestureUpdated(DigitalRubyShared.GestureRecognizer r)
        {
            if (!AllowScale)
            {
                r.Reset();
                return;
            }
            else if (MinMaxScale.x == MinMaxScale.y && MinMaxScale.y == 1.0f)
            {
                return;
            }

            Camera     camera;
            GameObject obj = FingersScript.StartOrResetGesture(r, BringToFront, Cameras, gameObject, spriteRenderer, Mode, out camera);

            if (camera == null)
            {
                r.Reset();
                return;
            }
            else if (r.State == GestureRecognizerState.Began)
            {
                SetStartState(r, obj, false);
            }
            else if (r.State == GestureRecognizerState.Executing && _transform != null)
            {
                // assume uniform scale
                float scale = _transform.localScale.x * ScaleGesture.ScaleMultiplier;

                if (MinMaxScale.x > 0.0f && MinMaxScale.y >= MinMaxScale.x)
                {
                    scale = Mathf.Clamp(scale, MinMaxScale.x, MinMaxScale.y);
                }

                // don't mess with z scale for 2D
                float zScale = (rigidBody2D == null && spriteRenderer == null && canvasRenderer == null ? scale : _transform.localScale.z);
                _transform.localScale = new Vector3(scale, scale, zScale);
            }
            else if (r.State == GestureRecognizerState.Ended)
            {
                ClearStartState();
            }
        }
示例#14
0
 private void Tap_Updated(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (doubleTapScaleTimeSecondsRemaining == 0.0f && gesture.State == GestureRecognizerState.Ended)
     {
         doubleTapScaleStart = contentRectTransform.localScale.x;
         doubleTapScaleTimeSecondsRemaining = DoubleTapAnimationTimeSeconds;
         if (ScrollContent.transform.localScale.x >= DoubleTapZoomOutThreshold)
         {
             doubleTapScaleEnd = Mathf.Min(MaximumScale, DoubleTapZoomOutValue);
         }
         else
         {
             doubleTapScaleEnd = Mathf.Max(MinimumScale, DoubleTapZoomInValue);
         }
         doubleTapPosStart = contentRectTransform.anchoredPosition;
         Vector2 localPoint;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(contentRectTransform, new Vector2(gesture.FocusX, gesture.FocusY), CanvasCamera, out localPoint);
         doubleTapPosEnd = localPoint * -doubleTapScaleEnd;
     }
 }
示例#15
0
 public void GestureCallback(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (gesture.State == GestureRecognizerState.Began)
     {
     }
     else if (gesture.State == GestureRecognizerState.Executing)
     {
     }
     else if (gesture.State == GestureRecognizerState.Ended)
     {
         // save off the matched image, the gesture may reset if max path count has been reached
         matchedImage = Gesture.MatchedGestureImage;
     }
     else
     {
         // don't update lines
         return;
     }
     UpdateLines();
 }
示例#16
0
 private void Pan_Updated(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (gesture.State == GestureRecognizerState.Began)
     {
         panStart = contentRectTransform.anchoredPosition;
     }
     else if (gesture.State == GestureRecognizerState.Executing)
     {
         Vector2 zero;
         Vector2 offset;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRectTransform, Vector2.zero, null, out zero);
         RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRectTransform, new Vector2(gesture.DistanceX, gesture.DistanceY), null, out offset);
         contentRectTransform.anchoredPosition = panStart + offset - zero;
     }
     else if (gesture.State == GestureRecognizerState.Ended)
     {
         panVelocity   = new Vector2(gesture.VelocityX, gesture.VelocityY);
         panVelocity.x = Mathf.Clamp(panVelocity.x, -MaxSpeed, MaxSpeed);
         panVelocity.y = Mathf.Clamp(panVelocity.y, -MaxSpeed, MaxSpeed);
     }
 }
        public static GameObject StartOrResetGesture(DigitalRubyShared.GestureRecognizer r, bool bringToFront, Camera camera, GameObject obj, SpriteRenderer spriteRenderer, GestureRecognizerComponentScriptBase.GestureObjectMode mode)
        {
            GameObject result = null;

            if (r.State == GestureRecognizerState.Began)
            {
                if ((result = GestureIntersectsObject(r, camera, obj, mode)) != null)
                {
                    SpriteRenderer _spriteRenderer;
                    if (bringToFront && (_spriteRenderer = result.GetComponent <SpriteRenderer>()) != null)
                    {
                        _spriteRenderer.sortingOrder = 1000;
                    }
                }
                else
                {
                    r.Reset();
                }
            }
            return(result);
        }
 private void ImageGestureUpdated(DigitalRubyShared.GestureRecognizer imageGesture)
 {
     if (imageGesture.State == GestureRecognizerState.Ended)
     {
         AddTouches(imageGesture.CurrentTrackedTouches);
         // note - if you have received an image you care about, you should reset the image gesture, i.e. imageGesture.Reset()
         // the ImageGestureRecognizer doesn't automaticaly Reset like other gestures when it ends because some images need multiple paths
         // which requires lifting the mouse or finger and drawing again
     }
     else if (imageGesture.State == GestureRecognizerState.Began)
     {
         // began
         currentPointList = new List <Vector2>();
         lineSet.Add(currentPointList);
         AddTouches(imageGesture.CurrentTrackedTouches);
     }
     else if (imageGesture.State == GestureRecognizerState.Executing)
     {
         // moving
         AddTouches(imageGesture.CurrentTrackedTouches);
     }
 }
示例#19
0
        private void Scale_Updated(DigitalRubyShared.GestureRecognizer gesture)
        {
            if (gesture.State == GestureRecognizerState.Executing)
            {
                float scale = (gesture as ScaleGestureRecognizer).ScaleMultiplier;

                if (scale >= 0.999f && scale <= 1.001f)
                {
                    return;
                }
                else if (scale > 1.0f)
                {
                    zoomSpeed += (scale * ScaleSpeed);
                }
                else if (scale < 1.0f)
                {
                    zoomSpeed -= ((1.0f / scale) * ScaleSpeed);
                }
                lastScaleFocus = new Vector2(gesture.FocusX, gesture.FocusY);
            }

            WriteDebug("Scale: {0},{1}", gesture.State, (gesture as ScaleGestureRecognizer).ScaleMultiplier);
        }
 private void Tap_Updated(DigitalRubyShared.GestureRecognizer gesture)
 {
     if (scaleEnd == 0.0f && gesture.State == GestureRecognizerState.Ended)
     {
         scaleStart       = contentRectTransform.localScale.x;
         scaleTime        = 0.5f;
         elapsedScaleTime = 0.0f;
         if (ScrollContent.transform.localScale.x >= 2.5f)
         {
             // zoom out
             scaleEnd = 1.0f;
         }
         else
         {
             // zoom in
             scaleEnd = 4.0f;
         }
         scalePosStart = contentRectTransform.anchoredPosition;
         Vector2 localPoint;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(contentRectTransform, new Vector2(gesture.FocusX, gesture.FocusY), null, out localPoint);
         scalePosEnd = localPoint * -scaleEnd;
     }
 }
 private void DoubleTapGestureUpdated(DigitalRubyShared.GestureRecognizer r)
 {
     if (DoubleTapResetMode == _DoubleTapResetMode.Off)
     {
         r.Reset();
         return;
     }
     else if (r.State == GestureRecognizerState.Ended)
     {
         GameObject obj = GestureIntersectsObject(r, Camera, gameObject, Mode);
         SavedState state;
         if (obj != null && savedStates.TryGetValue(obj.transform, out state))
         {
             obj.transform.rotation   = state.Rotation;
             obj.transform.localScale = state.Scale;
             if (DoubleTapResetMode == _DoubleTapResetMode.ResetScaleRotationPosition)
             {
                 obj.transform.position = state.Position;
             }
             savedStates.Remove(obj.transform);
         }
     }
 }
示例#22
0
        private static GameObject GestureIntersectsObject(DigitalRubyShared.GestureRecognizer r, Camera camera, GameObject obj, GestureRecognizerComponentScriptBase.GestureObjectMode mode)
        {
            if (EventSystem.current == null)
            {
                return(null);
            }

            captureRaycastResults.Clear();
            PointerEventData p = new PointerEventData(EventSystem.current);

            p.Reset();
            p.position   = new Vector2(r.FocusX, r.FocusY);
            p.clickCount = 1;
            EventSystem.current.RaycastAll(p, captureRaycastResults);
            captureRaycastResults.Sort(RaycastResultCompare);

            foreach (RaycastResult result in captureRaycastResults)
            {
                if (result.gameObject == obj)
                {
                    return(result.gameObject);
                }
                else if (result.gameObject.GetComponent <Collider>() != null ||
                         result.gameObject.GetComponent <Collider2D>() != null ||
                         result.gameObject.GetComponent <FingersPanRotateScaleComponentScript>() != null)
                {
                    if (mode == GestureRecognizerComponentScriptBase.GestureObjectMode.AllowOnAnyGameObjectViaRaycast)
                    {
                        return(result.gameObject);
                    }

                    // blocked by a collider or another gesture, bail
                    break;
                }
            }
            return(null);
        }
 private void PanGesture_Updated(DigitalRubyShared.GestureRecognizer gesture)
 {
     // if gesture is not executing, exit function
     if (gesture.State != GestureRecognizerState.Executing)
     {
         if (gesture.State == GestureRecognizerState.Ended)
         {
             lockedAxis = 0;
             if (OrbitInertia > 0.0f)
             {
                 panVelocity = new Vector2(gesture.VelocityX * 0.01f, gesture.VelocityY * 0.01f);
                 if (OrbitXSpeed == 0.0f)
                 {
                     panVelocity.x = 0.0f;
                 }
                 if (OrbitYSpeed == 0.0f)
                 {
                     panVelocity.y = 0.0f;
                 }
             }
         }
         else if (gesture.State == GestureRecognizerState.Began)
         {
             panVelocity = Vector2.zero;
         }
         return;
     }
     else
     {
         float xVelocity = gesture.DeltaX;
         float yVelocity = gesture.DeltaY;
         if (PanGestureHasEnoughMovementOnOneAxis(ref xVelocity, ref yVelocity))
         {
             UpdateOrbit(xVelocity, yVelocity);
         }
     }
 }
示例#24
0
        private void PanGestureUpdated(DigitalRubyShared.GestureRecognizer gesture)
        {
            if (gesture.State == GestureRecognizerState.Executing)
            {
                // clamp joystick movement to max values
                float   maxOffset = (Screen.width + Screen.height) * MaxExtentPercent;
                Vector2 offset    = new Vector2(gesture.FocusX - gesture.StartFocusX, gesture.FocusY - gesture.StartFocusY);

                // check distance from center, clamp to distance
                offset = Vector2.ClampMagnitude(offset, maxOffset);

                // don't bother if no motion
                if (offset == Vector2.zero)
                {
                    return;
                }

                // handle eight axis offset param
                offset = UpdateForEightAxisMode(offset, maxOffset);

                // move image
                SetImagePosition(startCenter + offset);

                if (!AddUpToOne)
                {
                    float maxOffsetLerp = maxOffset * 0.7f;
                    offset.x = Mathf.Sign(offset.x) * Mathf.Lerp(0.0f, maxOffset, Mathf.Abs(offset.x / maxOffsetLerp));
                    offset.y = Mathf.Sign(offset.y) * Mathf.Lerp(0.0f, maxOffset, Mathf.Abs(offset.y / maxOffsetLerp));
                }

                // callback with movement weight
                if (JoystickPower >= 1.0f)
                {
                    // power is reducing offset, apply as is
                    offset.x = Mathf.Sign(offset.x) * Mathf.Pow(Mathf.Abs(offset.x) / maxOffset, JoystickPower);
                    offset.y = Mathf.Sign(offset.y) * Mathf.Pow(Mathf.Abs(offset.y) / maxOffset, JoystickPower);
                }
                else
                {
                    // power is increasing offset, we need to make sure we maintain the aspect ratio of offset
                    Vector2 absOffset   = new Vector2(Mathf.Abs(offset.x), Mathf.Abs(offset.y));
                    float   offsetTotal = absOffset.x + absOffset.y;
                    float   xWeight     = absOffset.x / offsetTotal;
                    float   yWeight     = absOffset.y / offsetTotal;
                    offset.x = xWeight * Mathf.Sign(offset.x) * Mathf.Pow(absOffset.x / maxOffset, JoystickPower);
                    offset.y = yWeight * Mathf.Sign(offset.y) * Mathf.Pow(absOffset.y / maxOffset, JoystickPower);
                    offset   = Vector2.ClampMagnitude(offset, maxOffset);
                }
                ExecuteCallback(offset);

                if (crossPlatformInputHorizontalAxisObject != null)
                {
                    FingersCrossPlatformInputReflectionScript.UpdateVirtualAxis(crossPlatformInputHorizontalAxisObject, offset.x);
                }
                if (crossPlatformInputVerticalAxisObject != null)
                {
                    FingersCrossPlatformInputReflectionScript.UpdateVirtualAxis(crossPlatformInputVerticalAxisObject, offset.y);
                }
            }
            else if (gesture.State == GestureRecognizerState.Began)
            {
                if (MoveJoystickToGestureStartLocation)
                {
                    JoystickImage.transform.parent.position = new Vector3(gesture.FocusX, gesture.FocusY, JoystickImage.transform.parent.position.z);
                }
                startCenter = JoystickImage.rectTransform.anchoredPosition;
            }
            else if (gesture.State == GestureRecognizerState.Ended)
            {
                // return to center
                SetImagePosition(startCenter);

                // final callback
                ExecuteCallback(Vector2.zero);
            }
        }
示例#25
0
 /// <summary>
 /// Callback for one touch scale gesture
 /// </summary>
 /// <param name="gesture">One touch scale gesture</param>
 public void OneTouchScaleGestureExecuted(DigitalRubyShared.GestureRecognizer gesture)
 {
     oneTouchScale *= (gesture as OneTouchScaleGestureRecognizer).ScaleMultiplier;
     Debug.LogFormat("Scale gesture executing, state: {0}, scale: {1} pos: {2},{3}", gesture.State, oneTouchScale, gesture.FocusX, gesture.FocusY);
 }
示例#26
0
 /// <summary>
 /// Callback for rotate gesture
 /// </summary>
 /// <param name="gesture">Rotate gesture</param>
 public void RotateGestureExecuted(DigitalRubyShared.GestureRecognizer gesture)
 {
     Debug.LogFormat("Rotate gesture executing, state: {0}, degrees: {1} pos: {2},{3}", gesture.State, (gesture as RotateGestureRecognizer).RotationDegrees, gesture.FocusX, gesture.FocusY);
 }
示例#27
0
        private ICollection <GestureTouch> FilterTouchesBegan(List <GestureTouch> touches, DigitalRubyShared.GestureRecognizer r)
        {
            // in order to begin, touches must match the platform specific view
            List <GameObject> gameObjects;

            filteredTouches.Clear();
            foreach (GestureTouch t in touches)
            {
                if (!gameObjectsForTouch.TryGetValue(t.Id, out gameObjects) || GameObjectMatchesPlatformSpecificView(gameObjects, r))
                {
                    filteredTouches.Add(t);
                }
            }
            return(filteredTouches);
        }
 private void RotationGesture_Updated(DigitalRubyShared.GestureRecognizer gesture)
 {
     Orbiter.transform.RotateAround(OrbitTarget.transform.position, Axis, RotationGesture.RotationDegreesDelta * Time.deltaTime * RotationSpeed);
 }
示例#29
0
 /// <summary>
 /// Callback for long press gesture
 /// </summary>
 /// <param name="gesture">Long press gesture</param>
 public void LongPressGestureExecuted(DigitalRubyShared.GestureRecognizer gesture)
 {
     Debug.LogFormat("Long press gesture executing, state: {0}, pos: {1},{2}", gesture.State, gesture.FocusX, gesture.FocusY);
 }
示例#30
0
        private void LongPress_StateUpdated(DigitalRubyShared.GestureRecognizer gesture)
        {
            if (gesture.State == GestureRecognizerState.Began)
            {
                // raycast out for the card - this let's us have multiple cards
                Vector3    gestureWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f));
                Collider2D hit             = Physics2D.OverlapPoint(gestureWorldPos);

                // see if we found a card
                if (hit != null && !swipedCards.Contains(hit.transform))
                {
                    // set the draggingCard variable to the card transform, this let's us move it around in the "Executing" state
                    Debug.Log("Found card, beginning drag...");
                    draggingCard            = hit.GetComponent <Transform>();
                    draggingCard.localScale = Vector3.one * 1.2f;
                    draggingCard.transform.SetSiblingIndex(draggingCard.transform.parent.childCount - 1);
                    SpriteRenderer renderer = draggingCard.GetComponent <SpriteRenderer>();
                    if (renderer != null)
                    {
                        // put the picked up card on top of everything else
                        renderer.transform.SetSiblingIndex(renderer.transform.parent.childCount - 1);
                        for (int i = 0; i < renderer.transform.parent.childCount; i++)
                        {
                            SpriteRenderer other = renderer.transform.parent.GetChild(i).GetComponent <SpriteRenderer>();
                            if (other != null)
                            {
                                // make sure sort order and z position is set for the other cards to ensure they are in the right
                                // spot in the pile
                                other.sortingOrder = i;
                                Vector3 pos = other.transform.position;
                                pos.z = ((float)(renderer.transform.parent.childCount - i) * 0.01f);
                                other.transform.position = pos;
                            }
                        }
                    }
                }
                else
                {
                    // no card, reset the gesture and they must lift the touch and try again
                    Debug.Log("No card under gesture, resetting...");
                    gesture.Reset();
                }

                // apply an offset from the center of the card so it drags from wherever it was touched on the card
                dragOffset   = draggingCard.position - Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f));
                dragOffset.z = 0.0f;
            }
            else if (gesture.State == GestureRecognizerState.Executing)
            {
                // if the gesture velocity is high enough, fling the card off screen
                float speed = longPress.Distance(gesture.VelocityX, gesture.VelocityY);
                if (speed >= SwipeAwaySpeed)
                {
                    // convert the screen units velocity to world velocity and apply to the card
                    draggingCard.localScale = Vector3.one;
                    Vector3 worldVelocityZero    = Camera.main.ScreenToWorldPoint(Vector3.zero);
                    Vector3 worldVelocityGesture = Camera.main.ScreenToWorldPoint(new Vector3(gesture.VelocityX, gesture.VelocityY, 0.0f));
                    Vector3 worldVelocity        = (worldVelocityGesture - worldVelocityZero) * 0.5f;
                    worldVelocity.z = 0.0f;
                    Rigidbody2D rb = draggingCard.GetComponent <Rigidbody2D>();
                    rb.velocity = worldVelocity;

                    // apply some random spin for fun
                    rb.angularVelocity = Random.Range(-1000.0f, 1000.0f);

                    // don't allow the card to be re-dragged while it flings away
                    swipedCards.Add(draggingCard);
                    draggingCard = null;

                    // reset gesture, the swipe away finishes the gesture
                    gesture.Reset();

                    Debug.LogFormat("Swiping card away at world velocity {0} (screen velocity units {1})", (Vector2)worldVelocity, new Vector2(gesture.VelocityX, gesture.VelocityY));
                }
                else
                {
                    // drag the card
                    Vector3 dragCurrent = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f));
                    dragCurrent.z         = draggingCard.transform.position.z;
                    draggingCard.position = dragCurrent + dragOffset;
                }
            }
            else
            {
                // if not begin or execute state, null out the dragging card
                if (draggingCard != null)
                {
                    draggingCard.localScale = Vector3.one;
                    SpriteRenderer renderer = draggingCard.GetComponent <SpriteRenderer>();
                    if (renderer != null)
                    {
                        //renderer.sortingOrder = savedSortOrder;
                    }
                }
                draggingCard = null;
            }
        }