Пример #1
0
    public void InitCubes(float scale, float density)
    {
        MeshRenderer structureMesh = parent.Component<MeshRenderer>();
        Vector3 extents = structureMesh.bounds.extents;
        Vector3 offset = new Vector3(-2f * extents.x, 0f, -2f * extents.z);
        Vector3 grid = new Vector3(4 * extents.x, 2 * extents.y, 4 * extents.z) / scale;

        for (int i = 0; i < grid.x; i++)
        {
            for (int j = 0; j < grid.y; j++)
            {
                for (int k = 0; k < grid.z; k++)
                {
                    if (Random.value < density)
                    {
                        Vector3 position = parent.Position() + offset + scale * new Vector3(i, j, k);
                        Vector3 size = scale * Vector3.one;
                        if (structureMesh.bounds.Contains(position))
                            continue;
                        Cubeform cube = new Cubeform(position, size);
                        cubes.Add(cube);
                        AddChild(cube);
                    }
                }
            }
        }
    }
Пример #2
0
 public void ShuffleCube(Cubeform cube)
 {
     var position = cube.LocalPosition();
     var steps = Random.Range(-3, 3) * 100f;
     var roll = Random.value;
     var direction = roll < 0.33f ? Vector3.forward
         : roll < 0.66f ? Vector3.up
         : Vector3.right;
     var offset = steps * direction;
     var destination = cube.destination;
     var shufflePos = destination + offset;
     cube.destination = shufflePos;
 }