mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-27 06:20:17 +00:00
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using Mirror;
|
|
using UnityEngine;
|
|
|
|
namespace SanAndreasUnity.Net
|
|
{
|
|
public class SyncedServerData : NetworkBehaviour
|
|
{
|
|
public static SyncedServerData Instance { get; private set; }
|
|
|
|
SyncedBag.StringSyncDictionary _syncDictionary = new SyncedBag.StringSyncDictionary();
|
|
|
|
public static SyncedBag Data { get; private set; } = new SyncedBag(new SyncedBag.StringSyncDictionary());
|
|
|
|
|
|
|
|
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 SyncedBag.StringSyncDictionary());
|
|
}
|
|
}
|
|
}
|