Ejemplo n.º 1
0
    public void CutBackward(Vector3 dir, bool resetNodulesOnZero)
    {
        if (AmountCut == 0)
        {
            return;
        }


        var objectsToActivate = new List <SetVoxelProperties>();

        for (var xi = 0; xi < _cubeSize; xi++)
        {
            for (var yi = 0; yi < _cubeSize; yi++)
            {
                for (var zi = 0; zi < _cubeSize; zi++)
                {
                    SetVoxelProperties beforeVoxel = null;
                    try
                    {
                        beforeVoxel = _vs.VoxelArray[xi + Mathf.RoundToInt(dir.x),
                                                     yi + Mathf.RoundToInt(dir.y),
                                                     zi + Mathf.RoundToInt(dir.z)];
                    }
                    catch
                    {
                        continue;
                    }

                    if (!beforeVoxel.Transparent)
                    {
                        objectsToActivate.Add(_vs.VoxelArray[xi, yi, zi]);
                    }
                }
            }
        }

        objectsToActivate.ForEach(
            obj =>
        {
            obj.transform.parent.GetComponent <Collider>().enabled = true;
            obj.Transparent = false;
            obj.Redraw();
        }
            );

        AmountCut -= 1;

        if (AmountCut == 0 && resetNodulesOnZero)
        {
            GetComponent <VoxelSpawner>()
            .Nodules.ForEach(n => { n.SetActive(true); });
        }
    }
Ejemplo n.º 2
0
    public void CutForward(Vector3 dir)
    {
        currentCutDir = dir;
        cubeSize      = vs.cubeSize;
        if (amountCut == ((int)cubeSize - 1))
        {
            return;
        }

        List <SetVoxelProperties> objectsToDeactivate = new List <SetVoxelProperties>();

        for (int xi = 0; xi < cubeSize; xi++)
        {
            for (int yi = 0; yi < cubeSize; yi++)
            {
                for (int zi = 0; zi < cubeSize; zi++)
                {
                    SetVoxelProperties beforeVoxel = null;
                    try
                    {
                        beforeVoxel = vs.voxelArray[xi - Mathf.RoundToInt(dir.x), yi - Mathf.RoundToInt(dir.y), zi - Mathf.RoundToInt(dir.z)];
                    }
                    catch
                    {
                        objectsToDeactivate.Add(vs.voxelArray[xi, yi, zi]);
                        continue;
                    }

                    if (beforeVoxel.transparent)
                    {
                        objectsToDeactivate.Add(vs.voxelArray[xi, yi, zi]);
                    }
                }
            }
        }
        objectsToDeactivate.ForEach((Obj) =>
        {
            Obj.transform.parent.GetComponent <Collider>().enabled = false;
            Obj.transparent = true;
            Obj.Redraw();
        });

        amountCut += 1;
    }