private void Spawn( SpawnPopulation population, SpawnDistribution distribution, int targetCount, int numToFill, int numToTry) { if (targetCount == 0) { return; } if (!population.Initialize()) { Debug.LogError((object)("[Spawn] No prefabs to spawn in " + population.ResourceFolder), (Object)population); } else { if (Global.developer > 1) { Debug.Log((object)("[Spawn] Population " + population.ResourceFolder + " needs to spawn " + (object)numToFill)); } float num1 = Mathf.Max((float)population.ClusterSizeMax, distribution.GetGridCellArea() * population.GetMaximumSpawnDensity()); population.UpdateWeights(distribution, targetCount); while (numToFill >= population.ClusterSizeMin && numToTry > 0) { ByteQuadtree.Element node = distribution.SampleNode(); int num2 = Random.Range(population.ClusterSizeMin, population.ClusterSizeMax + 1); int num3 = Mathx.Min(numToTry, numToFill, num2); for (int index = 0; index < num3; ++index) { Vector3 spawnPos; Quaternion spawnRot; if (distribution.Sample(out spawnPos, out spawnRot, node, population.AlignToNormal, (float)population.ClusterDithering) && (double)population.Filter.GetFactor(spawnPos) > 0.0 && (double)distribution.GetCount(spawnPos) < (double)num1) { this.Spawn(population, spawnPos, spawnRot); --numToFill; } --numToTry; } } } }
public bool Sample(out Vector3 spawnPos, out Quaternion spawnRot, ByteQuadtree.Element node, bool alignToNormal = false, float dithering = 0f) { RaycastHit raycastHit; if (this.Handler == null || TerrainMeta.HeightMap == null) { spawnPos = Vector3.zero; spawnRot = Quaternion.identity; return(false); } LayerMask placementMask = this.Handler.PlacementMask; LayerMask placementCheckMask = this.Handler.PlacementCheckMask; float placementCheckHeight = this.Handler.PlacementCheckHeight; LayerMask radiusCheckMask = this.Handler.RadiusCheckMask; float radiusCheckDistance = this.Handler.RadiusCheckDistance; for (int i = 0; i < 15; i++) { spawnPos = this.origin; ref float coords = ref spawnPos.x; coords = coords + node.Coords.x * this.area.x; ref float singlePointer = ref spawnPos.z;
public bool Sample( out Vector3 spawnPos, out Quaternion spawnRot, ByteQuadtree.Element node, bool alignToNormal = false, float dithering = 0.0f) { if (Object.op_Equality((Object)this.Handler, (Object)null) || Object.op_Equality((Object)TerrainMeta.HeightMap, (Object)null)) { spawnPos = Vector3.get_zero(); spawnRot = Quaternion.get_identity(); return(false); } LayerMask placementMask = this.Handler.PlacementMask; LayerMask placementCheckMask = this.Handler.PlacementCheckMask; float placementCheckHeight = this.Handler.PlacementCheckHeight; LayerMask radiusCheckMask = this.Handler.RadiusCheckMask; float radiusCheckDistance = this.Handler.RadiusCheckDistance; for (int index = 0; index < 15; ++index) { spawnPos = this.origin; ref __Null local1 = ref spawnPos.x;
private void Spawn(SpawnPopulation population, SpawnDistribution distribution, int targetCount, int numToFill, int numToTry) { Vector3 vector3; Quaternion quaternion; if (targetCount == 0) { return; } if (!population.Initialize()) { UnityEngine.Debug.LogError(string.Concat("[Spawn] No prefabs to spawn in ", population.ResourceFolder), population); return; } if (Global.developer > 1) { UnityEngine.Debug.Log(string.Concat(new object[] { "[Spawn] Population ", population.ResourceFolder, " needs to spawn ", numToFill })); } float single = Mathf.Max((float)population.ClusterSizeMax, distribution.GetGridCellArea() * population.GetMaximumSpawnDensity()); population.UpdateWeights(distribution, targetCount); while (numToFill >= population.ClusterSizeMin && numToTry > 0) { ByteQuadtree.Element element = distribution.SampleNode(); int num = UnityEngine.Random.Range(population.ClusterSizeMin, population.ClusterSizeMax + 1); num = Mathx.Min(numToTry, numToFill, num); for (int i = 0; i < num; i++) { if (distribution.Sample(out vector3, out quaternion, element, population.AlignToNormal, (float)population.ClusterDithering) && population.Filter.GetFactor(vector3) > 0f && (float)distribution.GetCount(vector3) < single) { this.Spawn(population, vector3, quaternion); numToFill--; } numToTry--; } } }