mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 14:00:17 +00:00
0445f29dfd
* Updated SyncDictionary usage in SyncedBag.cs - Removed the extra class that is no longer needed for SyncDictionary's - Removed OP codes (OP_DIRTY) switch case that no longer exists (superseded by OP_SET) Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Updated method names Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Updated more string sync dictionaries Ped_Networking.cs VehicleController.cs Player.cs SyncedServerData.cs Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Updated NetworkTime fields in NetStats.cs Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Updated syncData types Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Implemented conditional compilation to replace old isHeadless Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com> * Updated hooks * A few more syncDictionary upgrades * Moved away from obsolete NetworkIdentity.spawned * Updated SetDirtyBit to SetSyncVarDirtyBit in DeadBody.cs * Updated ScriptingDefineSymbols for Mirror * Updated JoinGameWindow.cs * Use latest MirrorLite commit for submodule * Use latest MirrorLite commit for submodule * Reverted EditorSettings.asset to commitb1c9d38e3a
* Reverted JoinGameWindow.cs to commitb1c9d38e3a
* Changed method for headless mode in NetCmdLineHandler.cs Changed from compiler defs to SanAndreasUnity helpers for determining headless mode in NetCmdLineHandler.cs * Re-Added ConfigureHeadlessFrameRate override on CustomNetworkManager.cs * Started updating JoinGameWindow.cs - Commented out GUI errors - Updated type 'DiscoveryInfo' to 'ServerResponse' in method ConnectFromDiscovery() params. - Updated Connect() 'port' parameter to use type 'int' rather than 'ushort' as per Mirror conventions. Co-authored-by: Lukas Olson <lukasolson@greyblockgames.com>
63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using Mirror;
|
|
using SanAndreasUnity.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace SanAndreasUnity.Net
|
|
{
|
|
public class SyncedServerData : NetworkBehaviour
|
|
{
|
|
public static SyncedServerData Instance { get; private set; }
|
|
|
|
readonly SyncDictionary<string, string> _syncDictionary = new SyncDictionary<string, string>();
|
|
|
|
public static SyncedBag Data { get; private set; } = new SyncedBag(new SyncDictionary<string, string>());
|
|
|
|
public static event System.Action onInitialSyncDataAvailable = delegate {};
|
|
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null)
|
|
{
|
|
Debug.LogError($"{nameof(SyncedServerData)} object already exists. There should only be 1.");
|
|
Destroy(this.gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
|
|
var oldData = Data;
|
|
|
|
if (NetStatus.IsServer)
|
|
{
|
|
var newData = new SyncedBag(_syncDictionary);
|
|
newData.SetData(oldData);
|
|
newData.SetCallbacks(oldData);
|
|
|
|
Data = newData;
|
|
}
|
|
else
|
|
{
|
|
var newData = new SyncedBag(_syncDictionary);
|
|
newData.SetCallbacks(oldData);
|
|
Data = newData;
|
|
}
|
|
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
// clear data for next server start
|
|
Data = new SyncedBag(new SyncDictionary<string, string>());
|
|
}
|
|
|
|
public override void OnStartClient()
|
|
{
|
|
if (NetStatus.IsServer)
|
|
return;
|
|
|
|
F.InvokeEventExceptionSafe(onInitialSyncDataAvailable);
|
|
}
|
|
}
|
|
}
|