Client spawning fix
This commit is contained in:
@@ -92,6 +92,17 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
private SpawnFragment spawnFragment;
|
||||
|
||||
private IEnumerator _CheckAutoSyncCo()
|
||||
{
|
||||
yield return null;
|
||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
||||
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
||||
{
|
||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||
RegisterSyncable();
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
@@ -99,12 +110,7 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
FindComponents();
|
||||
|
||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
||||
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
||||
{
|
||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||
RegisterSyncable();
|
||||
}
|
||||
MelonCoroutines.Start(_CheckAutoSyncCo());
|
||||
}
|
||||
|
||||
public bool CheckIfShouldAutoSync()
|
||||
@@ -156,26 +162,49 @@ namespace BoneSync.Sync.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
DiscardSyncable();
|
||||
//MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
}
|
||||
|
||||
public void DiscardSyncable()
|
||||
private void _DiscardSyncable(bool force)
|
||||
{
|
||||
if (Registered)
|
||||
{
|
||||
MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath());
|
||||
MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
||||
if (!force) return;
|
||||
}
|
||||
syncablesCache.Remove(gameObject);
|
||||
ObjectSyncCache.RemoveSyncable(this);
|
||||
Destroy(this);
|
||||
Destroy(this); // delete the component
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (Registered)
|
||||
{
|
||||
MelonLogger.Warning("Destroying registered syncable: " + transform.GetPath());
|
||||
}
|
||||
_DiscardSyncable(true);
|
||||
//MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
}
|
||||
|
||||
private IEnumerator _FlagForDiscardCo(bool force)
|
||||
{
|
||||
yield return null;
|
||||
_DiscardSyncable(force);
|
||||
}
|
||||
|
||||
public void DiscardSyncable(bool force = false)
|
||||
{
|
||||
MelonCoroutines.Start(_FlagForDiscardCo(force));
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
DiscardSyncable();
|
||||
if (Registered && !isOwner)
|
||||
{
|
||||
MelonLogger.Warning("tried to disable non-owner syncable: " + transform.GetPath());
|
||||
gameObject.SetActive(true);
|
||||
} else
|
||||
{
|
||||
DiscardSyncable();
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterSyncable()
|
||||
|
||||
Reference in New Issue
Block a user