public static IEnumerator Zoom(TwitchModule module, SuperZoomData zoomData, object yield) { var zoomCoroutine = TwitchGame.ModuleCameras?.ZoomCamera(module, zoomData, 1); if (zoomCoroutine != null) { while (zoomCoroutine.MoveNext()) { yield return(zoomCoroutine.Current); } } yield return(yield is float delay ? new WaitForSecondsWithCancel(delay, false, module.Solver) : yield); if (CoroutineCanceller.ShouldCancel) { module.StartCoroutine(TwitchGame.ModuleCameras?.UnzoomCamera(module, zoomData, 0)); yield break; } var unzoomCoroutine = TwitchGame.ModuleCameras?.UnzoomCamera(module, zoomData, 1); if (unzoomCoroutine != null) { while (unzoomCoroutine.MoveNext()) { yield return(unzoomCoroutine.Current); } } }
public IEnumerator UnzoomCamera(float duration = 1.0f, SuperZoomData zoomData = default) { yield return(null); foreach (float lerp in duration.TimedAnimation()) { CameraInstance.rect = new Rect(Mathf.Lerp(ZoomCameraLocation.x, OriginalCameraRect.x, lerp), Mathf.Lerp(ZoomCameraLocation.y, OriginalCameraRect.y, lerp), Mathf.Lerp(ZoomCameraLocation.width, OriginalCameraRect.width, lerp), Mathf.Lerp(ZoomCameraLocation.height, OriginalCameraRect.height, lerp)); CameraInstance.fieldOfView = Mathf.Lerp(5, 5 / zoomData.factor, 1 - lerp); CameraInstance.transform.localPosition = Vector3.Lerp(new Vector3(0.001f, 2.25f, 0), new Vector3(0.001f + (zoomData.x - 0.5f) * 0.2f, 2.25f, (zoomData.y - 0.5f) * 0.2f), 1 - lerp); yield return(null); } CameraInstance.depth = 99; ZoomActive = false; if (PreviousModule != null) { // Return the camera back to the component that WAS there unless that module is now solved. ViewModule(PreviousModule.Solved ? Instance.PreferredToView : PreviousModule); PreviousModule = null; } }
public IEnumerator UnzoomCamera(TwitchModule component, SuperZoomData zoomData, float delay) { int existingCamera = CurrentModulesContains(component); if (existingCamera == -1) { existingCamera = BorrowCameraForZoom(component); } if (existingCamera > -1) { ModuleCamera cam = _moduleCameras[existingCamera]; return(cam.UnzoomCamera(delay, zoomData)); } return(null); }
public IEnumerator ZoomCamera(float duration = 1.0f, SuperZoomData zoomData = default) { CameraInstance.depth = 100; ZoomActive = true; yield return(null); foreach (float lerp in duration.TimedAnimation()) { CameraInstance.rect = new Rect(Mathf.Lerp(OriginalCameraRect.x, ZoomCameraLocation.x, lerp), Mathf.Lerp(OriginalCameraRect.y, ZoomCameraLocation.y, lerp), Mathf.Lerp(OriginalCameraRect.width, ZoomCameraLocation.width, lerp), Mathf.Lerp(OriginalCameraRect.height, ZoomCameraLocation.height, lerp)); CameraInstance.fieldOfView = Mathf.Lerp(5, 5 / zoomData.factor, lerp); CameraInstance.transform.localPosition = Vector3.Lerp(new Vector3(0.001f, 2.25f, 0), new Vector3(0.001f + (zoomData.x - 0.5f) * 0.2f, 2.25f, (zoomData.y - 0.5f) * 0.2f), lerp); yield return(null); } }
public static IEnumerator DefaultCommand(TwitchModule module, string user, string cmd) { if ((Votes.Active && Votes.CurrentVoteType == VoteTypes.Solve && Votes.voteModule == module) || module.Votesolving) { IRCConnection.SendMessage($"Sorry @{user}, the module you are trying to interact with is being votesolved."); yield break; } if (cmd.RegexMatch(out Match match, @"(?:(?<zoom>zoom *(?<time>\d*\.?\d+)?)|(?<superzoom>superzoom *(?<factor>\d*\.?\d+) *(?<x>\d*\.?\d+)? *(?<y>\d*\.?\d+)? *(?<stime>\d*\.?\d+)?))? *(?:(?<tilt>tilt *(?<direction>[uptobmdwnlefrigh]+|-?\d+)?)|(?<show>show)?)? *(?:send *to *module)? *(?<command>.+)?")) { var groups = match.Groups; var timed = groups["time"].Success || groups["stime"].Success; var zooming = groups["zoom"].Success || groups["superzoom"].Success; var tilt = groups["tilt"].Success; var show = groups["show"].Success; var command = groups["command"].Success; if (!timed && !zooming && !command && show) { yield return(Show(module, 0.5)); yield break; } // Both a time and a command can't be entered. And either a zoom, show or tilt needs to take place otherwise, we should let the command run normally. if ((!timed || !command) && (zooming || tilt || show)) { MusicPlayer musicPlayer = null; float delay = 2; if (timed) { delay = groups["time"].Value.TryParseInt() ?? groups["stime"].Value.TryParseInt() ?? 2; delay = Math.Max(2, delay); } object toYield = command ? (object)RunModuleCommand(module, user, groups["command"].Value) : delay; IEnumerator routine = null; if (show) { routine = Show(module, toYield); } if (tilt) { routine = Tilt(module, toYield, groups["direction"].Value.ToLowerInvariant()); } if (zooming) { var zoomData = new SuperZoomData( groups["factor"].Value.TryParseFloat() ?? 1, groups["x"].Value.TryParseFloat() ?? 0.5f, groups["y"].Value.TryParseFloat() ?? 0.5f ); routine = Zoom(module, zoomData, routine ?? toYield); } if (delay >= 15) { musicPlayer = MusicPlayer.StartRandomMusic(); } yield return(routine); if (CoroutineCanceller.ShouldCancel) { CoroutineCanceller.ResetCancel(); IRCConnection.SendMessage($"Sorry @{user}, your request to hold up the bomb for {delay} seconds has been cut short."); } if (musicPlayer != null) { musicPlayer.StopMusic(); } yield break; } } yield return(RunModuleCommand(module, user, cmd)); }