示例#1
0
 private void Start()
 {
     Instance         = this;
     foundationObject = GameObject.Find("Foundation");
     blockOffset      = (Vector3.one * 1.0f) / 4;
     selectedColor    = BlockColor1.white;
     es = FindObjectOfType <EventSystem>();
 }
示例#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
                    };
                }
            }
        }
    }
示例#3
0
 public void ChangeBlockColor(int color)
 {
     selectedColor = (BlockColor1)color;
 }