/// <summary> /// Generates a foreground layer of objects at the start of each scenario iteration /// </summary> protected override void OnIterationStart() { var seed = SamplerState.NextRandomState(); var placementSamples = PoissonDiskSampling.GenerateSamples( placementArea.x, placementArea.y, separationDistance, seed); var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f; foreach (var sample in placementSamples) { var instance = m_GameObjectOneWayCache.GetOrInstantiate(prefabs.Sample()); instance.transform.position = new Vector3(sample.x, sample.y, depth) + offset; } placementSamples.Dispose(); }
void PlaceLayerTwoObjects() { if (m_LayerTwoSpawnedObjects == null) { m_LayerTwoSpawnedObjects = new List <GameObject>(); } var seed = scenario.GenerateRandomSeed(); var placementSamples = PoissonDiskSampling.GenerateSamples( layerTwoPlacementArea.x, layerTwoPlacementArea.y, layerTwoSeparationDistance.Sample(), seed); var offset = new Vector3(layerTwoPlacementArea.x, layerTwoPlacementArea.y, 0) * -0.5f; var parent = scenario.transform; foreach (var sample in placementSamples) { var instance = Object.Instantiate(layerTwoPrefabs.Sample(), parent); instance.transform.position = new Vector3(sample.x, sample.y, layerTwoDepth + layerTwoDepthDisplacement.Sample()) + offset; m_LayerTwoSpawnedObjects.Add(instance); } placementSamples.Dispose(); }
/// <summary> /// Generates a foreground layer of objects at the start of each scenario iteration /// </summary> protected override void OnIterationStart() { if (m_SpawnedObjects == null) { m_SpawnedObjects = new List <GameObject>(); } var seed = scenario.GenerateRandomSeed(); var placementSamples = PoissonDiskSampling.GenerateSamples( placementArea.x, placementArea.y, separationDistance.Sample(), seed); var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f; var parent = scenario.transform; foreach (var sample in placementSamples) { var instance = UnityEngine.Object.Instantiate(prefabs.Sample(), parent); instance.transform.position = new Vector3(sample.x, sample.y, depth) + offset; m_SpawnedObjects.Add(instance); } placementSamples.Dispose(); }
void PlaceObjects() { m_SpawnedCount = 0; var seed = SamplerState.NextRandomState(); var placementSamples = PoissonDiskSampling.GenerateSamples( placementArea.x, placementArea.y, separationDistance.Sample(), seed); var offset = new Vector3(placementArea.x, placementArea.y, 0) * -0.5f; foreach (var sample in placementSamples) { var instance = m_GameObjectOneWayCache.GetOrInstantiate(prefabs.Sample()); instance.transform.position = new Vector3(sample.x, sample.y, depth) + offset; m_SpawnedObjects.Add(instance); if (++m_SpawnedCount == maxObjectCount) { break; } } placementSamples.Dispose(); }