예제 #1
0
    public void undo()
    {
        if (previewAction.delete)
        {
            GameObject go = CreateBlock();

            blocks[(int)previewAction.index.x, (int)previewAction.index.y, (int)previewAction.index.z] = new Block1
            {
                blockTransform = go.transform,
                color          = selectedColor
            };

            PositionBlock(go.transform, previewAction.index);

            previewAction = new BlockAction1
            {
                delete = false,
                index  = previewAction.index,
                color  = previewAction.color
            };
        }
        else
        {
            Destroy(blocks[(int)previewAction.index.x, (int)previewAction.index.y, (int)previewAction.index.z].blockTransform.gameObject);
            blocks[(int)previewAction.index.x, (int)previewAction.index.y, (int)previewAction.index.z] = null;

            previewAction = new BlockAction1
            {
                delete = true,
                index  = previewAction.index,
                color  = previewAction.color
            };
        }
    }
예제 #2
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (es.IsPointerOverGameObject())// detect whether the player is clicking/touching a GUI button that happens to be over the game object
            {
                return;
            }

            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 30.0f))
            {
                /* if (hit.transform.gameObject != foundationObject)
                 * {
                 *   Vector3 blockPostion = hit.transform.position;
                 *   BlockCollision c = 0;
                 *
                 *   if (hit.point.x - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Right;
                 *   else if (hit.point.x - blockPostion.x == -0.5f)
                 *       c |= BlockCollision.Left;
                 *   else if (hit.point.z - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Forward;
                 *   else if (hit.point.z - blockPostion.x == -0.5f)
                 *       c |= BlockCollision.Backward;
                 *   else if (hit.point.y - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Up;
                 *   else c |= BlockCollision.Down;
                 * }*/

                //go.transform.position = hit.point;


                if (isDeleting)
                {
                    if (hit.transform.name != "Foundation")
                    {
                        Vector3     oldCubeIndex  = BlockPosition(hit.point - (hit.normal * blocksize));
                        BlockColor1 previousColor = blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z].color;
                        Destroy(blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z].blockTransform.gameObject);
                        blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z] = null;

                        previewAction = new BlockAction1
                        {
                            delete = true,
                            index  = oldCubeIndex,
                            color  = previousColor
                        };
                    }

                    return;
                }
                Vector3 index = BlockPosition(hit.point);

                int x = (int)index.x
                , y   = (int)index.y
                , z   = (int)index.z;

                if (blocks[x, y, z] == null)
                {
                    GameObject go = CreateBlock();

                    PositionBlock(go.transform, index);
                    blocks[x, y, z] = new Block1
                    {
                        blockTransform = go.transform,
                        color          = selectedColor
                    };

                    previewAction = new BlockAction1
                    {
                        delete = false,
                        index  = new Vector3(x, y, z),
                        color  = selectedColor
                    };
                }
                else
                {
                    //Debug.Log("Eroor: clicking inside of a cube at position" + index.ToString());
                    GameObject go = CreateBlock();

                    Vector3 newIndex = BlockPosition(hit.point + (hit.normal) * blocksize);

                    blocks[(int)newIndex.x, (int)newIndex.y, (int)newIndex.z] = new Block1
                    {
                        blockTransform = go.transform,
                        color          = selectedColor
                    };

                    PositionBlock(go.transform, newIndex);

                    previewAction = new BlockAction1
                    {
                        delete = false,
                        index  = newIndex,
                        color  = selectedColor
                    };
                }
            }
        }
    }