private void InitializeDrawer(FlowRainDrawerContainer dc) { dc.TimeElapsed = 0f; dc.lifetime = RainDropTools.Random(Variables.LifetimeMin, Variables.LifetimeMax); dc.fluctuationRate = RainDropTools.Random(Variables.fluctuationRateMin, Variables.fluctuationRateMax); dc.acceleration = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax); dc.transform.localPosition = RainDropTools.GetSpawnLocalPos(this.transform, camera, 0f, Variables.SpawnOffsetY); dc.startPos = dc.transform.localPosition; dc.acceleration = RainDropTools.Random(Variables.AccelerationMin, Variables.AccelerationMax); Material mat = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue); RainDropTools.ApplyRainMaterialValue( mat, ShaderType, Variables.NormalMap, Variables.OverlayTexture, Variables.DistortionValue, Variables.OverlayColor, Variables.ReliefValue, Variables.Blur, Variables.Darkness ); dc.Drawer.lifeTime = dc.lifetime; dc.Drawer.vertexDistance = 0.01f; dc.Drawer.angleDivisions = 20; dc.Drawer.material = mat; dc.Drawer.widthCurve = Variables.TrailWidth; dc.Drawer.widthMultiplier = RainDropTools.Random(Variables.SizeMinX, Variables.SizeMaxX); dc.Drawer.textureMode = LineTextureMode.Stretch; dc.Drawer.vertexDistance = (1f * this.Distance * RainDropTools.GetCameraOrthographicSize(this.camera).y) / (Variables.Resolution * 10f); dc.Drawer.Clear(); dc.Drawer.enabled = false; }
private void CheckSpawnNum() { int diff = Variables.MaxRainSpawnCount - drawers.Count(); // MaxRainSpawnCount was increased if (diff > 0) { for (int i = 0; i < diff; i++) { FlowRainDrawerContainer container = new FlowRainDrawerContainer("Flow RainDrawer " + (drawers.Count() + i), this.transform); container.currentState = DrawState.Disabled; drawers.Add(container); } } // MaxRainSpawnCount was decreased if (diff < 0) { int rmcnt = -diff; List <FlowRainDrawerContainer> removeList = drawers.FindAll(x => x.currentState != DrawState.Playing).Take(rmcnt).ToList(); if (removeList.Count() < rmcnt) { removeList.AddRange(drawers.FindAll(x => x.currentState == DrawState.Playing).Take(rmcnt - removeList.Count())); } foreach (var rem in removeList) { rem.Drawer.Clear(); DestroyImmediate(rem.Drawer.gameObject); } drawers.RemoveAll(x => x.Drawer == null); } }
/// <summary> /// Refresh this instance. /// </summary> public void Refresh() { foreach (var d in drawers) { DestroyImmediate(d.Drawer.gameObject); } drawers.Clear(); for (int i = 0; i < Variables.MaxRainSpawnCount; i++) { FlowRainDrawerContainer container = new FlowRainDrawerContainer("Flow RainDrawer " + i, this.transform); container.currentState = DrawState.Disabled; drawers.Add(container); } }
/// <summary> /// Update rain variables /// </summary> /// <param name="i">The index.</param> private void UpdateInstance(FlowRainDrawerContainer dc, int index) { if (dc.currentState == DrawState.Playing) { if (GetProgress(dc) >= 1.0f) { dc.Drawer.Clear(); dc.currentState = DrawState.Disabled; } else { dc.TimeElapsed += Time.deltaTime; UpdateTransform(dc); UpdateShader(dc, index); } } }
private void UpdateTransform(FlowRainDrawerContainer dc) { Action initRnd = () => { dc.rnd1 = RainDropTools.Random(-0.1f * Variables.Amplitude, 0.1f * Variables.Amplitude); dc.posXDt = 0f; }; if (dc.posXDt == 0f) { StartCoroutine( Wait( 0.01f, 0.01f, (int)(1f / dc.fluctuationRate * 100), () => { initRnd(); } ) ); } dc.posXDt += 0.01f * Variables.Smooth * Time.deltaTime; if (dc.rnd1 == 0f) { initRnd(); } float t = dc.TimeElapsed; Vector3 downward = RainDropTools.GetGForcedScreenMovement(this.camera.transform, this.GForceVector); downward = -downward.normalized; Vector3 nextPos = new Vector3( Vector3.Slerp(dc.transform.localPosition, dc.transform.localPosition + downward * dc.rnd1, dc.posXDt).x, dc.startPos.y - downward.y * (1 / 2f) * t * t * dc.acceleration - Variables.InitialVelocity * t, 0.001f // TODO: Work around ); dc.transform.localPosition = nextPos; dc.transform.localPosition += GetProgress(dc) * new Vector3(GlobalWind.x, GlobalWind.y, 0f); }
private void UpdateShader(FlowRainDrawerContainer dc, int index) { float progress = GetProgress(dc); dc.Drawer.material.renderQueue = RenderQueue + index; // Update shader if needed if (dc.Drawer.material.shader.name != RainDropTools.GetShaderName(ShaderType)) { dc.Drawer.material = RainDropTools.CreateRainMaterial(ShaderType, RenderQueue + index); } float distortionValue = Variables.DistortionValue * Variables.DistortionOverLifetime.Evaluate(progress) * Alpha; float reliefValue = Variables.ReliefValue * Variables.ReliefOverLifetime.Evaluate(progress) * Alpha; float blurValue = Variables.Blur * Variables.BlurOverLifetime.Evaluate(progress) * Alpha; Color overlayColor = new Color( Variables.OverlayColor.r, Variables.OverlayColor.g, Variables.OverlayColor.b, Variables.OverlayColor.a * Variables.AlphaOverLifetime.Evaluate(progress) * Alpha ); switch (ShaderType) { case RainDropTools.RainDropShaderType.Expensive: if (distortionValue == 0f && reliefValue == 0f && overlayColor.a == 0f && blurValue == 0f) { dc.Drawer.enabled = false; return; } break; case RainDropTools.RainDropShaderType.Cheap: if (distortionValue == 0f) { dc.Drawer.enabled = false; return; } break; case RainDropTools.RainDropShaderType.NoDistortion: if (reliefValue == 0f && overlayColor.a == 0f) { dc.Drawer.enabled = false; return; } break; } RainDropTools.ApplyRainMaterialValue( dc.Drawer.material, ShaderType, Variables.NormalMap, Variables.OverlayTexture, distortionValue, overlayColor, reliefValue, blurValue, Variables.Darkness * Alpha ); dc.Drawer.enabled = true; }
private float GetProgress(FlowRainDrawerContainer dc) { return(dc.TimeElapsed / dc.lifetime); }