Beispiel #1
0
    private IEnumerator WaitForVoxeland(CoordDir center, int damage)
    {
        yield return(new WaitUntil(() => { return Voxeland != null && Voxeland.IsReady; }));

        Voxeland.brush.form   = Brush.Form.volume;
        Voxeland.brush.extent = damage / 20;
        Voxeland.Alter(center, Voxeland.brush, Voxeland.EditMode.dig, Voxeland.landTypes.selected,
                       Voxeland.objectsTypes.selected, Voxeland.grassTypes.selected);
    }
Beispiel #2
0
    public IEnumerator RemoveGrassToPosition(Vector3 position, float radius)
    {
        if (Terrain == null)
        {
            yield break;
        }

        CoordDir Dir = Terrain.PointOut(new Ray(position, Vector3.down * 2));

        Terrain.brush.form          = Brush.Form.blob;
        Terrain.brush.round         = false;
        Terrain.brush.extent        = Mathf.RoundToInt(radius / 2);
        Terrain.standardEditMode    = Voxeland.EditMode.dig;
        Terrain.grassTypes.selected = 1;

        Terrain.Alter(Dir, Terrain.brush, Voxeland.EditMode.dig,
                      landType: Terrain.landTypes.selected,
                      objectType: Terrain.objectsTypes.selected,
                      grassType: Terrain.grassTypes.selected);

        yield break;
    }
Beispiel #3
0
    private void DigVoxelRpc(Vector3 pos, Vector3 dir, int damage)
    {
        CoordDir center = Voxeland.PointOut(new Ray(pos, dir));

        StartCoroutine(WaitForVoxeland(center, damage));
    }
Beispiel #4
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }

            //showing help panel
            if (Input.GetKeyDown(KeyCode.F1))
            {
                helpPanel.SetActive(!helpPanel.activeSelf);
            }

            //selecting tool
            if (Input.GetKey("`"))
            {
                vertGrassInstrument.isOn = true;
            }
            if (Input.GetKey("1"))
            {
                brightCliffInstrument.isOn = true;
            }
            if (Input.GetKey("2"))
            {
                darkCliffInstrument.isOn = true;
            }
            if (Input.GetKey("3"))
            {
                grassInstrument.isOn = true;
            }
            if (Input.GetKey("4"))
            {
                yellowGrassInstrument.isOn = true;
            }
            if (Input.GetKey("5"))
            {
                pineInstrument.isOn = true;
            }
            if (Input.GetKey("6"))
            {
                torchInstrument.isOn = true;
            }

            if (vertGrassInstrument.isOn)
            {
                voxeland.grassTypes.selected = 0;         voxeland.landTypes.selected = -1;         voxeland.objectsTypes.selected = -1;
            }
            if (darkCliffInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;        voxeland.landTypes.selected = 0;          voxeland.objectsTypes.selected = -1;
            }
            if (brightCliffInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;      voxeland.landTypes.selected = 1;          voxeland.objectsTypes.selected = -1;
            }
            if (grassInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;    voxeland.landTypes.selected = 2;          voxeland.objectsTypes.selected = -1;
            }
            if (yellowGrassInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;      voxeland.landTypes.selected = 3;          voxeland.objectsTypes.selected = -1;
            }
            if (pineInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;     voxeland.landTypes.selected = -1;         voxeland.objectsTypes.selected = 0;
            }
            if (torchInstrument.isOn)
            {
                voxeland.grassTypes.selected = -1;    voxeland.landTypes.selected = -1;         voxeland.objectsTypes.selected = 1;
            }

            if (voxeland.landTypes.selected == -1)
            {
                instrumentWarning.SetActive(true);
            }
            else
            {
                instrumentWarning.SetActive(false);
            }


            //mouselook and gravity
            if (Input.GetKeyDown("g"))
            {
                useGravity.isOn = !useGravity.isOn;
            }
            if (Input.GetKeyDown("m"))
            {
                useMouselook.isOn = !useMouselook.isOn;
            }
            if (Input.GetKeyDown("f"))
            {
                SwitchFullscreen();
            }
            //if (Input.GetKeyDown(KeyCode.Escape)) { useMouselook.isOn = false; useFullscreen.isOn = false; }

            charController.gravity      = useGravity.isOn;
            cameraController.lockCursor = useMouselook.isOn;
            crosshair.SetActive(cameraController.lockCursor);

            //fullscreen - reverse order, setting toggle from current fullscreen state
            //useFullscreen.isOn = Screen.fullScreen;
            fullscreenCheckmark.SetActive(Screen.fullScreen);

            //displaing build progress
            float calculatedSum; float completeSum; float totalSum;

            ThreadWorker.GetProgresByTag("VoxelandChunk", out totalSum, out calculatedSum, out completeSum);
            buildProgress.maxValue = totalSum;
            buildProgress.value    = completeSum;

            //editing
            if (cameraController.lockCursor || !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())             //IsPointerOverGameObject returns true if mouse hidden
            {
                //reading controls
                bool leftMouse = Input.GetMouseButtonDown(0);
                //bool middleMouse = Input.GetMouseButtonDown(2);
                bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                //bool alt = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);  //not used
                bool control = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

                //getting edit mode
                Voxeland.EditMode editMode = Voxeland.EditMode.none;
                if (leftMouse && !shift && !control)
                {
                    editMode = Voxeland.EditMode.dig;
                }
                else if (leftMouse && control)
                {
                    editMode = Voxeland.EditMode.add;
                }
                else if (leftMouse && shift)
                {
                    editMode = Voxeland.EditMode.replace;
                }

                //getting aiming ray
                Ray aimRay;
                if (cameraController.lockCursor)
                {
                    aimRay = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.5f));
                }
                else
                {
                    aimRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                }

                //aiming terrain block
                CoordDir aimCoord = voxeland.PointOut(aimRay);

                //if any change
                if (prevAimCoord != aimCoord || editMode != Voxeland.EditMode.none)
                {
                    //highlight
                    if (voxeland.highlight != null)
                    {
                        if (aimCoord.exists)
                        {
                            voxeland.Highlight(aimCoord, voxeland.brush, isEditing: editMode != Voxeland.EditMode.none);
                        }
                        else
                        {
                            voxeland.highlight.Clear();                          //clearing highlight if nothing aimed or voxeland not selected
                        }
                    }

                    //altering
                    if (editMode != Voxeland.EditMode.none && aimCoord.exists)
                    {
                        voxeland.Alter(aimCoord, voxeland.brush, editMode,
                                       landType: voxeland.landTypes.selected,
                                       objectType: voxeland.objectsTypes.selected,
                                       grassType: voxeland.grassTypes.selected);
                    }

                    prevAimCoord = aimCoord;
                }                 //if coord or button change
            }
        }