Esempio n. 1
0
        protected virtual void Start()
        {
            if (RequiredSelectable == null)
            {
                RequiredSelectable = GetComponent <LeanSelectable>();
            }

            //arController = UIController.GetComponent<SimpleARGUIController>();
        }
Esempio n. 2
0
        protected virtual void Start()
        {
            if (RequiredSelectable == null)
            {
                RequiredSelectable = GetComponent <LeanSelectable>();
            }

            _anchor = transform.position;
        }
Esempio n. 3
0
        /// <summary>This method returns a list of all fingers based on the current settings.</summary>
        public List <LeanFinger> GetFingers(bool ignoreUpFingers = false)
        {
            if (fingers == null)
            {
                fingers = new List <LeanFinger>();
            }

            switch (Filter)
            {
            case FilterType.AllFingers:
            {
                fingers.Clear();

                fingers.AddRange(LeanSelectable.GetFingers(IgnoreStartedOverGui, false, RequiredFingerCount, RequiredSelectable));
            }
            break;
            }

            if (ignoreUpFingers == true)
            {
                for (var i = fingers.Count - 1; i >= 0; i--)
                {
                    if (fingers[i].Up == true)
                    {
                        fingers.RemoveAt(i);
                    }
                }
            }

            if (RequiredMouseButtons != 0)
            {
                var keep = true;

                for (var i = 0; i < 5; i++)
                {
                    var mask = 1 << i;

                    if ((RequiredMouseButtons & mask) != 0 && LeanInput.GetMousePressed(i) == false)
                    {
                        keep = false; break;
                    }
                }

                if (keep == false)
                {
                    for (var i = fingers.Count - 1; i >= 0; i--)
                    {
                        if (fingers[i].Index < 0)
                        {
                            fingers.RemoveAt(i);
                        }
                    }
                }
            }

            return(fingers);
        }
        /// <summary>This method returns a list of all fingers based on the current settings.</summary>
        public List <LeanFinger> GetFingers(bool ignoreUpFingers = false)
        {
            if (fingers == null)
            {
                fingers = new List <LeanFinger>();
            }

            if (filteredFingers == null)
            {
                filteredFingers = new List <LeanFinger>();
            }

            filteredFingers.Clear();

            if (Filter == FilterType.AllFingers)
            {
                filteredFingers.AddRange(LeanSelectable.GetFingers(IgnoreStartedOverGui, false, 0, RequiredSelectable));
            }
            else
            {
                filteredFingers.AddRange(fingers);
            }

            if (ignoreUpFingers == true)
            {
                for (var i = filteredFingers.Count - 1; i >= 0; i--)
                {
                    if (filteredFingers[i].Up == true)
                    {
                        filteredFingers.RemoveAt(i);
                    }
                }
            }

            if (RequiredMouseButtons > 0 && SimulatedFingersExist(filteredFingers) == true)
            {
                for (var i = 0; i < 5; i++)
                {
                    var mask = 1 << i;

                    if ((RequiredMouseButtons & mask) != 0 && Lean.Common.LeanInput.GetMousePressed(i) == false)
                    {
                        filteredFingers.Clear();
                    }
                }

                return(filteredFingers);
            }

            if (RequiredFingerCount > 0 && filteredFingers.Count != RequiredFingerCount)
            {
                filteredFingers.Clear();
            }

            return(filteredFingers);
        }
        public LeanFingerFilter(FilterType newFilter, bool newIgnoreStartedOverGui, int newRequiredFingerCount, int newRequiredMouseButtons, LeanSelectable newRequiredSelectable)
        {
            Filter = newFilter;
            IgnoreStartedOverGui = newIgnoreStartedOverGui;
            RequiredFingerCount  = newRequiredFingerCount;
            RequiredSelectable   = newRequiredSelectable;
            RequiredMouseButtons = newRequiredMouseButtons;

            fingers = null;
        }
    public void Deselect_all()
    {
        var ls = new Lean.Touch.LeanSelectable();

        GameObject[] list = GameObject.FindGameObjectsWithTag("models");
        foreach (GameObject model in list)
        {
            model.GetComponent <Lean.Touch.LeanSelectable>().Deselect();
        }
    }
        protected virtual void OnEnable()
        {
            if (selectable == null)
            {
                selectable = GetComponent <LeanSelectable>();
            }

            // Hook LeanSelectable events
            selectable.OnSelect.AddListener(OnSelect);
            selectable.OnDeselect.AddListener(OnDeselect);
        }
        protected virtual void OnDisable()
        {
            if (selectable == null)
            {
                selectable = GetComponent <LeanSelectable>();
            }

            // Unhook LeanSelectable events
            selectable.OnSelect.RemoveListener(OnSelect);
            selectable.OnDeselect.RemoveListener(OnDeselect);
        }
