private void InitializeDictionary() { ACharacterState instance = new JumpState() as JumpState; instance.Initialize(ECharacterState.JUMP, this); _characterStates.Add(ECharacterState.JUMP, instance); instance = new IdleState() as IdleState; instance.Initialize(ECharacterState.IDLE, this); _characterStates.Add(ECharacterState.IDLE, instance); instance = new WalkState() as WalkState; instance.Initialize(ECharacterState.WALK, this); _characterStates.Add(ECharacterState.WALK, instance); instance = new FallState() as FallState; instance.Initialize(ECharacterState.FALL, this); _characterStates.Add(ECharacterState.FALL, instance); instance = new SteamState() as SteamState; instance.Initialize(ECharacterState.STEAM, this); _characterStates.Add(ECharacterState.STEAM, instance); }
//If the garment is being pressed, returns true; if it is being burned, returns false public SteamState Press(float ironPosition) { SteamState steam = SteamState.Off; if (TimeManager.instance.timeScale == 0.0f) { return(SteamState.Off); } //ironPosition has to be offset by an arbitrary value > 0.5 because the board overlaps with the 0 position on the X axis. //This ensures that we can distinguish between an uninitialized lastIronPos and a lastIronPos of value 0. ironPosition += 5.0f; if (lastIronPos == 0.0f) { lastIronPos = ironPosition; return(SteamState.Off); } float ironSpeed = Mathf.Abs(ironPosition - lastIronPos) / Time.fixedDeltaTime; //Debug.Log("Current speed: " + ironSpeed + " Minimum: " + minIronSpeed); if (ironingBoard.garmentOnBoard.fabric.pressingRestrictions != PressingRestrictions.NoIroning && ironSpeed > minIronSpeed && pressingProgress < 1.0f && !ironingBoard.garmentOnBoard.Pressed && !ironingBoard.garmentOnBoard.Ruined && ironingBoard.garmentOnBoard.Clean && ironingBoard.garmentOnBoard.Dry) { graceTimer = 0; //Press steam = SteamState.Steam; pressingProgress += (ironSpeed * Time.fixedDeltaTime) / ironingBoard.garmentOnBoard.fabric.ironingDistance; } else if (graceTimer < gracePeriod && !(ironingBoard.garmentOnBoard.Burned || ironingBoard.garmentOnBoard.Melted)) { //Grace period steam = SteamState.Off; graceTimer += Time.fixedDeltaTime; } else if (!(ironingBoard.garmentOnBoard.Burned || ironingBoard.garmentOnBoard.Melted) && ironingBoard.garmentOnBoard.Dry) { //Burn steam = SteamState.Burn; burnTimer += Time.fixedDeltaTime; } //If the garment was steamed long enough, it becomes pressed if (pressingProgress >= 1.0f && !ironingBoard.garmentOnBoard.Pressed) { AudioManager.instance.PlaySound(SoundName.ShiningGarment); ironingBoard.garmentOnBoard.Pressed = true; garmentRenderer.UpdateAppearance(); } //If the garment was burned too much, it becomes ruined if (burnTimer > burnTime && !(ironingBoard.garmentOnBoard.Burned || ironingBoard.garmentOnBoard.Melted)) { if (ironingBoard.garmentOnBoard.fabric.name.Equals("Synthetic")) { ironingBoard.garmentOnBoard.Melted = true; } else { ironingBoard.garmentOnBoard.Burned = true; } garmentRenderer.UpdateAppearance(); } lastIronPos = ironPosition; return(steam); }
private void FixedUpdate() { if (onIroningBoard && ironingBoard.garmentOnBoard != null) { if (TimeManager.instance.timeScale != 0.0f) { steamState = laundryIroningBoard.Press(transform.position.x); } } else { steamState = SteamState.Off; } if (steamState == SteamState.Steam && !steam.isEmitting) { steam.Play(true); smoke.Stop(true, ParticleSystemStopBehavior.StopEmitting); } if (steamState == SteamState.Burn && !smoke.isEmitting) { smoke.Play(true); steam.Stop(true, ParticleSystemStopBehavior.StopEmitting); } if (steamState == SteamState.Off && (steam.isEmitting || smoke.isEmitting)) { steam.Stop(true, ParticleSystemStopBehavior.StopEmitting); smoke.Stop(true, ParticleSystemStopBehavior.StopEmitting); } if (steamState == SteamState.Steam) { if (burnLoop != null) { burnLoop.Stop(); burnLoop = null; } if (steamLoop == null) { steamLoop = AudioManager.instance.PlaySoundLoop(SoundName.IronIsWorking); } } else if (steamState == SteamState.Burn) { if (steamLoop != null) { steamLoop.Stop(); steamLoop = null; } if (burnLoop == null) { burnLoop = AudioManager.instance.PlaySoundLoop(SoundName.IronisBurning); } } else { if (steamLoop != null) { steamLoop.Stop(); steamLoop = null; } if (burnLoop != null) { burnLoop.Stop(); burnLoop = null; } } }