Beispiel #1
0
        protected virtual void UpdateFingers(List <LeanFinger> fingers)
        {
            if (fingers.Count > 0)
            {
                // Get delta
                var delta = LeanGesture.GetScreenDelta(fingers);

                // Ignore?
                if (delta.sqrMagnitude == 0.0f)
                {
                    return;
                }

                // Scale?
                if (DeltaCoordinates == DeltaCoordinatesType.Scaled)
                {
                    delta *= LeanTouch.ScalingFactor;
                }

                // Call events
                if (OnSetCenter != null)
                {
                    OnSetCenter.Invoke(LeanGesture.GetScreenCenter(fingers));
                }

                if (OnSetDelta != null)
                {
                    OnSetDelta.Invoke(delta);
                }
            }
        }
Beispiel #2
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel translation
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount, RequiredSelectable);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);
            int layerMask   = ~LayerMask.GetMask("Ignore Raycast");

            if (Input.GetMouseButton(0))
            {
                Ray        raycast = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit raycastHit;
                if (Physics.Raycast(raycast, out raycastHit, Mathf.Infinity, layerMask, QueryTriggerInteraction.UseGlobal))
                {
                    // Perform the translation
                    Debug.Log("Ray hit occurred!");
                    Translate(screenDelta, raycastHit);
                }
            }
        }
Beispiel #3
0
        protected virtual void Update()
        {
            // Make sure the camera exists
            cachedCamera = LeanTouch.GetCamera(Camera, gameObject);

            if (cachedCamera != null)
            {
                // Get the fingers we want to use
                var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

                if (fingers.Count > 0)
                {
                    // If it's the first frame the fingers are down, grab the current screen point of this GameObject
                    if (targetSet == false)
                    {
                        targetSet         = true;
                        targetScreenPoint = cachedCamera.WorldToScreenPoint(transform.position);
                    }

                    // Shift target point based on finger deltas
                    targetScreenPoint += LeanGesture.GetScreenDelta(fingers);
                }
                // Unset if no fingers are down
                else
                {
                    targetSet = false;
                }
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }
Beispiel #4
0
        protected virtual void Update()
        {
            // Make sure the camera exists
            cachedCamera = LeanHelper.GetCamera(Camera, gameObject);

            if (cachedCamera != null)
            {
                // Get the fingers we want to use
                var fingers = Use.GetFingers();

                if (fingers.Count > 0)
                {
                    // If it's the first frame the fingers are down, grab the current screen point of this GameObject
                    if (targetSet == false)
                    {
                        targetSet         = true;
                        targetScreenPoint = cachedCamera.WorldToScreenPoint(transform.position);
                    }

                    // Shift target point based on finger deltas
                    // NOTE: targetScreenPoint.z already stores the depth
                    targetScreenPoint += (Vector3)LeanGesture.GetScreenDelta(fingers);
                }
                // Unset if no fingers are down
                else
                {
                    targetSet = false;
                }
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }
        protected virtual void Update()
        {
            // Make sure the camera exists
            cachedCamera = LeanTouch.GetCamera(Camera, gameObject);

            if (cachedCamera != null)
            {
                // Get the fingers we want to use
                var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

                if (fingers.Count > 0)
                {
                    // If it's the first frame the fingers are down, grab the current screen point of this GameObject
                    if (targetSet == false)
                    {
                        targetSet         = true;
                        targetScreenPoint = cachedCamera.WorldToScreenPoint(transform.position);
                    }

                    // Shift target point based on finger deltas
                    // NOTE: targetScreenPoint.z already stores the depth
                    targetScreenPoint += (Vector3)LeanGesture.GetScreenDelta(fingers);
                }
                // Unset if no fingers are down
                else
                {
                    targetSet = false;
                }
            }
        }
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0 && onDelta != null)
            {
                var finalDelta = (Quaternion.Euler(0.0f, 0.0f, Angle) * LeanGesture.GetScreenDelta(fingers)).y;

                switch (Coordinate)
                {
                case CoordinateType.ScaledPixels:     finalDelta *= LeanTouch.ScalingFactor; break;

                case CoordinateType.ScreenPercentage: finalDelta *= LeanTouch.ScreenFactor;  break;
                }

                if (OneWay == true && finalDelta < 0.0f)
                {
                    finalDelta = 0.0f;
                }

                finalDelta *= Multiplier;

                onDelta.Invoke(finalDelta);
            }
        }
        protected virtual void Update()
        {
            if (Selectable.IsSelected == true)
            {
                // Make sure the camera exists
                var camera = LeanTouch.GetCamera(Camera, gameObject);

                if (camera != null)
                {
                    if (cachedRigidbody == null)
                    {
                        cachedRigidbody = GetComponent <Rigidbody>();
                    }

                    // Screen position of the transform
                    var screenPosition = camera.WorldToScreenPoint(transform.position);

                    // Add the deltaPosition
                    screenPosition += (Vector3)LeanGesture.GetScreenDelta();

                    // Convert back to world space
                    transform.position = camera.ScreenToWorldPoint(screenPosition);

                    // Reset velocity
                    cachedRigidbody.velocity = Vector3.zero;
                }
            }
        }
