private IEnumerator BranchingExecution() { Vector3 newParticleDirection; float time, t; switch (step) { case Step.AppearZoom: { AppearZoom(gameObject, 0f); yield return(new WaitForSeconds(.2f)); step = Step.AffectedParticleRB; break; } case Step.AffectedParticleRB: { affectedParticle.enabled = true; //step = Step.Idle; step = Step.BeginVineTrail; break; } case Step.BeginVineTrail: { TrailRenderer trail = gameObject.GetComponent <TrailRenderer>(); trail = null; if (trail != null) { trail.enabled = false; } if (vine == null) { Transform vineObject = Instantiate <Transform>(vineTemplate); vineObject.transform.position = Vector3.zero; vine = vineObject.GetComponent <Scene_Vine> (); } vine.p.size = p.vineShapeSize; vine.mainTarget = transform; vine.Begin(); step = Step.Idle; break; } case Step.Travel: { #region travel time = Time.time; t = time * p.brownianCycleDuration; direction.coneRadius = LF(p.particleConeStart, p.particleConeEnd, Mathf.Sin(t) * .5f + .5f); newParticleDirection = direction.GetRandom(); UpdateParticleWith(newParticleDirection, p.particleSpeed); //direction.vector = newParticleDirectionB; #endregion yield return(new WaitForFixedUpdate()); break; } default: { yield return(new WaitForFixedUpdate()); break; } } }
private IEnumerator ScenarioExecution() { Vector3 newParticleDirection; float time, t; switch (step) { case Step.AppearZoom: { AppearZoom(gameObject, 1f); yield return(new WaitForSeconds(1f)); step = Step.Idle; break; } case Step.UpToSpeed: { #region get up to speed p.particleSpeed = p.particleBrownianSpeedStart; direction.coneRadius = p.particleConeStart; float duration = p.particleUpToSpeedDuration, start = Time.time; while (p.particleSpeed < p.particleBrownianSpeedEnd) { time = Time.time; t = (time - start) / duration; p.particleSpeed = LF(p.particleBrownianSpeedStart, p.particleBrownianSpeedEnd, t); //direction.coneRadius = LF ( p.particleConeStart, p.particleConeEnd, t ); direction.coneRadius = LF(p.particleConeStart, p.particleConeEnd, Mathf.Sin(time * p.brownianCycleDuration) * .5f + .5f); newParticleDirection = direction.GetRandom(); UpdateParticleWith(newParticleDirection, p.particleSpeed); //direction.vector = newParticleDirection; p.cameraFollowTarget = transform.position; UpdateCameraPosition(); yield return(new WaitForFixedUpdate()); } #endregion step = Step.Travel; break; } case Step.AffectedParticleRB: { affectedParticle.enabled = true; Vector3 velocity = direction.vector * p.particleSpeed; affectedParticle.GetComponent <Rigidbody> ().AddForce(velocity * 2f, ForceMode.Impulse); //step = Step.Idle; step = Step.Idle; break; } case Step.BeginVineTrail: { TrailRenderer trail = gameObject.GetComponent <TrailRenderer>(); trail = null; if (trail != null) { trail.enabled = false; } if (vine == null) { Transform vineObject = Instantiate <Transform>(vineTemplate); vineObject.transform.position = Vector3.zero; vine = vineObject.GetComponent <Scene_Vine> (); } vine.p.size = p.vineShapeSize; vine.mainTarget = transform; vine.Begin(); step = Step.Idle; break; } case Step.AutomateBranching: { automatedBranching = true; step = Step.Idle; break; } case Step.Travel: { #region travel time = Time.time; t = time * p.brownianCycleDuration; direction.coneRadius = LF(p.particleConeStart, p.particleConeEnd, Mathf.Sin(t) * .5f + .5f); newParticleDirection = direction.GetRandom(); UpdateParticleWith(newParticleDirection, p.particleSpeed); //direction.vector = newParticleDirectionB; p.cameraFollowTarget = transform.position; UpdateCameraPosition(); #endregion yield return(new WaitForFixedUpdate()); break; } case Step.BackEraseVines: { BackEraseVines(); StopVineGrowth(); step = Step.Idle; break; } default: { p.cameraFollowTarget = transform.position; UpdateCameraPosition(); yield return(new WaitForFixedUpdate()); break; } } }