Beispiel #1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            if (objectsPutThisClick.Count > 0)
            {
                for (int i = 0; i < objectsPutThisClick[0].Count; i++)
                {
                    Vector3 v = objectsPutThisClick[0][i];
                    chunkMap.blockGrid[(int)v.x, (int)v.y, (int)v.z] = new Block(0, 0, 0);
                }
                objectsPutThisClick.RemoveAt(0);
                ChunkRenderer.renderAll();
            }
            return;
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            if (rotation == 3)
            {
                rotation = 0;
            }
            else
            {
                rotation++;
            }
        }

        if (eventSys.IsPointerOverGameObject())
        {
            return;
        }

        ShowGuider();

        if (Input.GetMouseButtonDown(0))
        {
            if (objectsPutThisClick.Count >= 10)
            {
                objectsPutThisClick.RemoveAt(9);
            }

            objectsPutThisClick.Insert(0, new List <Vector3>());
        }

        if (Input.GetMouseButtonUp(0))
        {
            ChunkRenderer.renderAll();
        }

        if (Input.GetMouseButton(0))
        {
            Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit floorHit;
            float      camRayLength = 100f;
            if (Physics.Raycast(cameraRay, out floorHit, camRayLength, LayerMask.GetMask("Floor")))
            {
                Vector3 a    = floorHit.point;
                Vector3 orig = getLocationOfOriginalBlock(a);

                //Bugfix for dragging from UI to game.
                if (objectsPutThisClick == null || objectsPutThisClick.Count == 0)
                {
                    return;
                }

                //If clicked smoothedge
                if (blockIsInsideSmoothBounds(orig))
                {
                    if (chunkMap.blockGrid[(int)orig.x, (int)orig.y, (int)orig.z].shape == ObjectController.SMOOTHBORDER)
                    {
                        a    += Vector3.down;
                        orig += Vector3.down;
                    }
                }

                if (!objectsPutThisClick[0].Contains(new Vector3(orig.x, orig.y, orig.z)))
                {
                    a = getLocationOfNewBlock(a);

                    ObjectController oc = ObjectController.getInstance();

                    for (int i = 0; i < x; i++)
                    {
                        for (int j = 0; j < y; j++)
                        {
                            for (int k = 0; k < z; k++)
                            {
                                Vector3 b = new Vector3();

                                b.x = (int)(a.x) + i;
                                b.y = a.y + k;
                                b.z = (int)(a.z) + j;

                                if (oc.shape != ObjectController.SMOOTH)
                                {
                                    if (blockIsInsideBounds(b))
                                    {
                                        chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(oc.shape, oc.texture + 1, rotation);
                                        objectsPutThisClick[0].Add(new Vector3((int)b.x, (int)b.y, (int)b.z));
                                    }
                                }
                                else
                                {
                                    if (blockIsInsideSmoothBounds(b))
                                    {
                                        chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(oc.shape, oc.texture + 1, rotation);
                                        objectsPutThisClick[0].Add(new Vector3((int)b.x, (int)b.y, (int)b.z));
                                    }
                                }
                            }
                        }
                    }
                    if (objectsPutThisClick.Count != 0 && objectsPutThisClick[0].Count != 0)
                    {
                        ChunkRenderer.renderTemporarily(objectsPutThisClick[0]);
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Ray        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit floorHit;
            float      camRayLength = 200f;

            if (Physics.Raycast(cameraRay, out floorHit, camRayLength, LayerMask.GetMask("Floor")))
            {
                Vector3 a = floorHit.point;

                a = getLocationOfOriginalBlock(a);

                for (int i = 0; i < x; i++)
                {
                    for (int j = 0; j < y; j++)
                    {
                        for (int k = 0; k < z; k++)
                        {
                            Vector3 b = new Vector3();

                            b.x = (int)(a.x) + i;
                            b.y = a.y - k;
                            b.z = (int)(a.z) + j;

                            if (blockIsInsideBounds(b))
                            {
                                chunkMap.blockGrid[(int)b.x, (int)b.y, (int)b.z] = new Block(0, 0, 0);
                            }
                        }
                    }
                }
                ChunkRenderer.renderAll();
            }
        }
    }