/// <summary> /// The core shared code of the MoveToNISPosition method, split out to optimize /// updates in ScreenUpdate. /// </summary> /// <param name="instance">The map screen rendering this method.</param> /// <param name="scale">The current scale of the starmap.</param> /// <param name="targetScale">The scale that the starmap is moving towards.</param> /// <param name="position">The current and new position of the starmap</param> /// <param name="selectWhenComplete">The hex to select when complete.</param> /// <param name="selected">The currently selected hex.</param> private static void NISMoveCore(ClusterMapScreen instance, float scale, ref float targetScale, ref Vector3 position) { float dt = Time.unscaledDeltaTime, distance; bool move = true; Vector3 pos = position; var targetPosition = instance.targetNISPosition; var destination = new Vector3(-targetPosition.x * scale, -targetPosition.y * scale, targetPosition.z); var cells = instance.m_cellVisByLocation; // Always 150.0 when reached targetScale = Mathf.Lerp(targetScale, 150.0f, dt * 2.0f); position = pos = Vector3.Lerp(pos, destination, dt * 2.5f); distance = Vector3.Distance(pos, destination); // Close to destination? if (distance < 100.0f && cells.TryGetValue(instance.selectOnMoveNISComplete, out ClusterMapVisualizer visualizer)) { if (visualizer.TryGetComponent(out ClusterMapHex hex) && hex != instance. m_selectedHex) { instance.SelectHex(hex); } // Reached destination? if (distance < 10.0f) { move = false; } } instance.movingToTargetNISPosition = move; }
/// <summary> /// Applied before MoveToNISPosition runs. /// </summary> internal static bool Prefix(ClusterMapScreen __instance) { RectTransform content; var mapScrollRect = __instance.mapScrollRect; if (__instance.movingToTargetNISPosition && mapScrollRect != null && (content = mapScrollRect.content) != null) { var pos = content.localPosition; NISMoveCore(__instance, __instance.m_currentZoomScale, ref __instance. m_targetZoomScale, ref pos); content.localPosition = pos; } return(false); }
/// <summary> /// Applied before ScreenUpdate runs. /// </summary> internal static bool Prefix(ClusterMapScreen __instance) { RectTransform content; var mapScrollRect = __instance.mapScrollRect; if (mapScrollRect != null && (content = mapScrollRect.content) != null) { float scale = __instance.m_currentZoomScale, target = __instance. m_targetZoomScale; var mousePos = KInputManager.GetMousePos(); var ip = content.InverseTransformPoint(mousePos); Vector3 pos = content.localPosition; bool move = false; if (!Mathf.Approximately(target, scale)) { // Only if necessary __instance.m_currentZoomScale = scale = Mathf.Lerp(scale, target, Mathf.Min(4.0f * Time.unscaledDeltaTime, 0.9f)); content.localScale = new Vector3(scale, scale, 1f); var fp = content.InverseTransformPoint(mousePos); if (!Mathf.Approximately(ip.x, fp.x) || !Mathf.Approximately(ip.y, fp.y) || !Mathf.Approximately(ip.z, fp.z)) { // If the point changed, center it correctly pos += (fp - ip) * scale; move = true; } } if (__instance.movingToTargetNISPosition) { move = true; NISMoveCore(__instance, scale, ref target, ref pos); __instance.m_targetZoomScale = target; } if (move) { content.localPosition = pos; } } return(false); }