public IEnumerator <float> DoingJob() { //PlayerAnimationHelper.ResetPlayer(); Debug.Log("StartedWork"); Player.col.enabled = false; JobManager.Instance.CurrentJob.ShowUpAtWork(); Physics2D.IgnoreLayerCollision(GameLibOfMethods.player.layer, 10, true); GameLibOfMethods.cantMove = true; GameLibOfMethods.player.GetComponent <Rigidbody2D>().velocity = Vector2.zero; GameClock.ChangeSpeedToSleepingSpeed(); float TimeToFinishWork = ((float)System.TimeSpan.FromHours(JobManager.Instance.CurrentJob.WorkingTimeInHours).TotalSeconds - (GameClock.Time - (float)System.TimeSpan.FromHours(JobManager.Instance.CurrentJob.JobStartingTimeInHours).TotalSeconds)); float GetJobProgress() => JobManager.Instance.CurrentWorkingTime / TimeToFinishWork; int progressBarID = ProgressBar.StartTracking("Working", GetJobProgress); while (JobManager.Instance.CurrentJob != null && JobManager.Instance.CurrentWorkingTime <= TimeToFinishWork && !Input.GetKeyDown(KeyCode.P)) { JobManager.Instance.CurrentWorkingTime += (Time.deltaTime * GameClock.TimeMultiplier) * GameClock.Speed; // Debug.Log("Current job progress is " + GameLibOfMethods.progress + ". Working time in seconds: " + JobManager.Instance.CurrentWorkingTime + ". And required work time is " + JobManager.Instance.CurrentJob.WorkingTimeInSeconds); yield return(0f); } ProgressBar.HideUI(progressBarID); if (JobManager.Instance.CurrentJob != null) { JobManager.Instance.CurrentJob.Finish(); JobManager.Instance.CurrentWorkingTime = 0; } Debug.Log("Called car back from work"); CarToPlayerHouse(); yield return(0f); GameClock.ResetSpeed(); }
public IEnumerator <float> DoingJob() { //PlayerAnimationHelper.ResetPlayer(); Debug.Log("StartedWork"); JobManager.Instance.CurrentJob.ShowUpAtWork(); Physics2D.IgnoreLayerCollision(GameLibOfMethods.player.layer, 10, true); GameLibOfMethods.cantMove = true; GameLibOfMethods.player.GetComponent <Rigidbody2D>().velocity = Vector2.zero; GameClock.ChangeSpeedToSleepingSpeed(); while (JobManager.Instance.CurrentJob != null && System.TimeSpan.FromSeconds(JobManager.Instance.CurrentWorkingTime).Hours <= JobManager.Instance.CurrentJob.WorkingTimeInHours && !Input.GetKeyDown(KeyCode.P)) { JobManager.Instance.CurrentWorkingTime += (Time.deltaTime * GameClock.TimeMultiplier) * GameClock.Speed; GameLibOfMethods.progress = JobManager.Instance.CurrentWorkingTime / (float)System.TimeSpan.FromHours(JobManager.Instance.CurrentJob.WorkingTimeInHours).TotalSeconds; // Debug.Log("Current job progress is " + GameLibOfMethods.progress + ". Working time in seconds: " + JobManager.Instance.CurrentWorkingTime + ". And required work time is " + JobManager.Instance.CurrentJob.WorkingTimeInSeconds); yield return(0f); } GameLibOfMethods.progress = 0; if (JobManager.Instance.CurrentJob != null) { JobManager.Instance.CurrentJob.Finish(); JobManager.Instance.CurrentWorkingTime = 0; } Debug.Log("Called car back from work"); CarToPlayerHouse(); yield return(0f); GameClock.ResetSpeed(); }
IEnumerator <float> Sleeping() { HandlePlayerSprites(enable: false); //PlayerAnimationHelper.ResetPlayer(); yield return(0f); Debug.Log("Went to sleep"); Physics2D.IgnoreLayerCollision(GameLibOfMethods.player.layer, 10, true); GameLibOfMethods.isSleeping = true; GameLibOfMethods.cantMove = true; GameLibOfMethods.animator.SetBool("Sleeping", true); GameLibOfMethods.player.GetComponent <Rigidbody2D>().velocity = Vector2.zero; yield return(MEC.Timing.WaitForSeconds(0.5f)); GameLibOfMethods.AddChatMessege("Went to sleep."); float T = 0; GameClock.ChangeSpeedToSleepingSpeed(); while (true) { GameLibOfMethods.concecutiveSleepTime += (Time.deltaTime * GameClock.TimeMultiplier) * GameClock.Speed; float Multi = (Time.deltaTime / GameClock.Speed) * GameClock.TimeMultiplier; Stats.Status(Type.Energy).Add(EnergyGainPerHour * Multi); Stats.Status(Type.Mood).Add(MoodGainPerHour * Multi); Stats.Status(Type.Health).Add(HealthGainPerHour * Multi); if (Input.GetKeyUp(KeyCode.E)) { break; } if (Stats.Status(Type.Energy).CurrentAmount >= Stats.Status(Type.Energy).MaxAmount) { T += Time.deltaTime; if (T >= 2) { GameLibOfMethods.CreateFloatingText("Can't sleep more", 2); break; } } yield return(0f); } PlayExitSound(); GameLibOfMethods.animator.SetBool("Sleeping", false); yield return(0f); while (true) { var state = GameLibOfMethods.animator.GetCurrentAnimatorStateInfo(0); if (!state.IsName("JumpOffToBed")) { Debug.Log("Something is wrong.. this finished before firing the method. Make sure you don't call this from FixedUpdate."); break; } if (state.normalizedTime >= 40 / 50f) { break; } yield return(0f); } HandlePlayerSprites(enable: true); PlayerCommands.JumpOff(JumpOffSpeed); GameClock.ResetSpeed(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { GameClock.ChangeSpeed(TimeMultiplierWhileSleeping); }