using UnityEngine; /// /// Feeds fish-triggered ripple rings to the AFX/Water shader's _RippleData /// array. A tiny fixed-size ring buffer of (worldX, worldZ, startTime, /// strength); the shader ages and fades each slot itself, so this side just /// records where and when a disturbance happened. /// [RequireComponent(typeof(Renderer))] public class WaterRippleManager : MonoBehaviour { public static WaterRippleManager Instance { get; private set; } const int Slots = 12; static readonly int RippleDataId = Shader.PropertyToID("_RippleData"); Vector4[] data = new Vector4[Slots]; int next; Material mat; bool dirty; void Awake() { Instance = this; mat = GetComponent().material; // instance, since we mutate it every frame } void OnDestroy() { if (Instance == this) Instance = null; } /// Start a ripple ring expanding outward from this world position (Y ignored). public void Emit(Vector3 worldPos, float strength = 1f) { data[next] = new Vector4(worldPos.x, worldPos.z, Time.time, strength); next = (next + 1) % Slots; dirty = true; } void Update() { if (!dirty) return; mat.SetVectorArray(RippleDataId, data); // Cheap to just push every changed frame; ripples are infrequent (a few per second at most). dirty = false; } }