Esempio n. 1
0
    // Snapping dynamics:

    // snaps the height if necessary
    // @return: did a snap actually occur?
    bool SnapHeight(Transform t)
    {
        IntegerVector3 index = BlockArea.WorldSpaceToIndex(t.position);

        if (BlockArea.IsOccupied(index, cubePositions, t.rotation, id))
        {
            do
            {
                index.y++;
            } while (BlockArea.IsOccupied(index, cubePositions, t.rotation, id));

            t.SetPositionAndRotation(BlockArea.IndexToWorldSpace(index), t.rotation);

            return(true);
        }
        return(false);
    }
Esempio n. 2
0
    void Update()
    {
        if (grabbed)
        {
            shadow.transform.SetPositionAndRotation(transform.position, transform.rotation);
            Snap(shadow.transform);
        }
        else if (!planting)
        {
            transform.position += BlockManager.BlockFallingSpeed(transform.position.y) * Time.deltaTime * Vector3.down;

            //if (BlockArea.IsOccupied (BlockArea.WorldSpaceToIndex (transform.position), cubePositions, transform.rotation)) {
            //	Snap (transform);
            //	Lay ();
            //}
            if (Snap(transform))
            {
                Lay();
            }
        }
        if (planting)
        {
            IntegerVector3 underIndex = BlockArea.WorldSpaceToIndex(transform.position) + new IntegerVector3(0, -1, 0);

            if (!BlockArea.IsOccupied(underIndex, cubePositions, transform.rotation, id))
            {
                Unlay();
            }
        }

        // Debug

        /*cubeVFX.ApplyColor(Color.blue);
         * if (delayedUngrabbed) {
         *      cubeVFX.ApplyColor(Color.yellow);
         * }
         * if (grabbed) {
         *      cubeVFX.ApplyColor(Color.red);
         * }
         * if (planting) {
         *      cubeVFX.ApplyColor(Color.green);
         * }*/
    }