protected async override void HandleRespawnPlayer(Entity ent) { if (PinouNetworkManager.IsServer == false) { return; } NetworkConnection conn = (ent as EntityNet).References.NetworkIdentity.connectionToClient; await Task.Delay(2000); Vector3 spawnPos = default; if (PinouApp.Entity.Players.Length > 0) { float randAngle = Random.Range(0f, Mathf.PI * 2f); Vector3 offset = new Vector3(Mathf.Cos(randAngle), Mathf.Sin(randAngle)) * 3f; if (PinouApp.Entity.Mode2D == false) { offset = offset.SwapYZ(); } spawnPos = PinouApp.Entity.Players.Random().Position + offset; } EntityNet newPlayer = (EntityNet)CreateEntity(PinouApp.Resources.Data.Entities.PlayerModel, spawnPos, default); newPlayer.GetComponent <NetworkIdentity>().AssignClientAuthority(conn); if (conn == NetworkServer.localConnection) { SetLocalPlayer(newPlayer); } else { PinouNetworkManager.EntityBehaviour.TargetSetLocalPlayer(conn, newPlayer.gameObject); } }
private void OnTargetAddPlayer(NetworkConnection conn, GameObject playerPrefab) { EntityNet ent = playerPrefab.GetComponent <EntityNet>(); RegisterEntity(ent); SetLocalPlayer(ent); }
public void SetLocalPlayer(EntityNet newPlayer) { localPlayer = newPlayer; OnLocalPlayerAssigned.Invoke(newPlayer); }