57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
} |