Beispiel #1
0
        // Transform rect based on finger data
        private void WriteTransform(RectTransform rect, LeanFinger finger)
        {
            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(Camera, gameObject);

            if (camera != null)
            {
                var min = camera.ScreenToViewportPoint(finger.StartScreenPosition);
                var max = camera.ScreenToViewportPoint(finger.ScreenPosition);

                // Fix any inverted values
                if (min.x > max.x)
                {
                    var t = min.x;

                    min.x = max.x;
                    max.x = t;
                }

                if (min.y > max.y)
                {
                    var t = min.y;

                    min.y = max.y;
                    max.y = t;
                }

                // Reset pivot in case you forgot
                rect.pivot = Vector2.zero;

                // Set anchors
                rect.anchorMin = min;
                rect.anchorMax = max;

                // Make rect we check against
                var viewportRect = new Rect();

                viewportRect.min = min;
                viewportRect.max = max;

                // Rebuild list of all selectables within rect
                selectables.Clear();

                for (var i = LeanSelectable.Instances.Count - 1; i >= 0; i--)
                {
                    var selectable    = LeanSelectable.Instances[i];
                    var viewportPoint = camera.WorldToViewportPoint(selectable.transform.position);

                    if (viewportRect.Contains(viewportPoint) == true)
                    {
                        selectables.Add(selectable);
                    }
                }

                // Select them
                LeanSelectable.ReplaceSelection(finger, selectables);
            }
        }
        // Transform rect based on finger data
        private void WriteTransform(RectTransform rect, LeanFinger finger)
        {
            // Make sure the camera exists
            var camera = LeanHelper.GetCamera(Camera, gameObject);

            if (camera != null)
            {
                var min = camera.ScreenToViewportPoint(finger.StartScreenPosition);
                var max = camera.ScreenToViewportPoint(finger.ScreenPosition);

                // Fix any inverted values
                if (min.x > max.x)
                {
                    var t = min.x;

                    min.x = max.x;
                    max.x = t;
                }

                if (min.y > max.y)
                {
                    var t = min.y;

                    min.y = max.y;
                    max.y = t;
                }

                // Reset pivot in case you forgot
                rect.pivot = Vector2.zero;

                // Set anchors
                rect.anchorMin = min;
                rect.anchorMax = max;

                // Make rect we check against
                var viewportRect = new Rect();

                viewportRect.min = min;
                viewportRect.max = max;

                // Rebuild list of all selectables within rect
                selectables.Clear();

                foreach (var selectable in LeanSelectable.Instances)
                {
                    var viewportPoint = camera.WorldToViewportPoint(selectable.transform.position);

                    if (viewportRect.Contains(viewportPoint) == true)
                    {
                        selectables.Add(selectable);
                    }
                }

                // Select them
                LeanSelectable.ReplaceSelection(finger, selectables);
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }