riversong code showcase
This commit is contained in:
37
Source/Riversong/Game/World/BlockMap/BlockMap.cs
Normal file
37
Source/Riversong/Game/World/BlockMap/BlockMap.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class BlockMap : NativeGrid<BlockReason>
|
||||
{
|
||||
public BlockMap(int2 size) : base(size, Allocator.Persistent)
|
||||
{
|
||||
}
|
||||
|
||||
public void AddReason(int2 tile, BlockReason reason)
|
||||
{
|
||||
SetValue(tile, GetValue(tile) | reason);
|
||||
}
|
||||
|
||||
public void AddReason(int2 min, int2 max, BlockReason reason)
|
||||
{
|
||||
foreach (var tile in TileRange.From(min, max)) AddReason(tile, reason);
|
||||
}
|
||||
|
||||
public void RemoveReason(int2 tile, BlockReason reason)
|
||||
{
|
||||
SetValue(tile, GetValue(tile) & ~reason);
|
||||
}
|
||||
|
||||
public void RemoveReason(int2 min, int2 max, BlockReason reason)
|
||||
{
|
||||
foreach (var tile in TileRange.From(min, max)) RemoveReason(tile, reason);
|
||||
}
|
||||
|
||||
public bool IsBlocked(int2 tile, BlockReason reason = BlockReason.Any)
|
||||
{
|
||||
return (GetValue(tile) & reason) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user