Custom network manager

This commit is contained in:
Ricardo Lopes 2020-02-13 20:23:26 +01:00
parent bcfa41b26b
commit 65c8943bd8
6 changed files with 43 additions and 10 deletions

View File

@ -9,11 +9,7 @@ namespace QSB {
public static NetworkPlayer localInstance { get; private set; }
void Start () {
if (isLocalPlayer) {
QSB.LogToScreen("Started LOCAL network player", netId.Value);
} else {
QSB.LogToScreen("Started REMOTE network player", netId.Value);
}
QSB.Log("Start NetworkPlayer", netId.Value);
QSB.playerSectors[netId.Value] = Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform;
transform.parent = Locator.GetRootTransform();
@ -35,7 +31,6 @@ namespace QSB {
} else {
NetworkManager.singleton.client.RegisterHandler(SectorMessage.Type, QSB.OnReceiveMessage);
}
}
public void EnterSector (Sector sector) {

View File

@ -26,10 +26,14 @@ namespace QSB {
playerSectors = new Dictionary<uint, Transform>();
var assetBundle = ModHelper.Assets.LoadBundle("assets/network");
var networkManager = Instantiate(assetBundle.LoadAsset<GameObject>("assets/networkmanager.prefab"));
//var networkManager = Instantiate(assetBundle.LoadAsset<GameObject>("assets/networkmanager.prefab"));
var networkPlayerPrefab = assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
networkPlayerPrefab.AddComponent<NetworkPlayer>();
networkManager.GetComponent<NetworkManager>().playerPrefab = networkPlayerPrefab;
var networkManager = gameObject.AddComponent<QSBNetworkManager>();
networkManager.playerPrefab = networkPlayerPrefab;
gameObject.AddComponent<NetworkManagerHUD>();
ModHelper.HarmonyHelper.AddPrefix<PlayerSectorDetector>("OnAddSector", typeof(Patches), "OnAddSector");
}
@ -47,6 +51,11 @@ namespace QSB {
}
public static void LogToScreen (params object[] logObjects) {
if (Locator.GetPlayerBody() == null) {
Log("Warning: tried to log to HUD but player is not ready.");
Log(logObjects);
return;
}
NotificationData data = new NotificationData(NotificationTarget.Player, JoinAll(logObjects), 5f, true);
NotificationManager.SharedInstance.PostNotification(data, false);
}

View File

@ -78,10 +78,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="QSBNetworkManager.cs" />
<Compile Include="SectorMessage.cs" />
<Compile Include="QSB.cs" />
<Compile Include="NetworkPlayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SectorSync.cs" />
</ItemGroup>
<ItemGroup>
<None Include="default-config.json" />
@ -100,6 +102,6 @@ copy /y "$(ProjectDir)\default-config.json" "$(StartWorkingDirectory)"
copy /y "$(ProjectDir)\manifest.json" "$(StartWorkingDirectory)"
copy /y "$(ProjectDir)\Assets" "$(StartWorkingDirectory)"</PostBuildEvent>
copy /y "$(ProjectDir)\Assets" "$(StartWorkingDirectory)\assets"</PostBuildEvent>
</PropertyGroup>
</Project>

18
QSB/QSBNetworkManager.cs Normal file
View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.Networking;
namespace QSB {
class QSBNetworkManager: NetworkManager {
void Awake () {
}
public override void OnClientConnect (NetworkConnection conn) {
base.OnClientConnect(conn);
QSB.Log("OnClientConnect");
}
}
}

9
QSB/SectorSync.cs Normal file
View File

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB {
class SectorSync {
}
}

View File

@ -1,5 +1,5 @@
{
"filename": "QuantumSpaceBuddies.dll",
"filename": "QSB.dll",
"author": "Raicuparta",
"name": "QuantumSpaceBuddies",
"uniqueName": "Raicuparta.QuantumSpaceBuddies",