Esempio n. 9
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingersOrClear(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate the rotation values based on these fingers
            var twistDegrees = LeanGesture.GetTwistDegrees(fingers);

            // Perform rotation
            transform.Rotate(Axis, twistDegrees, Space);
        }
        protected virtual void Update()
        {
            // pega os dedos que queremos usar
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calcula os valores de rotação baseados nesses dedos
            var twistDegrees = LeanGesture.GetTwistDegrees(fingers);

            // Realiza rotação
            transform.Rotate(Axis, twistDegrees, Space);
        }
        public void Unregister()
        {
            if (selectable != null)
            {
                selectable.OnSelect.RemoveListener(OnSelect);
                selectable.OnSelectUp.RemoveListener(OnSelectUp);
                selectable.OnDeselect.RemoveListener(OnDeselect);

                selectable = null;
            }
        }
Esempio n. 12
0
        public void RemoveSelectable(LeanSelectable selectable)
        {
            for (var i = CurrentSelectables.Count - 1; i >= 0; i--)
            {
                if (CurrentSelectables[i] == selectable)
                {
                    CurrentSelectables.RemoveAt(i);

                    return;
                }
            }
        }
Esempio n. 13
0
        protected virtual void Start()
        {
            if (RequiredSelectable == null)
            {
                RequiredSelectable = GetComponent <LeanSelectable>();
            }

            if (Camera == null)
            {
                Camera = GetComponent <Camera>();
            }
        }
Esempio n. 14
0
        public void Deselect()
        {
            // Is there a selected object?
            if (CurrentSelectable != null)
            {
                // Deselect it
                CurrentSelectable.Deselect();

                // Mark it null
                CurrentSelectable = null;
            }
        }
        private void UpdateSelectable()
        {
            if (selectable == null)
            {
                selectable = GetComponentInParent <LeanSelectable>();

                if (selectable == null)
                {
                    Debug.LogError("This GameObject or one of its parents must have the LeanSelectable component.", this);
                }
            }
        }
        protected virtual void Start()
        {
            if (RequiredSelectable == null)
            {
                RequiredSelectable = GetComponent <LeanSelectable>();
            }

            IgnoreIsOverGui      = true;
            IgnoreStartedOverGui = true;
            ScaleClamp           = true;
            ScaleMax             = new Vector3(10f, 10f, 10f);
        }
Esempio n. 17
0
        /// <summary>This method allows you to manually select an object with the specified finger using this component's selection settings.</summary>
        public void Select(LeanSelectable selectable, LeanFinger finger)
        {
            if (TrySelect(selectable) == true)
            {
                var selectableByFinger = selectable as LeanSelectableByFinger;

                if (selectableByFinger != null)
                {
                    if (selectableByFinger.SelectingFingers.Contains(finger) == false)
                    {
                        selectableByFinger.SelectingFingers.Add(finger);
                    }

                    selectableByFinger.OnSelectedFinger.Invoke(finger);

                    LeanSelectableByFinger.InvokeAnySelectedFinger(this, selectableByFinger, finger);

                    if (finger.Up == true)
                    {
                        selectableByFinger.OnSelectedFingerUp.Invoke(finger);

                        selectableByFinger.SelectingFingers.Remove(finger);
                    }
                }

                if (onSelectedFinger != null)
                {
                    onSelectedFinger.Invoke(selectable, finger);
                }

                if (OnAnySelectedFinger != null)
                {
                    OnAnySelectedFinger.Invoke(this, selectable, finger);
                }
            }
            else
            {
                if (finger.Up == false)
                {
                    var selectableByFinger = selectable as LeanSelectableByFinger;

                    if (selectableByFinger != null)
                    {
                        if (selectableByFinger.SelectingFingers.Contains(finger) == false)
                        {
                            selectableByFinger.SelectingFingers.Add(finger);
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        protected virtual void FixedUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var targetPoint = LeanGesture.GetScreenCenter(fingers);
                var newPosition = ScreenDepth.Convert(targetPoint, Camera, gameObject);
                var factor      = LeanTouch.GetDampenFactor(Dampening, Time.fixedDeltaTime);

                transform.position = Vector3.Lerp(transform.position, newPosition, factor);
            }
        }
Esempio n. 19
0
        public bool IsSelected(LeanSelectable selectable)
        {
            // Loop through all current selectables
            for (var i = CurrentSelectables.Count - 1; i >= 0; i--)
            {
                var currentSelectable = CurrentSelectables[i];

                if (currentSelectable == selectable)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 20
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                delta += LeanGesture.GetScaledDelta(fingers);
                scale *= LeanGesture.GetPinchRatio(fingers);
                twist += LeanGesture.GetTwistDegrees(fingers);

                if (state == StateType.None)
                {
                    if (DragComponent != null && delta.magnitude >= DragThreshold)
                    {
                        state = StateType.Drag;
                    }
                    else if (PinchComponent != null && Mathf.Abs(scale - 1.0f) >= PinchThreshold)
                    {
                        state = StateType.Pinch;
                    }
                    else if (TwistComponent != null && Mathf.Abs(twist) >= TwistThreshold)
                    {
                        state = StateType.Twist;
                    }
                }
            }
            else
            {
                state = StateType.None;
                delta = Vector2.zero;
                scale = 1.0f;
                twist = 0.0f;
            }

            if (DragComponent != null)
            {
                DragComponent.enabled = state == StateType.Drag || (EnableWithoutIsolation == true && state == StateType.None);
            }

            if (PinchComponent != null)
            {
                PinchComponent.enabled = state == StateType.Pinch || (EnableWithoutIsolation == true && state == StateType.None);
            }

            if (TwistComponent != null)
            {
                TwistComponent.enabled = state == StateType.Twist || (EnableWithoutIsolation == true && state == StateType.None) || (TwistWithPinch == true && state == StateType.Pinch);
            }
        }
Esempio n. 21
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);
            }
        }
