// Token: 0x06000C9A RID: 3226 RVA: 0x00059E6C File Offset: 0x0005806C private void GeneratePatch(Vector3 camPos, Vector2Int p, ref bool generated, bool rebuildAll) { if (Utils.DistanceXZ(this.GetVegPatchCenter(p), camPos) > this.m_distance) { return; } ClutterSystem.PatchData patchData; if (this.m_patches.TryGetValue(p, out patchData) && !patchData.m_reset) { patchData.m_timer = 0f; return; } if (rebuildAll || !generated || this.m_menuHack) { ClutterSystem.PatchData patchData2 = this.GenerateVegPatch(p, this.m_grassPatchSize); if (patchData2 != null) { ClutterSystem.PatchData patchData3; if (this.m_patches.TryGetValue(p, out patchData3)) { foreach (GameObject obj in patchData3.m_objects) { UnityEngine.Object.Destroy(obj); } this.FreePatch(patchData3); this.m_patches.Remove(p); } this.m_patches.Add(p, patchData2); generated = true; } } }
// Token: 0x06000CA2 RID: 3234 RVA: 0x0005A756 File Offset: 0x00058956 private void FreePatch(ClutterSystem.PatchData patch) { patch.center = Vector3.zero; patch.m_objects.Clear(); patch.m_timer = 0f; patch.m_reset = false; this.m_freePatches.Push(patch); }
// Token: 0x06000CA0 RID: 3232 RVA: 0x0005A324 File Offset: 0x00058524 private ClutterSystem.PatchData GenerateVegPatch(Vector2Int patchID, float size) { Vector3 vegPatchCenter = this.GetVegPatchCenter(patchID); float num = size / 2f; Heightmap.Biome patchBiomes = this.GetPatchBiomes(vegPatchCenter, num); if (patchBiomes == Heightmap.Biome.None) { return(null); } float realtimeSinceStartup = Time.realtimeSinceStartup; UnityEngine.Random.State state = UnityEngine.Random.state; ClutterSystem.PatchData patchData = this.AllocatePatch(); patchData.center = vegPatchCenter; for (int i = 0; i < this.m_clutter.Count; i++) { ClutterSystem.Clutter clutter = this.m_clutter[i]; if (clutter.m_enabled && (patchBiomes & clutter.m_biome) != Heightmap.Biome.None) { InstanceRenderer instanceRenderer = null; UnityEngine.Random.InitState(patchID.x * (patchID.y * 1374) + i * 9321); Vector3 b = new Vector3(clutter.m_fractalOffset, 0f, 0f); float num2 = Mathf.Cos(0.017453292f * clutter.m_maxTilt); int num3 = (this.m_quality == ClutterSystem.Quality.High) ? clutter.m_amount : (clutter.m_amount / 2); num3 = (int)((float)num3 * this.m_amountScale); int j = 0; while (j < num3) { Vector3 vector = new Vector3(UnityEngine.Random.Range(vegPatchCenter.x - num, vegPatchCenter.x + num), 0f, UnityEngine.Random.Range(vegPatchCenter.z - num, vegPatchCenter.z + num)); float num4 = (float)UnityEngine.Random.Range(0, 360); if (!clutter.m_inForest) { goto IL_161; } float forestFactor = WorldGenerator.GetForestFactor(vector); if (forestFactor >= clutter.m_forestTresholdMin && forestFactor <= clutter.m_forestTresholdMax) { goto IL_161; } IL_3D5: j++; continue; IL_161: if (clutter.m_fractalScale > 0f) { float num5 = Utils.Fbm(vector * 0.01f * clutter.m_fractalScale + b, 3, 1.6f, 0.7f); if (num5 < clutter.m_fractalTresholdMin || num5 > clutter.m_fractalTresholdMax) { goto IL_3D5; } } Vector3 vector2; Vector3 vector3; Heightmap heightmap; Heightmap.Biome biome; if (!this.GetGroundInfo(vector, out vector2, out vector3, out heightmap, out biome) || (clutter.m_biome & biome) == Heightmap.Biome.None) { goto IL_3D5; } float num6 = vector2.y - this.m_waterLevel; if (num6 < clutter.m_minAlt || num6 > clutter.m_maxAlt || vector3.y < num2) { goto IL_3D5; } if (clutter.m_minOceanDepth != clutter.m_maxOceanDepth) { float oceanDepth = heightmap.GetOceanDepth(vector); if (oceanDepth < clutter.m_minOceanDepth || oceanDepth > clutter.m_maxOceanDepth) { goto IL_3D5; } } if (!clutter.m_onCleared || !clutter.m_onUncleared) { bool flag = heightmap.IsCleared(vector2); if ((clutter.m_onCleared && !flag) || (clutter.m_onUncleared && flag)) { goto IL_3D5; } } vector = vector2; if (clutter.m_snapToWater) { vector.y = this.m_waterLevel; } if (clutter.m_randomOffset != 0f) { vector.y += UnityEngine.Random.Range(-clutter.m_randomOffset, clutter.m_randomOffset); } Quaternion quaternion = Quaternion.identity; if (clutter.m_terrainTilt) { quaternion = Quaternion.AngleAxis(num4, vector3); } else { quaternion = Quaternion.Euler(0f, num4, 0f); } if (clutter.m_instanced) { if (instanceRenderer == null) { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(clutter.m_prefab, vegPatchCenter, Quaternion.identity, this.m_grassRoot.transform); instanceRenderer = gameObject.GetComponent <InstanceRenderer>(); if (instanceRenderer.m_lodMaxDistance > this.m_distance - this.m_grassPatchSize / 2f) { instanceRenderer.m_lodMaxDistance = this.m_distance - this.m_grassPatchSize / 2f; } patchData.m_objects.Add(gameObject); } float scale = UnityEngine.Random.Range(clutter.m_scaleMin, clutter.m_scaleMax); instanceRenderer.AddInstance(vector, quaternion, scale); goto IL_3D5; } GameObject item = UnityEngine.Object.Instantiate <GameObject>(clutter.m_prefab, vector, quaternion, this.m_grassRoot.transform); patchData.m_objects.Add(item); goto IL_3D5; } } } UnityEngine.Random.state = state; return(patchData); }