added zlinq

This commit is contained in:
Sebastian Bularca
2026-04-02 07:43:33 +02:00
parent 81b8eadaf1
commit 36d3f112ef
52 changed files with 3430 additions and 17 deletions

View File

@@ -0,0 +1,110 @@
#nullable enable
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace ZLinq
{
[StructLayout(LayoutKind.Auto)]
public struct OfComponentT<TEnumerable, TComponent> : IValueEnumerator<TComponent>
where TEnumerable : struct, IValueEnumerator<Transform>
where TComponent : Component
{
TEnumerable source;
internal OfComponentT(TEnumerable source)
{
this.source = source;
}
public bool TryGetNonEnumeratedCount(out int count)
{
count = 0;
return false;
}
public bool TryGetSpan(out ReadOnlySpan<TComponent> span)
{
span = default;
return false;
}
public bool TryGetNext(out TComponent current)
{
while (source.TryGetNext(out var value))
{
var component = value.GetComponent<TComponent>();
if (component != null)
{
current = component;
return true;
}
}
current = default!;
return false;
}
public void Dispose()
{
source.Dispose();
}
public bool TryCopyTo(Span<TComponent> destination, Index offset)
{
return false;
}
}
[StructLayout(LayoutKind.Auto)]
public struct OfComponentG<TEnumerable, TComponent> : IValueEnumerator<TComponent>
where TEnumerable : struct, IValueEnumerator<GameObject>
where TComponent : Component
{
TEnumerable source;
internal OfComponentG(TEnumerable source)
{
this.source = source;
}
public bool TryGetNonEnumeratedCount(out int count)
{
count = 0;
return false;
}
public bool TryGetSpan(out ReadOnlySpan<TComponent> span)
{
span = default;
return false;
}
public bool TryGetNext(out TComponent current)
{
while (source.TryGetNext(out var value))
{
var component = value.GetComponent<TComponent>();
if (component != null)
{
current = component;
return true;
}
}
current = default!;
return false;
}
public void Dispose()
{
source.Dispose();
}
public bool TryCopyTo(Span<TComponent> destination, Index offset)
{
return false;
}
}
}