protected override PlayerInfo CreatePlayer(byte id, bool local = false) { var ply = base.CreatePlayer(id, local); ply.PlayerObject = NetworkManager.CreatePlayer(ply, local); return(ply); }
protected override void OnLevelLoaded(string level) { if (!PlayerId.HasValue) { // If the scene was open in editor, this method gets called before we have actually joined the local // server. If this bool is set to true, LevelLoaded is called again once server has sent its // welcome packet. preloadedLevel = true; return; } Loaded = true; CreatePlayer(PlayerId.Value, true); if (Players != null) { foreach (var pl in Players) { if (pl == null || pl.Id == PlayerId.Value) { continue; } pl.PlayerObject = NetworkManager.CreatePlayer(pl); } } Debug.Assert(PlayerId != null, nameof(PlayerId) + " != null"); // Send our chosen player name and a random color to identify us. var info = new PlayerPreferences { playerId = PlayerId.Value, name = Preferences.Name, color = Random.ColorHSV(0, 1f, 0.3f, 1f, 0.5f, 1f), modelId = (byte)Random.Range(0, 3) }; Send(info, NetDeliveryMethod.ReliableUnordered); OnPlayerSentPreferences(info); CreateServerPlayers(); base.OnLevelLoaded(level); }