public void SpawnPlayer(NetworkConnection conn, short playerControllerId, Utils.PlayerType type) { GameObject prefab = null; switch (type) { case Utils.PlayerType.HoloLens: prefab = holoLensPlayerPrefab; break; case Utils.PlayerType.VR: prefab = vrPlayerPrefab; break; } if (!prefab) { Debug.LogError("Unspawnable player type for client: " + type.ToString()); return; } Debug.Log("Spawning a " + type.ToString() + " player."); GameObject player = Instantiate(prefab, playersContainer.transform); player.GetComponent <PlayerController>().alignmentManagerObject = alignmentManager.gameObject; NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); player.GetComponent <PlayerController>().RpcPlayerIsInitialized(); }
/// <summary> /// Spawns a new network player and sets him up (Runs on server side) /// </summary> /// <param name="conn">Connection from where the original message came from</param> /// <param name="playerControllerId">ID for identifying the playerController</param> /// <param name="playerType">Type of the player (VR or HoloLens)</param> /// <param name="alignmentPosition">Offset Position for Hololens (equals the Markerposition in the HoloLens coordinate system)</param> /// <param name="alignmentRotation">Offset Rotation for HoloLens (equals the Markerrotation in the HoloLens coordinate system)</param> public void SpawnPlayer(NetworkConnection conn, short playerControllerId, Utils.PlayerType playerType, Vector3 alignmentPosition, float alignmentRotation, string localPlayerName) { Debug.Log("Spawning a " + playerType.ToString() + " player."); var _alignmentTranslation = playerType == Utils.PlayerType.HoloLens ? alignmentPosition : playersContainer.transform.position; var _alignmentRotation = playerType == Utils.PlayerType.HoloLens ? alignmentRotation : playersContainer.transform.rotation.eulerAngles.y; GameObject player = Instantiate(networkPlayer, playersContainer.transform); NetworkServer.AddPlayerForConnection(conn, player, playerCounter); player.GetComponent <NetworkPlayer>().RpcSetupPlayer(_alignmentTranslation, _alignmentRotation, playerType, playerCounter, MarkerOffset.position, localPlayerName); player.GetComponent <NetworkPlayer>().PlayerName = localPlayerName; if (playerType == Utils.PlayerType.HoloLens) { playerCounter++; } }