modular-avatar/Runtime/ArmatureAwase/DeferDestroy.cs
bd_ f6ac07e1cd
opti: perf improvements for armature lock (#714)
* opti: perf improvements for armature lock

* chore: unity 2019 compatibility

* chore: update comments
2024-03-03 17:34:48 +09:00

40 lines
813 B
C#

#region
using System;
using UnityEditor;
#endregion
namespace nadena.dev.modular_avatar.core.armature_lock
{
internal static class DeferDestroy
{
private static bool _immediate = false;
internal static void DestroyImmediate(IDisposable obj)
{
var oldValue = _immediate;
_immediate = true;
try
{
obj.Dispose();
}
finally
{
_immediate = oldValue;
}
}
internal static void DeferDestroyObj(IDisposable obj)
{
if (_immediate)
{
obj.Dispose();
return;
}
#if UNITY_EDITOR
EditorApplication.delayCall += () => obj.Dispose();
#endif
}
}
}