private bool RemoveDrop(FluidLine fluidLine, int flowingToPosition) { if (fluidLine.length == 0) { Debug.Log("[ERROR]RemoveTop(): Couldnt remove a drop from the top FluidLine."); return(false); } else if (fluidLine.length == 1) { //Debug.Log ("Removing drop at " + fluidLine.ToString ()); DeleteFluidLine(fluidLine); return(true); } else { IList <int> mostFreePositions = FindMostFreePositionsIn(fluidLine); //Debug.Log("Most Free positions = " + mostFreePositions.ToArray ().ElementsToString ()); if (mostFreePositions.Count == 1) { return(RemoveDropAtPosition(fluidLine, mostFreePositions.ElementAt(0))); } else { List <int> removeCandidates = new List <int>(); int maxSinkDistance = 0; // select the drops that are furthest away from their sink lines for (int i = 0; i < mostFreePositions.Count; i++) { if (fluidLine.SinkDistanceAt(mostFreePositions[i]) > maxSinkDistance) { removeCandidates.Clear(); removeCandidates.Add(mostFreePositions[i]); maxSinkDistance = fluidLine.SinkDistanceAt(mostFreePositions[i]); } else if (fluidLine.SinkDistanceAt(mostFreePositions[i]) == maxSinkDistance) { removeCandidates.Add(mostFreePositions[i]); } } // chose the closest one of those int distance; int maxDistance = 0; int maxDistancePosition = 0; foreach (int position in removeCandidates) { distance = Mathf.Abs(position - (flowingToPosition - fluidLine.x)); if (maxDistance <= distance) { maxDistance = distance; maxDistancePosition = position; } } //Debug.Log ("Removing drop in " + fluidLine.ToString () + " at position " + minDistancePosition); return(RemoveDropAtPosition(fluidLine, maxDistancePosition)); } } }