rokojori_action_library/Runtime/Godot/Extensions/ArrayExtensions.cs

45 lines
1015 B
C#
Raw Normal View History

2026-01-10 18:35:50 +00:00
using Godot;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace Rokojori
{
public static class ArrayExtensions
{
public static void ForEach<[MustBeVariant] T>( this Godot.Collections.Array<T> array, System.Action<T> action )
{
for (int i = 0; i < array.Count; i++)
{
action( array[i] );
}
}
2026-01-15 14:00:42 +00:00
public static T Find<[MustBeVariant] T>( this Godot.Collections.Array<T> array, System.Func<T,bool> evaluater, int offset = 0 )
2026-01-10 18:35:50 +00:00
{
2026-01-15 14:00:42 +00:00
for ( int i = offset; i < array.Count; i++ )
2026-01-10 18:35:50 +00:00
{
if ( evaluater( array[ i ] ) )
{
return array[ i ];
}
}
return default(T);
}
2026-01-15 14:00:42 +00:00
public static int FindIndex<[MustBeVariant] T>( this Godot.Collections.Array<T> array, System.Func<T,bool> evaluater, int offset = 0 )
{
for ( int i = offset; i < array.Count; i++ )
{
if ( evaluater( array[ i ] ) )
{
return i;
}
}
return -1;
}
2026-01-10 18:35:50 +00:00
}
}