mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
pause timer if we fail to init or uninit
This commit is contained in:
parent
d47d0556e6
commit
c1be2e4d22
@ -150,7 +150,7 @@ namespace QSB.Syncs
|
||||
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
|
||||
if (IsInitialized)
|
||||
{
|
||||
this.Try("uninitializing (from object destroy)", Uninit);
|
||||
SafeUninit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,25 +158,49 @@ namespace QSB.Syncs
|
||||
{
|
||||
if (IsInitialized)
|
||||
{
|
||||
this.Try("uninitializing (from scene change)", Uninit);
|
||||
SafeUninit();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Init()
|
||||
private const float _pauseTimerDelay = 1;
|
||||
private float _pauseTimer;
|
||||
|
||||
private void SafeInit()
|
||||
{
|
||||
AttachedTransform = InitAttachedTransform();
|
||||
IsInitialized = true;
|
||||
this.Try("initializing", () =>
|
||||
{
|
||||
Init();
|
||||
IsInitialized = true;
|
||||
});
|
||||
if (!IsInitialized)
|
||||
{
|
||||
_pauseTimer = _pauseTimerDelay;
|
||||
}
|
||||
}
|
||||
|
||||
private void SafeUninit()
|
||||
{
|
||||
this.Try("uninitializing", () =>
|
||||
{
|
||||
Uninit();
|
||||
IsInitialized = false;
|
||||
IsValid = false;
|
||||
});
|
||||
if (IsInitialized)
|
||||
{
|
||||
_pauseTimer = _pauseTimerDelay;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Init() =>
|
||||
AttachedTransform = InitAttachedTransform();
|
||||
|
||||
protected virtual void Uninit()
|
||||
{
|
||||
if (IsPlayerObject && !hasAuthority && AttachedTransform)
|
||||
{
|
||||
Destroy(AttachedTransform.gameObject);
|
||||
}
|
||||
|
||||
IsInitialized = false;
|
||||
IsValid = false;
|
||||
}
|
||||
|
||||
private bool _shouldApply;
|
||||
@ -192,13 +216,20 @@ namespace QSB.Syncs
|
||||
|
||||
protected sealed override void Update()
|
||||
{
|
||||
if (_pauseTimer > 0)
|
||||
{
|
||||
_pauseTimer = Mathf.Max(0, _pauseTimer - Time.unscaledDeltaTime);
|
||||
base.Update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsInitialized && CheckReady())
|
||||
{
|
||||
this.Try("initializing", Init);
|
||||
SafeInit();
|
||||
}
|
||||
else if (IsInitialized && !CheckReady())
|
||||
{
|
||||
this.Try("uninitializing", Uninit);
|
||||
SafeUninit();
|
||||
base.Update();
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user