Hex Update

This commit is contained in:
Rokojori 2026-10-04 22:39:10 +02:00
parent 1d37c3a6cf
commit 68105b2275
2 changed files with 30 additions and 0 deletions

View File

@ -51,6 +51,7 @@ public struct HexagonCoord
public static HexagonCoord Direction( int direction ) public static HexagonCoord Direction( int direction )
{ {
RJLog.Log( direction );
return directions[ direction ]; return directions[ direction ];
} }
@ -60,6 +61,14 @@ public struct HexagonCoord
return this + directions[ direction ]; return this + directions[ direction ];
} }
public void ForEachNeighbor( System.Action<HexagonCoord> callback )
{
for ( int i = 0; i < directions.Length; i++ )
{
callback( Neighbor( i ) );
}
}
public Vector3 ToWorldPosition( float size ) public Vector3 ToWorldPosition( float size )
{ {
var x = size * 1.5f * q; var x = size * 1.5f * q;
@ -138,6 +147,8 @@ public struct HexagonCoord
return Ring( HexagonCoord.Center, radius ); return Ring( HexagonCoord.Center, radius );
} }
public static List<HexagonCoord> Ring( HexagonCoord center, int radius ) public static List<HexagonCoord> Ring( HexagonCoord center, int radius )
{ {
var results = new List<HexagonCoord>(); var results = new List<HexagonCoord>();

View File

@ -237,6 +237,25 @@ namespace Rokojori
} }
#if !ROKOJORI_ACTION_CORE_GD #if !ROKOJORI_ACTION_CORE_GD
public T From<T>( HashSet<T> set )
{
var count = set.Count;
var index = IntegerExclusivePositive( count );
foreach ( T item in set)
{
if ( index-- == 0 )
{
return item;
}
}
return default(T);
}
public T From<T>( List<T> list ) public T From<T>( List<T> list )
{ {
if ( list.Count == 0 ) if ( list.Count == 0 )