riversong code showcase

This commit is contained in:
Daniele Marotta
2026-05-21 15:52:18 +02:00
commit 4c9eea1c02
462 changed files with 23406 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using Cysharp.Threading.Tasks;
using Unity.Mathematics;
namespace DanieleMarotta.RiversongCodeShowcase
{
public class DeleteTool : DragTool
{
private ISignalBus _signalBus;
public DeleteTool(IServiceLocator serviceLocator) : base(serviceLocator)
{
}
protected override DeletedGameObjectsFilter DeletedGameObjectsFilter => DeletedGameObjectsFilter.All;
public override async UniTask InitializeAsync()
{
await base.InitializeAsync();
_signalBus = ServiceLocator.GetService<ISignalBus>();
}
protected override bool Validate(ref int2 startTile, ref int2 endTile)
{
return true;
}
protected override void UpdateAffectedTiles(bool isValid, int2 startTile, int2 endTile)
{
foreach (var tile in TileRange.From(startTile, endTile)) AffectedTiles.Add((tile, TileHighlightType.DeletePreview));
}
protected override void DoTool(int2 startTile, int2 endTile)
{
_ = DoToolAsync(new TileRect(startTile, endTile));
}
private async UniTask DoToolAsync(TileRect rect)
{
const int count = 10;
var countX = (int)math.ceil((float)rect.Width / count);
var countY = (int)math.ceil((float)rect.Height / count);
for (var x = 0; x < countX; x++)
for (var y = 0; y < countY; y++)
{
var r = new TileRect(rect.Min + new int2(x, y) * count, count, count);
r.Max = math.min(r.Max, rect.Max);
_signalBus.Raise(new DoDeleteToolSignal(r));
await UniTask.NextFrame();
}
}
}
}