private static void AddCubeGrid(Snapshot snapshot, int cubeCount) { // Calculate grid size var gridLength = (int)Math.Ceiling(Math.Sqrt(cubeCount)); if (gridLength % 2 == 1) // To make sure nothing is in (0, 0) { gridLength += 1; } var cubesToSpawn = cubeCount; for (var x = -gridLength + 1; x <= gridLength - 1; x += 2) { for (var z = -gridLength + 1; z <= gridLength - 1; z += 2) { // Leave the centre empty if (x == 0 && z == 0) { continue; } // Exit when we've hit our cube limit if (cubesToSpawn-- <= 0) { return; } var location = new Vector3(x, 1, z); var cubeTemplate = EntityTemplates.CreateCubeEntityTemplate(location); snapshot.AddEntity(cubeTemplate); } } }
private void SpawnCube(EntityId entityId) { var location = gameObject.transform.position - offset; location.y += 2; var cubeEntityTemplate = EntityTemplates.CreateCubeEntityTemplate(location); worldCommandRequestSender.SendCreateEntityCommand( new WorldCommands.CreateEntity.Request(cubeEntityTemplate, entityId), OnEntityCreated); }