mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-30 07:50:22 +00:00
46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using SanAndreasUnity.Utilities;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace SanAndreasUnity.Net
|
|
{
|
|
public class SyncedServerDataObjectSpawner : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject m_syncedServerDataPrefab = null;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
m_syncedServerDataPrefab.GetComponentOrLogError<SyncedServerData>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
NetManager.Instance.onServerStatusChanged += OnServerStatusChanged;
|
|
SceneManager.activeSceneChanged += OnActiveSceneChanged;
|
|
}
|
|
|
|
private void OnServerStatusChanged()
|
|
{
|
|
// scene is not changed yet, so the object will get destroyed when it changes
|
|
//Spawn();
|
|
}
|
|
|
|
private void OnActiveSceneChanged(Scene arg0, Scene arg1)
|
|
{
|
|
Spawn();
|
|
}
|
|
|
|
private void Spawn()
|
|
{
|
|
if (!NetStatus.IsServer)
|
|
return;
|
|
|
|
if (null != SyncedServerData.Instance)
|
|
return;
|
|
|
|
var go = Instantiate(m_syncedServerDataPrefab);
|
|
NetManager.Spawn(go);
|
|
}
|
|
}
|
|
}
|