Ejemplo n.º 1
0
        private Component FindComponentUnder(NewLeanFinger finger)
        {
            var component = default(Component);

            switch (SelectUsing)
            {
            case SelectType.Raycast3D:
            {
                // Get ray for finger
                var ray = finger.GetRay();

                // Stores the raycast hit info
                var hit = default(RaycastHit);

                // Was this finger pressed down on a collider?
                if (Physics.Raycast(ray, out hit, float.PositiveInfinity, LayerMask) == true)
                {
                    component = hit.collider;
                }
            }
            break;

            case SelectType.Overlap2D:
            {
                // Find the position under the current finger
                var point = finger.GetWorldPosition(1.0f);

                // Find the collider at this position
                component = Physics2D.OverlapPoint(point, LayerMask);
            }
            break;
            }

            return(component);
        }
Ejemplo n.º 2
0
        public void Select(NewLeanFinger finger)
        {
            isSelected      = true;
            SelectingFinger = finger;

            OnSelect.Invoke(finger);
        }
Ejemplo n.º 3
0
        public void Select(NewLeanFinger finger, NewLeanSelectable selectable)
        {
            // Something was selected?
            if (selectable != null && selectable.isActiveAndEnabled == true)
            {
                if (CurrentSelectables == null)
                {
                    CurrentSelectables = new List <NewLeanSelectable>();
                }

                // Loop through all current selectables
                for (var i = CurrentSelectables.Count - 1; i >= 0; i--)
                {
                    var currentSelectable = CurrentSelectables[i];

                    if (currentSelectable != null)
                    {
                        // Already selected?
                        if (currentSelectable == selectable)
                        {
                            return;
                        }
                    }
                    else
                    {
                        CurrentSelectables.RemoveAt(i);
                    }
                }

                // Not selected yet, so select it
                CurrentSelectables.Add(selectable);

                selectable.Select(finger);
            }
        }
Ejemplo n.º 4
0
        private void OnFingerUp(NewLeanFinger finger)
        {
            // If the finger went up, it's no longer selecting anything
            if (finger == SelectingFinger)
            {
                OnSelectUp.Invoke(SelectingFinger);

                SelectingFinger = null;
            }
        }
Ejemplo n.º 5
0
        public void OnFingerDown(NewLeanFinger finger)
        {
            Vector2    position    = new Vector2(finger.ScreenPosition.x, finger.ScreenPosition.y);
            GameObject touchedMesh = finger.FlagObjectTouched(position, "PlanetMesh");

            if (touchedMesh != null)
            {
                TouchedElement = touchedMesh;
            }
        }
Ejemplo n.º 6
0
        public void Deselect()
        {
            if (SelectingFinger != null)
            {
                OnSelectUp.Invoke(SelectingFinger);

                SelectingFinger = null;
            }

            isSelected = false;

            OnDeselect.Invoke();
        }
Ejemplo n.º 7
0
        private void FingerUp(NewLeanFinger finger)
        {
            for (var i = CurrentSelectables.Count - 1; i >= 0; i--)
            {
                var currentSelectable = CurrentSelectables[i];

                if (currentSelectable != null)
                {
                    if (currentSelectable.SelectingFinger == finger || currentSelectable.SelectingFinger == null)
                    {
                        Deselect(currentSelectable);
                    }
                }
                else
                {
                    CurrentSelectables.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 8
0
        private void FingerSet(NewLeanFinger finger)
        {
            if (DeselectOnExit == true)
            {
                // Run through all selected objects
                for (var i = CurrentSelectables.Count - 1; i >= 0; i--)
                {
                    var currentSelectable = CurrentSelectables[i];

                    // Is it valid?
                    if (currentSelectable != null)
                    {
                        // Is this object associated with this finger?
                        if (currentSelectable.SelectingFinger == finger)
                        {
                            // Find the component under the finger
                            var component = FindComponentUnder(finger);

                            // Find the selectable associated with this component
                            var selectable = FindSelectableFrom(component);

                            // If the associated object is no longer under the finger, deselect it
                            if (selectable != currentSelectable)
                            {
                                Deselect(currentSelectable);
                            }
                        }
                        // Deselect in case the association was lost
                        else if (currentSelectable.SelectingFinger == null)
                        {
                            Deselect(currentSelectable);
                        }
                    }
                    // Remove invalid
                    else
                    {
                        CurrentSelectables.RemoveAt(i);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void FingerDown(NewLeanFinger finger)
        {
            // Ignore this finger?
            if (IgnoreGuiFingers == true && finger.StartedOverGui == true)
            {
                return;
            }

            // Find the component under the finger
            var component = FindComponentUnder(finger);

            // Find the selectable associated with this component
            var selectable = FindSelectableFrom(component);

            if (component != null)
            {
                TouchedElement = component.gameObject;
            }
            // Select the found selectable with the selecting finger
            Select(finger, selectable);
        }
Ejemplo n.º 10
0
        // Add a finger based on index, or return the existing one
        private void AddFinger(int index, Vector2 screenPosition)
        {
            var finger = FindFinger(index);

            // No finger found?
            if (finger == null)
            {
                var inactiveIndex = FindInactiveFingerIndex(index);

                // Use inactive finger?
                if (inactiveIndex >= 0)
                {
                    finger = InactiveFingers[inactiveIndex]; InactiveFingers.RemoveAt(inactiveIndex);

                    // Inactive for too long?
                    if (finger.Age > TapThreshold)
                    {
                        finger.TapCount = 0;
                    }

                    // Reset values
                    finger.Age     = 0.0f;
                    finger.Set     = false;
                    finger.LastSet = false;
                    finger.Tap     = false;
                    finger.Swipe   = false;
                }
                // Create new finger?
                else
                {
                    finger = new NewLeanFinger();

                    finger.Index = index;
                }

                finger.StartScreenPosition = screenPosition;
                finger.LastScreenPosition  = screenPosition;
                finger.ScreenPosition      = screenPosition;
                finger.StartedOverGui      = finger.IsOverGui;

                Fingers.Add(finger);
            }

            finger.Set            = true;
            finger.ScreenPosition = screenPosition;

            // Record?
            if (RecordFingers == true)
            {
                // Too many snapshots?
                if (RecordLimit > 0.0f)
                {
                    if (finger.SnapshotDuration > RecordLimit)
                    {
                        var removeCount = NewLeanSnapshot.GetLowerIndex(finger.Snapshots, finger.Age - RecordLimit);

                        finger.ClearSnapshots(removeCount);
                    }
                }

                // Record snapshot?
                if (RecordThreshold > 0.0f)
                {
                    if (finger.Snapshots.Count == 0 || finger.LastSnapshotScreenDelta.magnitude >= RecordThreshold)
                    {
                        finger.RecordSnapshot();
                    }
                }
                else
                {
                    finger.RecordSnapshot();
                }
            }
        }
Ejemplo n.º 11
0
 public void OnFingerUp(NewLeanFinger finger)
 {
     TouchedElement = null;
     Capi.set("Camera.Rotation.x", this.transform.rotation.x);
     Capi.set("Camera.Rotation.y", this.transform.parent.rotation.y);
 }