您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

53 行
1.2 KiB

using UnityEngine;
namespace MetaCity.Core.Common
{
public abstract class MustCallDestroy
{
private bool _destroyCalled;
private readonly bool _hasBeenConstructed;
protected MustCallDestroy()
{
_hasBeenConstructed = true;
}
~MustCallDestroy()
{
if (!_hasBeenConstructed || _destroyCalled || !ActuallyNeedsDestroyCalled()) return;
ReportError();
}
public void RestoreFromSave()
{
}
protected virtual bool ActuallyNeedsDestroyCalled()
{
return true;
}
private void ReportError()
{
var toString = ToString();
var type = GetType().FullName;
ThreadingUtils.EnqueueActionForMainThreadOrRunRightNow(() =>
{
Debug.LogError($"Destroy hasn't been called on {toString}: {type}");
});
}
public virtual void Destroy()
{
_destroyCalled = true;
}
public bool HasBeenDestroyed()
{
return _destroyCalled;
}
}
}