Esempio n. 1
0
        private void Awake()
        {
            singleton = this;

            // setup DPI, using a default value if it cannot be determined
            DeviceInfo.PixelsPerInch = (int)Screen.dpi;
            if (DeviceInfo.PixelsPerInch > 0)
            {
                DeviceInfo.UnitMultiplier = DeviceInfo.PixelsPerInch;
            }
            else
            {
                // pick a sensible dpi since we don't know the actual DPI
                DeviceInfo.UnitMultiplier = DeviceInfo.PixelsPerInch = DefaultDPI;
            }

            // set the main thread callback so gestures can callback after a delay
            GestureRecognizer.MainThreadCallback = (float delay, System.Action callback) =>
            {
                StartCoroutine(MainThreadCallback(delay, callback));
            };

            ResetState(false);
            UnityEngine.SceneManagement.SceneManager.sceneUnloaded += SceneManagerSceneUnloaded;
            if (!Input.multiTouchEnabled)
            {
                Input.multiTouchEnabled = true;
            }
            Input.simulateMouseWithTouches = SimulateMouseWithTouches;
            SetupDefaultPassThroughComponents();

#if UNITY_EDITOR
            if (EventSystem.current == null)
            {
                Debug.LogWarning("An event system is required if you want to use platform specific views for 2d and 3d collider game objects.");
            }
#endif
        }
Esempio n. 2
0
        private void Awake()
        {
            if (singleton != null && singleton != this && singleton.liveForever)
            {
                Debug.Log("A singleton instance of Fingers Script was already setup. You don't need to add any additional Fingers Script objects.");
                DestroyImmediate(gameObject, true);
                return;
            }

            // setup DPI, using a default value if it cannot be determined
            DeviceInfo.PixelsPerInch = (int)Screen.dpi;
            if (DeviceInfo.PixelsPerInch > 0)
            {
                DeviceInfo.UnitMultiplier = DeviceInfo.PixelsPerInch;
            }
            else
            {
                // pick a sensible dpi since we don't know the actual DPI
                DeviceInfo.UnitMultiplier = DeviceInfo.PixelsPerInch = DefaultDPI;
            }

            // set the main thread callback so gestures can callback after a delay
            GestureRecognizer.MainThreadCallback = (float delay, System.Action callback) =>
            {
                StartCoroutine(MainThreadCallback(delay, callback));
            };

            UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManagerSceneLoaded;

            ResetState();

            Input.multiTouchEnabled = true;

            SetupDefaultPassThroughComponents();

            singleton = this;
        }
Esempio n. 3
0
 private void DoubleTapGestureUpdated(DigitalRubyShared.GestureRecognizer r)
 {
     if (DoubleTapResetMode == _DoubleTapResetMode.Off)
     {
         r.Reset();
         return;
     }
     else if (r.State == GestureRecognizerState.Ended)
     {
         Camera     camera = FingersScript.GetCameraForGesture(r, Cameras);
         GameObject obj    = FingersScript.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);
         }
     }
 }
        private void PanGestureUpdated(DigitalRubyShared.GestureRecognizer panGesture)
        {
            if (!AllowPan)
            {
                panGesture.Reset();
                return;
            }

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

            if (camera == null)
            {
                panGesture.Reset();
                return;
            }

            StateUpdated.Invoke(PanGesture);
            if (panGesture.State == GestureRecognizerState.Began)
            {
                SetStartState(panGesture, obj, false);
            }
            else if (panGesture.State == GestureRecognizerState.Executing && _transform != null)
            {
                if (PanGesture.ReceivedAdditionalTouches)
                {
                    panZ = camera.WorldToScreenPoint(_transform.position).z;
                    if (canvasRenderer == null)
                    {
                        panOffset = _transform.position - camera.ScreenToWorldPoint(new Vector3(panGesture.FocusX, panGesture.FocusY, panZ));
                    }
                    else
                    {
                        Vector2 screenToCanvasPoint = canvasRenderer.GetComponentInParent <Canvas>().ScreenToCanvasPoint(new Vector2(panGesture.FocusX, panGesture.FocusY));
                        panOffset = new Vector3(screenToCanvasPoint.x - _transform.position.x, screenToCanvasPoint.y - _transform.position.y, 0.0f);
                    }
                }
                Vector3 gestureScreenPoint = new Vector3(panGesture.FocusX, panGesture.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 - panOffset;
                }
                else
                {
                    _transform.position = gestureWorldPoint;
                }
            }
            else if (panGesture.State == GestureRecognizerState.Ended)
            {
                if (spriteRenderer != null && BringToFront)
                {
                    spriteRenderer.sortingOrder = startSortOrder;
                }
                ClearStartState();
            }
        }