/// <summary> /// Pours the beer and attempts to fill another container /// The more the container is turned, the more it empties /// </summary> void PourBeer() { if (Time.time > overfillTimer && overfilling) { overfilling = false; emitter.emit = false; } if (ShouldPour() && !pouring) { emitter.emit = true; pouring = true; } if (!ShouldPour() && pouring) //If arent tilted enough to pour { if (!overfilling) { emitter.emit = false; } pouring = false; return; } if (!pouring) { return; } // //Calculate how much liquid is in the difference of the thetaDegree angle and our current angle float Vi = Mathf.PI * Mathf.Pow(radius, 2) * H; //Volume we start at float overpour = .5f * (deltaRot - thetaDegrees); float percentDelta = .5f + overpour; //How much % we are dropping float Vf = Mathf.PI * Mathf.Pow(radius, 2) * ((beerPercent - percentDelta) * .01f * height); //Volume we end at if (beerPercent - percentDelta < 0) //Cant empty more than we have { percentDelta = beerPercent; } if (!debugDontPour) { beerPercent -= percentDelta; } emitter.minSize = Mathf.Clamp(.25f * percentDelta, .02f, .06f); emitter.maxSize = Mathf.Clamp(emitter.minSize * 2.5f, .045f, .12f); BeerContainer bc = GetPourContainer(); if (bc != null) { bc.ReceiveBeer(Vi - Vf); } }
/// <summary> /// Pours the overflow beer if we attempt to fill an already full beer /// </summary> void PourOverflowBeer(float volume) { BeerContainer bc = GetPourContainer(); if (bc != null) { float percent = volume / totalVolume; emitter.minSize = .045f * percent; emitter.minSize = Mathf.Clamp(.25f * percent, .02f, .06f); emitter.maxSize = Mathf.Clamp(emitter.minSize * 2.5f, .045f, .12f); bc.ReceiveBeer(volume); } }
/// <summary> /// Checks if there is something to pour into below the tap /// </summary> void CheckForBeerContainer() { for (int i = 0; i < Taps.Count; i++) { Transform t = Taps [i]; RaycastHit hit; if (Physics.Raycast(t.position, Vector3.down, out hit, 5)) { if (hit.transform.name == "CenterTop") { BeerContainer b = hit.transform.GetComponentInParent <BeerContainer> (); if (b != null) { TapEmitters[i].emit = true; b.ReceiveBeer(VolumeFillPerSecond * Time.deltaTime); } } else { TapEmitters[i].emit = false; } } } }