private IEnumerator ArriveFromHyperspaceJump(HyperspaceJump jump) { gameLog.AddMessage($"Arriving in system {jump.toSystem}."); Instantiate(hyperspaceArrivalPrefab); hyperspaceJumpInSound.Play(); rigidbody.velocity = Vector3.zero; rigidbody.rotation = Quaternion.Euler(-90, 0, 0); rigidbody.position = new Vector3(0, -HyperspaceArrivalPositionOffset, HyperspaceEntryZPosition); // Returning thrust is applied in the opposite direction of going out (though we don't render that way, because it Looks Dumb) Quaternion returnAngle = Quaternion.Euler(HyperspaceEntryZAngle, 180, 180); while (rigidbody.position.z > 0) { yield return(new WaitForFixedUpdate()); rigidbody.AddForce(returnAngle * Vector3.forward * ThrustForce); } rigidbody.velocity = Vector3.Project(rigidbody.velocity, Vector3.up); rigidbody.position = Vector3.Project(rigidbody.position, Vector3.up); rigidbody.constraints = DefaultRigidbodyConstraints; StopEngineGlow(); inputs.Player.Enable(); CmdFinishedArrivingFromHyperspaceJump(jump); }
private IEnumerator PrepareForHyperspaceJumpThenNotifyServer(HyperspaceJump jump) { inputs.Player.Disable(); // Disable constraints while animating for hyperspace, as we will now move into the Z axis. rigidbody.constraints = RigidbodyConstraints.None; Quaternion targetRotation = Quaternion.Euler(HyperspaceEntryZAngle, 0, 0); while (!rigidbody.rotation.ApproximatelyEquals(targetRotation, HyperspaceRotationTolerance)) { yield return(new WaitForFixedUpdate()); rigidbody.MoveRotation(Quaternion.RotateTowards(rigidbody.rotation, targetRotation, RotationSpeed * Time.deltaTime)); } StartEngineGlow(); hyperspaceJumpOutSound.Play(); while (rigidbody.transform.position.z < HyperspaceEntryZPosition) { yield return(new WaitForFixedUpdate()); rigidbody.AddRelativeForce(Vector3.forward * ThrustForce); } CmdReadyForHyperspaceJump(); }
private void CmdStartHyperspaceJump(HyperspaceJump jump) { if (inProgressHyperspaceJump != null) { Debug.Log($"Hyperspace jump for {this} already in progress: {inProgressHyperspaceJump}"); return; } if (jump.fromSystem != gameObject.scene.name) { Debug.LogError($"Client requested hyperspace jump from system {jump.fromSystem}, but player is in {gameObject.scene.name}"); return; } inProgressHyperspaceJump = new InProgressHyperspaceJump(jump); TargetPrepareForHyperspaceJump(jump); // In host mode, the target scene should already be loaded. if (isLocalPlayer) { MoveToScene(SceneManager.GetSceneByName(jump.toSystem)); } else { connectionToClient.Send(new SceneMessage { sceneName = jump.toSystem, sceneOperation = SceneOperation.LoadAdditive, customHandling = true }); } }
private void CmdFinishedArrivingFromHyperspaceJump(HyperspaceJump jump) { // Don't unload any scenes in host mode if (!isLocalPlayer) { connectionToClient.Send(new SceneMessage { sceneName = jump.fromSystem, sceneOperation = SceneOperation.UnloadAdditive, customHandling = true }); } }
private void FinishHyperspaceJumpIfReady() { if (!inProgressHyperspaceJump.clientPlayerReady || !inProgressHyperspaceJump.clientSceneLoaded) { return; } HyperspaceJump jump = inProgressHyperspaceJump.jump; Scene scene = SceneManager.GetSceneByName(jump.toSystem); Debug.Assert(scene.IsValid() && scene.isLoaded, $"Scene for hyperspace jump {jump} is invalid"); // This needs to be cleared before MoveToScene, because it calls back into this method otherwise. inProgressHyperspaceJump = null; MoveToScene(scene); TargetArriveFromHyperspaceJump(jump); }
private void StartHyperspaceJumpFromMapSelection() { if (inProgressHyperspaceJump != null) { Debug.Log($"Hyperspace jump for {this} already in progress: {inProgressHyperspaceJump}"); return; } var selectedSystem = uiController.galaxyMap.selectedSystem; if (selectedSystem == null) { gameLog.AddMessage("Cannot jump to hyperspace, no system selected. Press M to view the map."); return; } var jump = new HyperspaceJump(gameObject.scene.name, selectedSystem.name); Debug.Log($"Requesting hyperspace jump {jump}"); CmdStartHyperspaceJump(jump); }
private void TargetArriveFromHyperspaceJump(HyperspaceJump jump) { StartCoroutine(ArriveFromHyperspaceJump(jump)); }
private void TargetPrepareForHyperspaceJump(HyperspaceJump jump) { gameLog.AddMessage($"Beginning hyperspace jump to system {jump.toSystem}."); StartCoroutine(PrepareForHyperspaceJumpThenNotifyServer(jump)); }
public InProgressHyperspaceJump(HyperspaceJump jump) { this.jump = jump; }