private IEnumerator SetupRoomElevatorSwitch() { SetupRoom setupRoom = SceneManager.Instance.CurrentRoom as SetupRoom; if (setupRoom == null) { yield break; } try { ElevatorRoomGameObject = Resources.Load <GameObject>("PC/Prefabs/ElevatorRoom/ElevatorBombRoom"); } catch (Exception ex) { DebugHelper.LogException(ex, "Can't load the Elevator room prefab."); gameObject.SetActive(false); yield break; } if (setupRoom.ElevatorSwitch == null) { ElevatorSwitch.OnInteract += OnInteract; ElevatorLEDOn.SetActive(IsON); ElevatorLEDOff.SetActive(!IsON); ElevatorSwitch.transform.localEulerAngles = new Vector3(IsON ? 55 : -55, 0, 0); yield break; } ElevatorSwitch elevatorSwitch = setupRoom.ElevatorSwitch; DebugHelper.Log("Found an Elevator switch, Activating it now"); try { elevatorSwitch.GetComponentInChildren <Selectable>(true).SelectableArea.ActivateSelectableArea(); elevatorSwitch.Switch.SetInitialState(GameplayState.GameplayRoomPrefabOverride != null); elevatorSwitch.LEDOn.SetActive(GameplayState.GameplayRoomPrefabOverride != null); elevatorSwitch.LEDOff.SetActive(GameplayState.GameplayRoomPrefabOverride == null); elevatorSwitch.Switch.OnToggle += toggleState => { DebugHelper.Log($"Toggle State = {toggleState}"); if (elevatorSwitch.On() && IRCConnection.Instance.State != IRCConnectionState.Connected) { elevatorSwitch.Switch.Toggle(); Audio.PlaySound(KMSoundOverride.SoundEffect.Strike, elevatorSwitch.Switch.transform); return; } GameplayState.GameplayRoomPrefabOverride = toggleState ? ElevatorRoomGameObject : null; IRCConnection.SendMessageFormat("Elevator is {0}", GameplayState.GameplayRoomPrefabOverride == null ? (ElevatorRoomGameObject == null ? "not loaded" : "off") : "on"); elevatorSwitch.LEDOn.SetActive(GameplayState.GameplayRoomPrefabOverride != null); elevatorSwitch.LEDOff.SetActive(GameplayState.GameplayRoomPrefabOverride == null); }; } catch (Exception ex) { DebugHelper.LogException(ex, "Could not activate elevator switch due to an exception:"); yield break; } elevatorSwitch.gameObject.SetActive(true); yield return(null); yield return(null); elevatorSwitch.gameObject.SetActive(true); gameObject.SetActive(false); }
public IEnumerator ToggleSetupRoomElevatorSwitch(bool elevatorState) { ElevatorSwitch elevatorSwitch = null; if (SceneManager.Instance.CurrentRoom is SetupRoom setupRoom) { elevatorSwitch = setupRoom.ElevatorSwitch; } DebugHelper.Log("Setting Elevator state to {0}", elevatorState); if (elevatorSwitch == null) { IEnumerator ircManager = IRCConnectionManagerHandler.Instance.RespondToCommand("Elevator Switch", elevatorState ? "elevator on" : "elevator off"); while (ircManager.MoveNext()) { yield return(ircManager.Current); } yield break; } else { IEnumerator dropHoldables = MiscellaneousMessageResponder.DropAllHoldables(); while (dropHoldables.MoveNext()) { yield return(dropHoldables.Current); } yield return(new WaitForSeconds(0.25f)); } float duration = 2f; GameRoom.ToggleCamera(false); yield return(null); float initialTime = Time.time; Vector3 currentWallPosition = new Vector3(0, 0, 0); Vector3 currentWallRotation = new Vector3(26.39f, 0, 0); Vector3 newWallPosition = new Vector3(-0.6f, -1f, 0.3f); Vector3 newWallRotation = new Vector3(0, 40, 0); Transform camera = GameRoom.SecondaryCamera.transform; while ((Time.time - initialTime) < duration) { float lerp = (Time.time - initialTime) / duration; camera.localPosition = new Vector3(Mathf.SmoothStep(currentWallPosition.x, newWallPosition.x, lerp), Mathf.SmoothStep(currentWallPosition.y, newWallPosition.y, lerp), Mathf.SmoothStep(currentWallPosition.z, newWallPosition.z, lerp)); camera.localEulerAngles = new Vector3(Mathf.SmoothStep(currentWallRotation.x, newWallRotation.x, lerp), Mathf.SmoothStep(currentWallRotation.y, newWallRotation.y, lerp), Mathf.SmoothStep(currentWallRotation.z, newWallRotation.z, lerp)); yield return(null); } camera.localPosition = newWallPosition; camera.localEulerAngles = newWallRotation; yield return(new WaitForSeconds(0.5f)); DebugHelper.Log("Elevator Switch Toggled"); if (elevatorState != elevatorSwitch.On()) { elevatorSwitch.Switch.Toggle(); } else { ReportState(); } yield return(new WaitForSeconds(0.5f)); initialTime = Time.time; while ((Time.time - initialTime) < duration) { float lerp = (Time.time - initialTime) / duration; camera.localPosition = new Vector3(Mathf.SmoothStep(newWallPosition.x, currentWallPosition.x, lerp), Mathf.SmoothStep(newWallPosition.y, currentWallPosition.y, lerp), Mathf.SmoothStep(newWallPosition.z, currentWallPosition.z, lerp)); camera.localEulerAngles = new Vector3(Mathf.SmoothStep(newWallRotation.x, currentWallRotation.x, lerp), Mathf.SmoothStep(newWallRotation.y, currentWallRotation.y, lerp), Mathf.SmoothStep(newWallRotation.z, currentWallRotation.z, lerp)); yield return(null); } camera.localPosition = currentWallPosition; camera.localEulerAngles = currentWallRotation; yield return(null); DebugHelper.Log("Finished"); GameRoom.ToggleCamera(true); }