using UnityEngine;

public class WaterColliderProxy : MonoBehaviour {

	public RippleSystem rippleSystem;
	public Vector2 waterDropletAudioVolumeRange;

	ParticleCollisionEvent[] collisionEvents = new ParticleCollisionEvent[16];

	void OnParticleCollision(GameObject other) {
		var part = other.GetComponent<ParticleSystem>();
		int safeLength = part.GetSafeCollisionEventSize();
		if (collisionEvents.Length < safeLength)
			collisionEvents = new ParticleCollisionEvent[safeLength];

		int numCollisionEvents = part.GetCollisionEvents(gameObject, collisionEvents);

		for(int i=0; i<numCollisionEvents; i++)
		{
			var collisionEvent = collisionEvents[i];
			rippleSystem.CreateDropAtPosition(collisionEvent.intersection, 0.00075f);
		}

		AudioManager.Instance.Play(AudioClips.Instance.WaterDropletGroup.Random(), Random.Range(waterDropletAudioVolumeRange.x, waterDropletAudioVolumeRange.y), position:collisionEvents[0].intersection).spatialBlend = 1f;;
	}
}
