quantum-space-buddies/QSB/QSBNetworkManager.cs

53 lines
1.7 KiB
C#
Raw Normal View History

2020-02-21 23:36:07 +01:00
using QSB.Animation;
using QSB.TimeSync;
2020-02-21 23:36:07 +01:00
using QSB.TransformSync;
using UnityEngine;
2020-02-13 20:23:26 +01:00
using UnityEngine.Networking;
2020-02-15 20:48:02 +01:00
namespace QSB
{
public class QSBNetworkManager : NetworkManager
{
private const int MaxConnections = 128;
2020-02-21 23:36:07 +01:00
private AssetBundle _assetBundle;
private GameObject _shipPrefab;
2020-02-15 20:48:02 +01:00
private void Awake()
{
_assetBundle = QSB.Helper.Assets.LoadBundle("assets/network");
playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
2020-02-21 23:36:07 +01:00
playerPrefab.AddComponent<PlayerTransformSync>();
playerPrefab.AddComponent<AnimationSync>();
playerPrefab.AddComponent<WakeUpSync>();
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
_shipPrefab.AddComponent<ShipTransformSync>();
spawnPrefabs.Add(_shipPrefab);
maxConnections = MaxConnections;
customConfig = true;
connectionConfig.AddChannel(QosType.Reliable);
connectionConfig.AddChannel(QosType.Unreliable);
channels.Add(QosType.Reliable);
channels.Add(QosType.Unreliable);
}
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
base.OnServerAddPlayer(conn, playerControllerId);
NetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), conn);
2020-02-13 20:23:26 +01:00
}
2020-02-15 20:48:02 +01:00
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
2020-02-13 20:23:26 +01:00
DebugLog.Screen("OnClientConnect");
2020-02-13 21:23:12 +01:00
gameObject.AddComponent<SectorSync>();
2020-02-13 20:23:26 +01:00
}
2020-02-13 20:23:26 +01:00
}
}