45 lines
1015 B
C#
45 lines
1015 B
C#
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] );
|
|
}
|
|
}
|
|
|
|
public static T Find<[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 array[ i ];
|
|
}
|
|
}
|
|
|
|
return default(T);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
} |