Beispiel #8
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel translation
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount, RequiredSelectable);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Perform the translation
            Translate(screenDelta);

            Debug.Log(collided);

            if (!collided)
            {
                positions.Add(transform.position);
            }
            else
            {
                transform.position = new Vector3(0, 3.8f, 1);
                //GameObject.Find("LeanSelect").GetComponent<LeanSelect>().DeselectAll();
            }
        }
Beispiel #9
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                // Get delta
                var delta = LeanGesture.GetScreenDelta(fingers);

                // Ignore?
                if (delta.sqrMagnitude == 0.0f)
                {
                    return;
                }

                // Scale?
                if (DeltaCoordinates == DeltaCoordinatesType.Scaled)
                {
                    delta *= LeanTouch.ScalingFactor;
                }

                // Call events
                if (OnSetCenter != null)
                {
                    OnSetCenter.Invoke(LeanGesture.GetScreenCenter(fingers));
                }

                if (OnSetDelta != null)
                {
                    OnSetDelta.Invoke(delta);
                }
            }
        }
Beispiel #10
0
 public void OnGesture(List <LeanFinger> fingers)
 {
     Debug.Log("Gesture with " + fingers.Count + " finger(s)");
     Debug.Log("    pinch scale: " + LeanGesture.GetPinchScale(fingers));
     Debug.Log("    twist degrees: " + LeanGesture.GetTwistDegrees(fingers));
     Debug.Log("    twist radians: " + LeanGesture.GetTwistRadians(fingers));
     Debug.Log("    screen delta: " + LeanGesture.GetScreenDelta(fingers));
 }
Beispiel #11
0
        protected virtual void Update()
        {
            // Store
            var oldPosition = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // Perform the translation
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }

            // Increment
            remainingTranslation += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

            /*
             * // Motion along XYX - Code
             * // Shift this transform by the change in delta
             *          transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation;
             */

            ////
            //// Motion along XZ - Code
            Vector3 changeInDelta = remainingTranslation - newRemainingTranslation;

            changeInDelta.z = 1 * changeInDelta.y;
            changeInDelta.y = 0;

            transform.localPosition = oldPosition + changeInDelta;
            ////

            if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f)
            {
                newRemainingTranslation = Vector3.Lerp(newRemainingTranslation, remainingTranslation, Inertia);
            }

            // Update remainingDelta with the dampened value
            remainingTranslation = newRemainingTranslation;
        }
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Perform the translation
            Translate(screenDelta);
        }
