2024-02-18 20:56:59 +08:00
|
|
|
|
#region
|
|
|
|
|
|
|
|
|
|
using System;
|
2024-03-03 16:34:48 +08:00
|
|
|
|
using UnityEditor;
|
2024-02-18 20:56:59 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core.armature_lock
|
|
|
|
|
{
|
|
|
|
|
internal static class DeferDestroy
|
|
|
|
|
{
|
2024-02-26 17:03:16 +08:00
|
|
|
|
private static bool _immediate = false;
|
|
|
|
|
|
|
|
|
|
internal static void DestroyImmediate(IDisposable obj)
|
|
|
|
|
{
|
|
|
|
|
var oldValue = _immediate;
|
|
|
|
|
_immediate = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
obj.Dispose();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_immediate = oldValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 20:56:59 +08:00
|
|
|
|
internal static void DeferDestroyObj(IDisposable obj)
|
|
|
|
|
{
|
2024-02-26 17:03:16 +08:00
|
|
|
|
if (_immediate)
|
|
|
|
|
{
|
|
|
|
|
obj.Dispose();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-18 20:56:59 +08:00
|
|
|
|
#if UNITY_EDITOR
|
2024-03-03 16:34:48 +08:00
|
|
|
|
EditorApplication.delayCall += () => obj.Dispose();
|
2024-02-18 20:56:59 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|