// Actual initialization code. Can be called multiple times, and the initialization is propagated down public void Generate(int width, int height) { water = gameObject.GetComponent<Water>(); water.Generate(width, height); inputForceType = SquareForce; }
// Adds a force onto a given range. The specified mapper customizes how the force is propagated public float AddForce(int centerX, int centerY, float force, int range, ForceMapper mapper) { int halfRange = (range + 1) / 2; // Bounds for force area to be applied int left = Mathf.Max(centerX - halfRange, 0), right = Mathf.Min(centerX + halfRange, water.Width), top = Mathf.Max(centerY - halfRange, 0), bottom = Mathf.Min(centerY + halfRange, water.Height); float upthrust = 0; for (int x = left; x < right; x++) for (int y = top; y < bottom; y++) upthrust += water.AddForce(x, y, mapper(x, y, force, range, centerX, centerY)); return upthrust; }