Esempio n. 22
0
        protected virtual void Update()
        {
            // Get fingers and calculate how many are still touching the screen
            var fingers     = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);
            var fingerCount = GetFingerCount(fingers);

            // At least one finger set?
            if (fingerCount > 0)
            {
                // Did this just begin?
                if (lastFingerCount == 0)
                {
                    age = 0.0f;
                    HighestFingerCount = fingerCount;
                }
                else if (fingerCount > HighestFingerCount)
                {
                    HighestFingerCount = fingerCount;
                }
            }

            age += Time.unscaledDeltaTime;

            // Reset
            MultiTap = false;

            // Is a multi-tap still eligible?
            if (age <= LeanTouch.CurrentTapThreshold)
            {
                // All fingers released?
                if (fingerCount == 0 && lastFingerCount > 0)
                {
                    MultiTapCount += 1;

                    if (OnTap != null)
                    {
                        OnTap.Invoke(MultiTapCount, HighestFingerCount);
                    }
                }
            }
            // Reset
            else
            {
                MultiTapCount      = 0;
                HighestFingerCount = 0;
            }

            lastFingerCount = fingerCount;
        }
Esempio n. 23
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var screenPoint   = LeanGesture.GetScreenCenter(fingers);
                var worldPosition = default(Vector3);

                if (ScreenDepth.TryConvert(ref worldPosition, screenPoint, gameObject) == true)
                {
                    transform.position = worldPosition;
                }
            }
        }
Esempio n. 24
0
        protected virtual void Update()
        {
            if (Camera.main == null)
            {
                return;
            }

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

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);

            var newScale = transform.localScale * pinchScale;

            if (newScale.x < ScaleMin.x || newScale.x > ScaleMax.x)
            {
                return;
            }

            if (pinchScale > 0.0f)
            {
                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (!Physics.Raycast(Camera.main.ScreenPointToRay(pinchScreenCenter)))
                    {
                        return;
                    }

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // Perform the scaling
                Scale(transform.localScale * pinchScale);
            }
        }
Esempio n. 25
0
        public void Deselect(LeanFinger finger)
        {
            // Is there a selected object?
            if (CurrentSelectable != null)
            {
                // Does its finger match?
                // NOTE: This will usually only work with OnFingerDown selection, and OnFingerUp deselection
                if (CurrentSelectable.SelectingFinger == finger)
                {
                    // Deselect it
                    CurrentSelectable.Deselect();

                    // Mark it null
                    CurrentSelectable = null;
                }
            }
        }
Esempio n. 26
0
        private bool ShouldRemoveSelectable(LeanSelectable selectable)
        {
            var selectableByFinger = selectable as LeanSelectableByFinger;

            if (selectableByFinger != null)
            {
                foreach (var finger in selectableByFinger.SelectingFingers)
                {
                    if (finger.Up == false)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 27
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingersOrClear(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);


            if (pinchScale == 1)
            {
                Debug.Log("pinch = 1");
            }
            else
            {
                canResetTrail = false;
                if (!canResetTrail)
                {
                    canResetTrail = true;
                    StartCoroutine(enableAndReanbleTrails());
                }
            }

            if (pinchScale > 0.0f)
            {
                canResetTrail = false;
                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // Perform the scaling
                Scale(transform.localScale * pinchScale);
            }
        }
        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);
            }
        }
        /// <summary>This method allows you to manually register the LeanSelectable this component is associated with.</summary>
        public void Register(LeanSelectable newSelectable)
        {
            if (newSelectable != selectable)
            {
                // Unregister existing
                Unregister();

                // Register a new one?
                if (newSelectable != null)
                {
                    selectable = newSelectable;

                    selectable.OnSelect.AddListener(OnSelect);
                    selectable.OnSelectUp.AddListener(OnSelectUp);
                    selectable.OnDeselect.AddListener(OnDeselect);
                }
            }
        }
Esempio n. 30
0
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Get the pinch ratio of these fingers
            var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity);

            // Modify the zoom value
            Zoom *= pinchRatio;

            if (ZoomClamp == true)
            {
                Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax);
            }

            // Set the new zoom
            SetZoom(Zoom);
        }