public void DrawDebug() { if (WaterOnTerrainSFX.cellTexture == null) { WaterOnTerrainSFX.CreateDebugTextures(); } if (Camera.main != null) { Vector2 vector = new Vector2(110f, (float)(Camera.main.pixelHeight - 110)); Vector2 vector2 = vector - new Vector2(105f, 105f); GUI.Box(new Rect(vector2.x, vector2.y - 35f, 210f, 245f), "Water On Terrain"); GUI.Label(new Rect(vector2.x, vector2.y - 10f, 210f, 35f), string.Format("Wetness: {0:f2}", WaterOnTerrainSFX.Wetness)); float num = 10f * this.gridCellSize * Mathf.Sqrt(2f); float d = 100f / num; float num2 = 0f; float num3 = 0f; for (int i = 0; i < 21; i++) { for (int j = 0; j < 21; j++) { num2 = Mathf.Max(num2, this.ScoreForSource(new WaterOnTerrainSFX.IntVector(i, j), null)); num3 = Mathf.Max(num3, this.sampleGrid[i, j].gradient); } } float num4 = (num2 <= 0f) ? 0f : (1f / num2); float num5 = (num3 <= 0f) ? 0f : (1f / num3); Matrix4x4 matrix4x = Matrix4x4.TRS(vector, Quaternion.Euler(0f, 0f, -LocalPlayer.Transform.eulerAngles.y), new Vector3(1f, -1f, 1f) * d); matrix4x *= Matrix4x4.TRS(new Vector3(-LocalPlayer.Transform.position.x, -LocalPlayer.Transform.position.z, 0f), Quaternion.identity, Vector3.one); Matrix4x4 matrix = GUI.matrix; Color color = GUI.color; GUI.matrix *= matrix4x; for (int k = 0; k < 21; k++) { for (int l = 0; l < 21; l++) { WaterOnTerrainSFX.IntVector intVector = new WaterOnTerrainSFX.IntVector(k, l); GUI.color = new Color(0f, this.sampleGrid[k, l].gradient * num5, this.ScoreForSource(intVector, null) * num4, 0.5f); GUI.DrawTexture(this.GridCellRect(this.SampleGridToWorldGrid(intVector)), WaterOnTerrainSFX.cellTexture); } } GUI.matrix = matrix; GUI.color = color; if (this.centreSource.IsPlaying()) { this.DrawSource(this.centreSource, matrix4x); } for (int m = 0; m < this.sources.Count; m++) { this.DrawSource(this.sources[m], matrix4x); } } }
private float ScoreForSource(WaterOnTerrainSFX.IntVector position, WaterOnTerrainSFX.Source source) { float num = 0f; if (WaterOnTerrainSFX.IsWithinSampleGrid(position)) { num = this.sampleGrid[position.x, position.y].score; for (int i = 0; i < this.sources.Count; i++) { if (this.sources[i] != source) { float t = (float)((position - this.sources[i].localPosition).squareMagnitude / 5); num *= Mathf.Lerp(0.1f, 1f, t); } } } return(num); }
private void UpdateSampleGrid() { WaterOnTerrainSFX.IntVector intVector = new WaterOnTerrainSFX.IntVector(Mathf.FloorToInt(base.transform.position.x / this.gridCellSize), Mathf.FloorToInt(base.transform.position.z / this.gridCellSize)); if (intVector != this.gridPosition) { WaterOnTerrainSFX.IntVector intVector2 = intVector - this.gridPosition; if (Math.Abs(intVector2.x) < 21 && Math.Abs(intVector2.y) < 21) { this.MoveSampleGridEntries(-intVector2); WaterOnTerrainSFX.IntVector intVector3; WaterOnTerrainSFX.IntVector intVector4; if (intVector2.x < 0) { intVector3.x = 0; intVector4.x = -intVector2.x; } else { intVector3.x = 21 - intVector2.x; intVector4.x = 21; } if (intVector2.y < 0) { intVector3.y = 0; intVector4.y = -intVector2.y; } else { intVector3.y = 21 - intVector2.y; intVector4.y = 21; } this.CacheGradients(intVector, new WaterOnTerrainSFX.IntVector(0, intVector3.y), new WaterOnTerrainSFX.IntVector(21, intVector4.y)); if (intVector3.y > 0) { this.CacheGradients(intVector, new WaterOnTerrainSFX.IntVector(intVector3.x, 0), new WaterOnTerrainSFX.IntVector(intVector4.x, intVector3.y)); } else { this.CacheGradients(intVector, new WaterOnTerrainSFX.IntVector(intVector3.x, intVector4.y), new WaterOnTerrainSFX.IntVector(intVector4.x, 21)); } } else { this.CacheGradients(intVector, new WaterOnTerrainSFX.IntVector(0, 0), new WaterOnTerrainSFX.IntVector(21, 21)); } this.CalculateSampleGridScores(); int i = 0; while (i < this.sources.Count) { WaterOnTerrainSFX.Source source = this.sources[i]; this.sources[i].localPosition -= intVector2; int squareMagnitude = (source.localPosition - WaterOnTerrainSFX.SAMPLE_GRID_CENTRE).squareMagnitude; if (!WaterOnTerrainSFX.IsWithinSampleGrid(source.localPosition) || squareMagnitude > 100) { this.StopSource(i); } else { i++; } } this.gridPosition = intVector; } }