Custom network manager configures itself

This commit is contained in:
Ricardo Lopes 2020-02-13 20:34:51 +01:00
parent 65c8943bd8
commit e454653c29
2 changed files with 10 additions and 15 deletions

View File

@ -6,6 +6,7 @@ using UnityEngine.Networking;
namespace QSB { namespace QSB {
public class QSB: ModBehaviour { public class QSB: ModBehaviour {
public static IModHelper Helper;
static QSB _instance; static QSB _instance;
public static Dictionary<uint, Transform> playerSectors; public static Dictionary<uint, Transform> playerSectors;
@ -22,17 +23,11 @@ namespace QSB {
void Start () { void Start () {
_instance = this; _instance = this;
Helper = ModHelper;
playerSectors = new Dictionary<uint, Transform>(); playerSectors = new Dictionary<uint, Transform>();
var assetBundle = ModHelper.Assets.LoadBundle("assets/network"); gameObject.AddComponent<QSBNetworkManager>();
//var networkManager = Instantiate(assetBundle.LoadAsset<GameObject>("assets/networkmanager.prefab"));
var networkPlayerPrefab = assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
networkPlayerPrefab.AddComponent<NetworkPlayer>();
var networkManager = gameObject.AddComponent<QSBNetworkManager>();
networkManager.playerPrefab = networkPlayerPrefab;
gameObject.AddComponent<NetworkManagerHUD>(); gameObject.AddComponent<NetworkManagerHUD>();
ModHelper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "OnAddSector"); ModHelper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "OnAddSector");

View File

@ -1,18 +1,18 @@
using System; using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.Networking; using UnityEngine.Networking;
namespace QSB { namespace QSB {
class QSBNetworkManager: NetworkManager { class QSBNetworkManager: NetworkManager {
void Awake () { void Awake () {
var assetBundle = QSB.Helper.Assets.LoadBundle("assets/network");
playerPrefab = assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
playerPrefab.AddComponent<NetworkPlayer>();
} }
public override void OnClientConnect (NetworkConnection conn) { public override void OnStartClient (NetworkClient client) {
base.OnClientConnect(conn); base.OnStartClient(client);
QSB.Log("OnClientConnect"); QSB.Log("start client");
} }
} }
} }