fix: added Queue.TryDequeue extension for Unity 2019

This commit is contained in:
vis2k 2022-04-01 17:18:12 +08:00
parent 6c2559a73e
commit 3d471db938

View File

@ -38,5 +38,20 @@ public static void CopyTo<T>(this IEnumerable<T> source, List<T> destination)
// foreach allocates. use AddRange.
destination.AddRange(source);
}
#if !UNITY_2020_1_OR_NEWER
// Unity 2019 doesn't have Queue.TryDeque which we need for batching.
public static bool TryDequeue<T>(this Queue<T> source, out T element)
{
if (source.Count > 0)
{
element = source.Dequeue();
return true;
}
element = default;
return false;
}
#endif
}
}