use prefab template to make network objects

This commit is contained in:
JohnCorby 2021-12-04 17:44:21 -08:00
parent 2bce5b5e3b
commit 41af623ded
4 changed files with 34 additions and 28 deletions

Binary file not shown.

View File

@ -1,12 +1,12 @@
ManifestFileVersion: 0 ManifestFileVersion: 0
CRC: 2906651145 CRC: 1208921857
Hashes: Hashes:
AssetFileHash: AssetFileHash:
serializedVersion: 2 serializedVersion: 2
Hash: 0fa5758f55c8803c7ba77a52ab2c9488 Hash: e6fb281706df372893c7d91213b2598a
TypeTreeHash: TypeTreeHash:
serializedVersion: 2 serializedVersion: 2
Hash: 87b5c87f221cc0cbe8c4eefab7d02419 Hash: 91770441465e7cb2442c311d5ad605d6
HashAppended: 0 HashAppended: 0
ClassTypes: ClassTypes:
- Class: 1 - Class: 1
@ -17,8 +17,6 @@ ClassTypes:
Script: {fileID: -1208705890, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3} Script: {fileID: -1208705890, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3}
- Class: 114 - Class: 114
Script: {fileID: 1142416158, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3} Script: {fileID: 1142416158, guid: 8929207a0d76fd54a8a2a820c652720f, type: 3}
- Class: 114
Script: {fileID: 519208029, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
Script: {fileID: -790547616, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: -790547616, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
@ -29,18 +27,10 @@ ClassTypes:
Script: {fileID: -1164351254, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: -1164351254, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
Script: {fileID: -1309757293, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: -1309757293, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114
Script: {fileID: 316226861, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
Script: {fileID: 78926581, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: 78926581, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114
Script: {fileID: -1381557116, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114
Script: {fileID: -1937550126, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
Script: {fileID: -749020886, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: -749020886, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114
Script: {fileID: -2281650, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
Script: {fileID: 677635994, guid: 27687deae413b90448366870cb0de502, type: 3} Script: {fileID: 677635994, guid: 27687deae413b90448366870cb0de502, type: 3}
- Class: 114 - Class: 114
@ -49,10 +39,6 @@ ClassTypes:
Script: {instanceID: 0} Script: {instanceID: 0}
SerializeReferenceClassIdentifiers: [] SerializeReferenceClassIdentifiers: []
Assets: Assets:
- Assets/Prefabs/NetworkJellyfish.prefab - Assets/Prefabs/NetworkObject.prefab
- Assets/Prefabs/NetworkProbe.prefab
- Assets/Prefabs/NETWORK_Player_Body.prefab - Assets/Prefabs/NETWORK_Player_Body.prefab
- Assets/Prefabs/NetworkOrb.prefab
- Assets/Prefabs/NetworkAngler.prefab
- Assets/Prefabs/NetworkShip.prefab
Dependencies: [] Dependencies: []

View File

@ -69,7 +69,7 @@ namespace QSB
public static bool ShowQuantumDebugBoxes => DebugMode && DebugSettings.ShowQuantumDebugBoxes; public static bool ShowQuantumDebugBoxes => DebugMode && DebugSettings.ShowQuantumDebugBoxes;
public static bool AvoidTimeSync => DebugMode && DebugSettings.AvoidTimeSync; public static bool AvoidTimeSync => DebugMode && DebugSettings.AvoidTimeSync;
public static bool SkipTitleScreen => DebugMode && DebugSettings.SkipTitleScreen; public static bool SkipTitleScreen => DebugMode && DebugSettings.SkipTitleScreen;
public static AssetBundle NetworkAssetBundle { get; private set; } public static AssetBundle NetworkAssetBundle { get; internal set; }
public static AssetBundle InstrumentAssetBundle { get; private set; } public static AssetBundle InstrumentAssetBundle { get; private set; }
public static AssetBundle ConversationAssetBundle { get; private set; } public static AssetBundle ConversationAssetBundle { get; private set; }
public static AssetBundle DebugAssetBundle { get; private set; } public static AssetBundle DebugAssetBundle { get; private set; }

View File

@ -2,10 +2,12 @@
using System.Linq; using System.Linq;
using OWML.Common; using OWML.Common;
using OWML.Utils; using OWML.Utils;
using QSB.Anglerfish.TransformSync;
using QSB.AuthoritySync; using QSB.AuthoritySync;
using QSB.ClientServerStateSync; using QSB.ClientServerStateSync;
using QSB.DeathSync; using QSB.DeathSync;
using QSB.Events; using QSB.Events;
using QSB.JellyfishSync.TransformSync;
using QSB.OrbSync.TransformSync; using QSB.OrbSync.TransformSync;
using QSB.Patches; using QSB.Patches;
using QSB.Player; using QSB.Player;
@ -13,6 +15,8 @@ using QSB.Player.TransformSync;
using QSB.PoolSync; using QSB.PoolSync;
using QSB.ShipSync.TransformSync; using QSB.ShipSync.TransformSync;
using QSB.TimeSync; using QSB.TimeSync;
using QSB.Tools.ProbeTool.TransformSync;
using QSB.TornadoSync.TransformSync;
using QSB.Utility; using QSB.Utility;
using QSB.WorldSync; using QSB.WorldSync;
using QuantumUNET; using QuantumUNET;
@ -42,7 +46,6 @@ namespace QSB
private const int MaxConnections = 128; private const int MaxConnections = 128;
private const int MaxBufferedPackets = 64; private const int MaxBufferedPackets = 64;
private AssetBundle _assetBundle;
private GameObject _probePrefab; private GameObject _probePrefab;
private bool _everConnected; private bool _everConnected;
@ -52,26 +55,25 @@ namespace QSB
Instance = this; Instance = this;
PlayerName = GetPlayerName(); PlayerName = GetPlayerName();
_assetBundle = QSBCore.NetworkAssetBundle;
playerPrefab = _assetBundle.LoadAsset<GameObject>("Assets/Prefabs/NETWORK_Player_Body.prefab"); playerPrefab = QSBCore.NetworkAssetBundle.LoadAsset<GameObject>("Assets/Prefabs/NETWORK_Player_Body.prefab");
ShipPrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkship.prefab"); ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync));
spawnPrefabs.Add(ShipPrefab); spawnPrefabs.Add(ShipPrefab);
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkprobe.prefab"); _probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync));
spawnPrefabs.Add(_probePrefab); spawnPrefabs.Add(_probePrefab);
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkorb.prefab"); OrbPrefab = MakeNewNetworkObject(4, "NetworkOrb", typeof(NomaiOrbTransformSync));
spawnPrefabs.Add(OrbPrefab); spawnPrefabs.Add(OrbPrefab);
AnglerPrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkangler.prefab"); AnglerPrefab = MakeNewNetworkObject(5, "NetworkAngler", typeof(AnglerTransformSync));
spawnPrefabs.Add(AnglerPrefab); spawnPrefabs.Add(AnglerPrefab);
JellyfishPrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkjellyfish.prefab"); JellyfishPrefab = MakeNewNetworkObject(6, "NetworkJellyfish", typeof(JellyfishTransformSync));
spawnPrefabs.Add(JellyfishPrefab); spawnPrefabs.Add(JellyfishPrefab);
OccasionalPrefab = _assetBundle.LoadAsset<GameObject>("assets/Prefabs/networkoccasional.prefab"); OccasionalPrefab = MakeNewNetworkObject(7, "NetworkOccasional", typeof(OccasionalTransformSync));
spawnPrefabs.Add(OccasionalPrefab); spawnPrefabs.Add(OccasionalPrefab);
ConfigureNetworkManager(); ConfigureNetworkManager();
@ -94,6 +96,24 @@ namespace QSB
} }
} }
/// create a new network prefab from the network object prefab template.
/// this works by calling Unload(false) and then reloading the AssetBundle,
/// which makes LoadAsset give you a new resource.
/// see https://docs.unity3d.com/Manual/AssetBundles-Native.html.
private static GameObject MakeNewNetworkObject(int assetId, string name, Type transformSyncType)
{
QSBCore.NetworkAssetBundle.Unload(false);
QSBCore.NetworkAssetBundle = QSBCore.Helper.Assets.LoadBundle("AssetBundles/network");
var template = QSBCore.NetworkAssetBundle.LoadAsset<GameObject>("Assets/Prefabs/NetworkObject.prefab");
DebugLog.DebugWrite($"MakeNewNetworkObject - prefab id {template.GetInstanceID()} "
+ $"for {assetId} {name} {transformSyncType.Name}");
template.name = name;
template.GetRequiredComponent<QNetworkIdentity>().SetValue("m_AssetId", assetId);
template.AddComponent(transformSyncType);
return template;
}
private void ConfigureNetworkManager() private void ConfigureNetworkManager()
{ {
networkAddress = QSBCore.DefaultServerIP; networkAddress = QSBCore.DefaultServerIP;