예제 #1
0
        void OnMouseDown()
        {
            var touchPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var position   = transform.position;
            var scale      = transform.lossyScale;

            _beingDragged = true;
            touchOffset   = touchPoint - position;
            lastSnap      = position;
            _bounds       = SlidingPuzzle.CalculateSlidingBounds(position, scale);

            SlidingPuzzle.RegisterObstacle(transform, true);
        }
예제 #2
0
        /// <summary>
        ///   This is where the dragging logic takes places.
        /// </summary>
        private void Drag()
        {
            var input = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var scale = transform.lossyScale;

            var destination = ClampPosition(input - touchOffset);

            destination.z = transform.position.z;

            // Now use that information to get the new bounds.
            _bounds = SlidingPuzzle.CalculateSlidingBounds(lastSnap, scale);

            // Simulate a snap to the grid so we can get potentially new bounds
            // in the next step.
            lastSnap = ClampPosition(SlidingPuzzle._grid.AlignVector3(destination, scale));

            // Move to the destination!
            transform.position = destination;
        }