Beispiel #13
0
        private void UpdateTranslation()
        {
            var finalTransform = Target != null ? Target : transform;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(ScreenDepth.Camera, gameObject);

            if (fingers.Count == 0)
            {
                deltaDifference = Vector2.zero;
            }

            if (camera != null)
            {
                if (TrackScreenPosition == true)
                {
                    var oldScreenPoint = camera.WorldToScreenPoint(finalTransform.position);
                    var worldPosition  = finalTransform.position;

                    if (ScreenDepth.TryConvert(ref worldPosition, oldScreenPoint + (Vector3)(screenDelta + deltaDifference), gameObject) == true)
                    {
                        finalTransform.position = worldPosition;
                    }

                    var newScreenPoint = camera.WorldToScreenPoint(finalTransform.position);
                    var oldNewDelta    = (Vector2)(newScreenPoint - oldScreenPoint);

                    deltaDifference += screenDelta - oldNewDelta;
                }
                else
                {
                    var oldScreenPoint = camera.WorldToScreenPoint(finalTransform.position);
                    var worldPosition  = finalTransform.position;

                    if (ScreenDepth.TryConvert(ref worldPosition, oldScreenPoint + (Vector3)screenDelta, gameObject) == true)
                    {
                        finalTransform.position = worldPosition;
                    }
                }
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }
Beispiel #14
0
        protected virtual void Update()
        {
            // Store
            var oldPosition = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // Perform the translation
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }

            // Increment
            remainingTranslation += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

            // Shift this transform by the change in delta
            Vector3 newPosition = oldPosition + remainingTranslation - newRemainingTranslation;

            transform.localPosition = newPosition;

            if (Vector3.Distance(oldPosition, newPosition) > 0)
            {
                OnDrag?.Invoke(oldPosition - newPosition);
            }

            if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f)
            {
                newRemainingTranslation = Vector3.Lerp(newRemainingTranslation, remainingTranslation, Inertia);
            }

            // Update remainingDelta with the dampened value
            remainingTranslation = newRemainingTranslation;
        }
        protected virtual void Update()
        {
            if (Selectable.IsSelected == true)
            {
                // Screen position of the transform
                var screenPosition = Camera.main.WorldToScreenPoint(transform.position);

                // Add the deltaPosition
                screenPosition += (Vector3)LeanGesture.GetScreenDelta();

                // Convert back to world space
                transform.position = Camera.main.ScreenToWorldPoint(screenPosition);
            }
        }
Beispiel #16
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(ScreenDepth.Camera, gameObject);

            if (fingers.Count == 0)
            {
                deltaDifference = Vector2.zero;
            }

            if (camera != null)
            {
                if (TrackScreenPosition == true)
                {
                    var oldScreenPoint = camera.WorldToScreenPoint(transform.position);
                    var worldPosition  = default(Vector3);

                    if (ScreenDepth.TryConvert(ref worldPosition, oldScreenPoint + (Vector3)(screenDelta + deltaDifference), gameObject) == true)
                    {
                        transform.position = worldPosition;
                    }

                    var newScreenPoint = camera.WorldToScreenPoint(transform.position);
                    var oldNewDelta    = (Vector2)(newScreenPoint - oldScreenPoint);

                    deltaDifference += screenDelta - oldNewDelta;
                }
                else
                {
                    var oldScreenPoint = camera.WorldToScreenPoint(transform.position);
                    var worldPosition  = default(Vector3);

                    if (ScreenDepth.TryConvert(ref worldPosition, oldScreenPoint + (Vector3)screenDelta, gameObject) == true)
                    {
                        transform.position = worldPosition;
                    }
                }
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }
Beispiel #17
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel translation
            if ((RequiredSelectable != null && RequiredSelectable.IsSelected == false))
            {
                return;
            }
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Perform the translation
            Translate(screenDelta);
        }
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            // Perform the translation
            if (transform is RectTransform)
            {
                TranslateUI(screenDelta);
            }
            else
            {
                Translate(screenDelta);
            }
        }
Beispiel #19
0
        protected virtual void Update()
        {
            // pega os dedos que queremos usar
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // calcular o valor screenDelta com base nesses dedos
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // realiza a movimentacao
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }
        }
Beispiel #20
0
        protected virtual void Update()
        {
            // Store
            var oldPosition = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // Perform the translation
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }

            // Increment
            remainingTranslation  += transform.localPosition - oldPosition;
            remainingTranslation.y = 0;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

            // Shift this transform by the change in delta
            transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation;

            // Update remainingDelta with the dampened value
            remainingTranslation = newRemainingTranslation;
        }
        protected virtual void Update()
        {
            if (body == null)
            {
                body = GetComponent <Rigidbody>();
            }

            if (Selectable.IsSelected == true)
            {
                // Screen position of the transform
                var screenPosition = Camera.main.WorldToScreenPoint(transform.position);

                // Add the deltaPosition
                screenPosition += (Vector3)LeanGesture.GetScreenDelta();

                // Convert back to world space
                transform.position = Camera.main.ScreenToWorldPoint(screenPosition);

                // Reset velocity
                body.velocity = Vector3.zero;
            }
        }
        protected virtual void Update()
        {
            RectTransform workstationBorders = workstation.GetComponent <RectTransform>();
            Rect          rectWorkstation    = new Rect(getLeftWorldCorner(workstationBorders).x, getLeftWorldCorner(workstationBorders).y, 300, 600);
            Vector2       workstationCenter  = new Vector2(rectWorkstation.center.x, rectWorkstation.center.y);
            Rect          rectEmoji          = new Rect(-1810, -282, 600, 600);

            if (isDragging)
            {
                // Store
                var oldPosition = transform.localPosition;

                // Get the fingers we want to use
                var fingers = Use.GetFingers();

                // Calculate the screenDelta value based on these fingers
                var screenDelta = LeanGesture.GetScreenDelta(fingers);

                if (screenDelta != Vector2.zero)
                {
                    // Perform the translation
                    if (transform is RectTransform)
                    {
                        TranslateUI(screenDelta);
                    }
                    else
                    {
                        Translate(screenDelta);
                    }
                }

                // Increment
                remainingTranslation += transform.localPosition - oldPosition;

                // Get t value
                var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

                // Dampen remainingDelta
                var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

                // Shift this transform by the change in delta
                transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation;

                if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f)
                {
                    newRemainingTranslation = Vector3.Lerp(newRemainingTranslation, remainingTranslation, Inertia);
                }

                // Update remainingDelta with the dampened value
                remainingTranslation = newRemainingTranslation;
            }
            else if (rectOverlaps(rectWorkstation))
            {
                GetComponent <LeanPinchScale>().enabled  = true;
                GetComponent <LeanTwistRotate>().enabled = true;
                transform.position = workstationCenter;
                lastPos            = workstationCenter;
            }
            else if (rectOverlaps(rectEmoji) && lastPos == workstationCenter)
            {
                GetComponent <LeanPinchScale>().enabled  = false;
                GetComponent <LeanTwistRotate>().enabled = false;

                Debug.Log(lastPos);
            }
            else
            {
                GetComponent <LeanPinchScale>().enabled  = false;
                GetComponent <LeanTwistRotate>().enabled = false;
                transform.position   = inventoryPos;
                lastPos              = transform.position;
                transform.localScale = oldScale;
                transform.rotation   = oldRotation;
            }
        }
        protected virtual void Update()
        {
            GameObject obj = this.gameObject;

            if (obj == null)
            {
                Debug.Log(this.gameObject.name + " obj is null");
                return;
            }

            BlockController bc = obj.GetComponent <BlockController>();

            if (bc == null)
            {
                Debug.Log(this.gameObject.name + " bc is null");
                return;
            }

            if (bc.isSelect() == false)
            {
                Debug.Log(this.gameObject.name + " Image not selected");
                return;
            }

            // Store
            var oldPosition = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);

            if (screenDelta != Vector2.zero)
            {
                // Perform the translation
                if (transform is RectTransform)
                {
                    TranslateUI(screenDelta);
                }
                else
                {
                    Translate(screenDelta);
                }
            }

            // Increment
            remainingTranslation += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor);

            // Shift this transform by the change in delta
            transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation;

            // Update remainingDelta with the dampened value
            remainingTranslation = newRemainingTranslation;
        }