Ejemplo n.º 1
0
        // Awake is being called before Start; this makes sure we have a matrix
        // to begin with when we add the blocks
        void Awake()
        {
            // because of how we wrote the accessor this will also immediately
            // build the matrix of our level
            var grid = gameObject.GetComponent <RectGrid>();
            var para = gameObject.GetComponent <Parallelepiped>();

            SlidingPuzzle.InitializePuzzle(grid, para);
        }
Ejemplo n.º 2
0
        // visualizes the matrix in text form to let you see what's going on
        void OnGUI()
        {
            const int w = 100;
            const int h = 100;
            const int x = 10;

            var y = Screen.height - x - h;

            GUI.TextArea(new Rect(x, y, w, h), SlidingPuzzle.MatrixToString());
        }
Ejemplo n.º 3
0
        void OnMouseUp()
        {
            var position = transform.position;

            _beingDragged = false;
            /* transform.position = ClampPosition(position); */
            SlidingPuzzle._grid.AlignTransform(transform);
            lastSnap = position;
            SlidingPuzzle.RegisterObstacle(transform, false);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
 void Start()
 {
     _beingDragged = false;
     SlidingPuzzle.RegisterObstacle(transform, false);
 }