public void OnLocalPlayerShipSpawned(PlayerShipController shipController) { Debug.Log("UIManager: received player ship spawn message"); double PlayerCurrentHealth = PlayerShipController.MAX_HEALTH; GameplayUiManager.LocalPlayerSetMaxHealth(PlayerCurrentHealth); SetCurrentPlayerHealth(PlayerCurrentHealth); TransitionToUIElements(UiElementTransitionType.Subtractive, UIElements.Respawn); TransitionToUIElements(UiElementTransitionType.Additive, UIElements.GameplayUI); }
private void playerShipSpawnedHandler(GameObject spawnedSpaceship) { MyContract.RequireArgumentNotNull( spawnedSpaceship, "Spawned Spaceship" ); Debug.Log("Player Ship spawn registered on this client"); ShipController = spawnedSpaceship.GetComponent<PlayerShipController>(); ShipController.EventDeath += ShipDestroyedClientAction; ShipController.EventHealthChanged += shipHealthChanged; }
private void localPlayerShipCreatedHandler(PlayerShipController ship_controller) { CameraRegistry.SetAllFollowTransforms(ship_controller.transform); }
private void SpawnSpaceShip(SpaceShipClass spaceShipType) { lock (SpaceshipSpawnLock) { if (ShipSpawned) { Debug.LogWarning(ShipAlreadySpawnedWarning); return; } MyContract.RequireArgument( spaceShipType != SpaceShipClass.NONE, "is not NONE", "spaceShipType" ); MyContract.RequireFieldNotNull( SpaceshipClassManager, "Spaceship Class Manager" ); GameObject SpaceshipPrefab = SpaceshipClassManager.getSpaceShipPrefab(spaceShipType); MyContract.RequireFieldNotNull(SpaceshipPrefab, "Spaceship Prefab"); // Should not remain null unless Unity.Instantiate can return null GameObject ServerSpaceship = null; if (CurrentSpaceship != null && ShipController.getSpaceshipClass() == spaceShipType) { // current_spaceship was just despawned, not destroyed, // so it simply needs to be respawned ServerSpaceship = CurrentSpaceship; ServerSpaceship.SetActive(true); MyContract.RequireFieldNotNull( ShipController, "ShipController" ); ShipController.Respawn(); } else { // Create the ship locally (local to the server) // NB: the ship will be moved to an appropriate NetworkStartPosition // by the server so the location specified here is irrelevant ServerSpaceship = (GameObject)Instantiate( SpaceshipPrefab, transform.TransformPoint(chooseSpawnLocation()), transform.rotation); ShipController = ServerSpaceship.GetComponent<PlayerShipController>(); ShipController.SetSpaceshipClass(spaceShipType); ShipController.owner = PlayerIdentifier.CreateNew(this); ShipController.EventDeath += ShipDestroyedServerAction; } MyContract.RequireFieldNotNull( ServerSpaceship, "Server Spaceship" ); CanRespawn = false; ShipSpawned = true; // Spawn the ship on the clients NetworkServer.SpawnWithClientAuthority( ServerSpaceship, connectionToClient ); CurrentSpaceship = ServerSpaceship; // Update [SyncVar] RpcPlayerShipSpawned(CurrentSpaceship); } }